Search in sources :

Example 1 with AlertSummary

use of com.usthe.alert.dto.AlertSummary in project hertzbeat by dromara.

the class AlertServiceImpl method getAlertsSummary.

@Override
public AlertSummary getAlertsSummary() {
    AlertSummary alertSummary = new AlertSummary();
    // Statistics on the alarm information in the alarm state
    // 统计正在告警状态下的告警信息
    List<AlertPriorityNum> priorityNums = alertDao.findAlertPriorityNum();
    if (priorityNums != null) {
        for (AlertPriorityNum priorityNum : priorityNums) {
            switch(priorityNum.getPriority()) {
                case CommonConstants.ALERT_PRIORITY_CODE_WARNING:
                    alertSummary.setPriorityWarningNum(priorityNum.getNum());
                    break;
                case CommonConstants.ALERT_PRIORITY_CODE_CRITICAL:
                    alertSummary.setPriorityCriticalNum(priorityNum.getNum());
                    break;
                case CommonConstants.ALERT_PRIORITY_CODE_EMERGENCY:
                    alertSummary.setPriorityEmergencyNum(priorityNum.getNum());
                    break;
                default:
                    break;
            }
        }
    }
    long total = alertDao.count();
    long dealNum = total - alertSummary.getPriorityCriticalNum() - alertSummary.getPriorityEmergencyNum() - alertSummary.getPriorityWarningNum();
    alertSummary.setDealNum(dealNum);
    try {
        if (total == 0) {
            alertSummary.setRate(100);
        } else {
            float rate = BigDecimal.valueOf(100 * (float) dealNum / total).setScale(2, RoundingMode.HALF_UP).floatValue();
            alertSummary.setRate(rate);
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return alertSummary;
}
Also used : AlertPriorityNum(com.usthe.alert.dto.AlertPriorityNum) AlertSummary(com.usthe.alert.dto.AlertSummary)

Example 2 with AlertSummary

use of com.usthe.alert.dto.AlertSummary in project hertzbeat by dromara.

the class AlertsController method getAlertsSummary.

@GetMapping(path = "/summary")
@ApiOperation(value = "Get alarm statistics", notes = "获取告警统计信息")
public ResponseEntity<Message<AlertSummary>> getAlertsSummary() {
    AlertSummary alertSummary = alertService.getAlertsSummary();
    Message<AlertSummary> message = new Message<>(alertSummary);
    return ResponseEntity.ok(message);
}
Also used : Message(com.usthe.common.entity.dto.Message) AlertSummary(com.usthe.alert.dto.AlertSummary) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

AlertSummary (com.usthe.alert.dto.AlertSummary)2 AlertPriorityNum (com.usthe.alert.dto.AlertPriorityNum)1 Message (com.usthe.common.entity.dto.Message)1 ApiOperation (io.swagger.annotations.ApiOperation)1