[monitor]feature dashboard仪表盘重构 (#13)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.usthe.alert.controller;
|
||||
|
||||
import com.usthe.alert.dto.AlertSummary;
|
||||
import com.usthe.common.entity.alerter.Alert;
|
||||
import com.usthe.alert.service.AlertService;
|
||||
import com.usthe.common.entity.dto.Message;
|
||||
@@ -114,4 +115,11 @@ public class AlertsController {
|
||||
return ResponseEntity.ok(message);
|
||||
}
|
||||
|
||||
@GetMapping(path = "/summary")
|
||||
@ApiOperation(value = "获取告警统计信息", notes = "获取告警统计信息")
|
||||
public ResponseEntity<Message<AlertSummary>> getAlertsSummary() {
|
||||
AlertSummary alertSummary = alertService.getAlertsSummary();
|
||||
Message<AlertSummary> message = new Message<>(alertSummary);
|
||||
return ResponseEntity.ok(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.usthe.alert.dao;
|
||||
|
||||
import com.usthe.alert.dto.AlertPriorityNum;
|
||||
import com.usthe.common.entity.alerter.Alert;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
@@ -32,4 +33,10 @@ public interface AlertDao extends JpaRepository<Alert, Long>, JpaSpecificationEx
|
||||
@Query("update Alert set status = :status where id in :ids")
|
||||
void updateAlertsStatus(@Param(value = "status") Byte status, @Param(value = "ids") List<Long> ids);
|
||||
|
||||
/**
|
||||
* 查询各个告警级别的未处理告警数量
|
||||
* @return 告警数量
|
||||
*/
|
||||
@Query("select new com.usthe.alert.dto.AlertPriorityNum(mo.priority, count(mo.id)) from Alert mo where mo.status = 0 group by mo.priority")
|
||||
List<AlertPriorityNum> findAlertPriorityNum();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.usthe.alert.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 监控级别告警数量
|
||||
* @author tom
|
||||
* @date 2022/3/6 19:52
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class AlertPriorityNum {
|
||||
|
||||
private byte priority;
|
||||
|
||||
private long num;
|
||||
}
|
||||
39
alerter/src/main/java/com/usthe/alert/dto/AlertSummary.java
Normal file
39
alerter/src/main/java/com/usthe/alert/dto/AlertSummary.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package com.usthe.alert.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import static io.swagger.annotations.ApiModelProperty.AccessMode.READ_ONLY;
|
||||
|
||||
/**
|
||||
* 告警统计信息
|
||||
* @author tom
|
||||
* @date 2022/3/6 19:25
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ApiModel(description = "告警统计信息")
|
||||
public class AlertSummary {
|
||||
|
||||
@ApiModelProperty(value = "告警总数量(包括已处理未处理告警)", example = "134", accessMode = READ_ONLY, position = 0)
|
||||
private long total;
|
||||
|
||||
@ApiModelProperty(value = "已处理告警数量", example = "34", accessMode = READ_ONLY, position = 1)
|
||||
private long dealNum;
|
||||
|
||||
@ApiModelProperty(value = "告警处理率", example = "39.34", accessMode = READ_ONLY, position = 2)
|
||||
private float rate;
|
||||
|
||||
@ApiModelProperty(value = "告警级别为警告告警的告警数量(指未处理告警)", example = "43", accessMode = READ_ONLY, position = 3)
|
||||
private long priorityWarningNum;
|
||||
|
||||
@ApiModelProperty(value = "告警级别为严重告警的告警数量(指未处理告警)", example = "56", accessMode = READ_ONLY, position = 4)
|
||||
private long priorityCriticalNum;
|
||||
|
||||
@ApiModelProperty(value = "告警级别为紧急告警的告警数量(指未处理告警)", example = "23", accessMode = READ_ONLY, position = 5)
|
||||
private long priorityEmergencyNum;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.usthe.alert.service;
|
||||
|
||||
import com.usthe.alert.dto.AlertSummary;
|
||||
import com.usthe.common.entity.alerter.Alert;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -42,4 +43,11 @@ public interface AlertService {
|
||||
* @param ids 待修改的告警IDs
|
||||
*/
|
||||
void editAlertStatus(Byte status, List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获取告警统计信息
|
||||
* @return 告警统计
|
||||
*/
|
||||
AlertSummary getAlertsSummary();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.usthe.alert.service.impl;
|
||||
|
||||
import com.usthe.alert.dao.AlertDao;
|
||||
import com.usthe.alert.dto.AlertPriorityNum;
|
||||
import com.usthe.alert.dto.AlertSummary;
|
||||
import com.usthe.common.entity.alerter.Alert;
|
||||
import com.usthe.alert.service.AlertService;
|
||||
import com.usthe.common.util.CommonConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -11,6 +14,8 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
@@ -47,4 +52,37 @@ public class AlertServiceImpl implements AlertService {
|
||||
alertDao.updateAlertsStatus(status, ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlertSummary getAlertsSummary() {
|
||||
AlertSummary alertSummary = new AlertSummary();
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user