|
@@ -1,26 +1,31 @@
|
|
|
package com.jjt.risk.controller;
|
|
|
|
|
|
import com.jjt.biz.domain.BizModel;
|
|
|
+import com.jjt.biz.domain.BizModelDetail;
|
|
|
+import com.jjt.biz.domain.BizObjMetrics;
|
|
|
+import com.jjt.biz.domain.BizObjMetricsData;
|
|
|
+import com.jjt.biz.service.IBizModelDetailService;
|
|
|
import com.jjt.biz.service.IBizModelService;
|
|
|
+import com.jjt.biz.service.IBizObjMetricsDataService;
|
|
|
+import com.jjt.biz.service.IBizObjMetricsService;
|
|
|
import com.jjt.biz.vo.ScoreVO;
|
|
|
import com.jjt.common.core.controller.BaseController;
|
|
|
import com.jjt.common.core.domain.AjaxResult;
|
|
|
+import com.jjt.common.utils.DateUtils;
|
|
|
import com.jjt.risk.domain.RiskMsConfig;
|
|
|
-import com.jjt.risk.service.IRiskAnalysisService;
|
|
|
-import com.jjt.risk.service.IRiskModelService;
|
|
|
import com.jjt.risk.service.IRiskMsConfigService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.text.DecimalFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.time.ZoneOffset;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -35,13 +40,17 @@ import java.util.stream.Collectors;
|
|
|
@RequestMapping("/risk/other")
|
|
|
public class RiskOtherController extends BaseController {
|
|
|
@Resource
|
|
|
- private IRiskAnalysisService riskAnalysisService;
|
|
|
- @Resource
|
|
|
- private IRiskModelService riskModelService;
|
|
|
- @Resource
|
|
|
private IBizModelService bizModelService;
|
|
|
@Resource
|
|
|
private IRiskMsConfigService riskMsConfigService;
|
|
|
+ @Resource
|
|
|
+ private IBizModelDetailService modelDetailService;
|
|
|
+ @Resource
|
|
|
+ private IBizObjMetricsService omService;
|
|
|
+ @Resource
|
|
|
+ private IBizObjMetricsDataService dataService;
|
|
|
+ @Resource
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
@ApiOperation("模型列表")
|
|
|
@GetMapping(value = "/model/list")
|
|
@@ -53,40 +62,60 @@ public class RiskOtherController extends BaseController {
|
|
|
@ApiOperation("业务主机分析")
|
|
|
@GetMapping(value = "/host/{modelId}")
|
|
|
public AjaxResult host(@PathVariable("modelId") Long modelId) {
|
|
|
- BizModel model = bizModelService.selectBizModelByModelId(modelId);
|
|
|
+
|
|
|
RiskMsConfig q = new RiskMsConfig();
|
|
|
q.setConfigType("host");
|
|
|
List<RiskMsConfig> configs = riskMsConfigService.selectRiskMsConfigList(q);
|
|
|
- String[] objs = {"ecs1", "ecs2", "ecs3", "ecs4", "ecs5", "ecs6", "ecs7"};
|
|
|
+ LocalDateTime endTime = LocalDateTime.now();
|
|
|
+ LocalDateTime beginTime = endTime.minusDays(7);
|
|
|
+ String begin = beginTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ String end = endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ List<BizModelDetail> mdList = modelDetailService.selectBizModelDetailList4ModelId(modelId);
|
|
|
for (RiskMsConfig config : configs) {
|
|
|
Map<String, Object> map = new HashMap<>(16);
|
|
|
map.put("title", config.getViewName());
|
|
|
List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
- for (String obj : objs) {
|
|
|
+ for (BizModelDetail md : mdList) {
|
|
|
Map<String, Object> dataMap = new HashMap<>(16);
|
|
|
- String name = model.getModelName() + "-" + obj;
|
|
|
- dataMap.put("id", new Random().nextInt(30) + 1);
|
|
|
- dataMap.put("objName", name);
|
|
|
- dataMap.put("value", new Random().nextInt(100));
|
|
|
+ dataMap.put("objName", md.getBizObj().getObjName());
|
|
|
if ("2".equals(config.getRankingBased())) {
|
|
|
dataMap.put("alarms", new Random().nextInt(50));
|
|
|
}
|
|
|
- dataList.add(dataMap);
|
|
|
+ BizObjMetrics bom = new BizObjMetrics();
|
|
|
+ bom.setObjId(md.getObjId());
|
|
|
+ bom.setMetricsId(config.getMetricsId());
|
|
|
+ List<BizObjMetrics> oms = omService.selectBizObjMetricsList(bom);
|
|
|
+ if (oms.size() > 0) {
|
|
|
+ BizObjMetrics om = oms.get(0);
|
|
|
+ dataMap.put("id", om.getObjMetricsId());
|
|
|
+ dataMap.put("value", om.getDValue().floatValue());
|
|
|
+ if ("2".equals(config.getRankingBased())) {
|
|
|
+ String sql = "SELECT COUNT(*) num,sum(TIMESTAMPDIFF(MINUTE, alarm_time, ifnull(end_time,SYSDATE()))) times FROM alarm_record WHERE alarm_time BETWEEN ? AND ? and obj_metrics_id=?";
|
|
|
+ Map<String, Object> dMap = jdbcTemplate.queryForMap(sql, begin, end, om.getObjMetricsId());
|
|
|
+ Long num = (Long) dMap.get("num");
|
|
|
+ dataMap.put("alarms", num.intValue());
|
|
|
+ dataMap.put("value", dMap.get("times"));
|
|
|
+ } else {
|
|
|
+ dataMap.put("value", om.getDValue().floatValue());
|
|
|
+ }
|
|
|
+ dataList.add(dataMap);
|
|
|
+ }
|
|
|
}
|
|
|
if ("2".equals(config.getRankingBased())) {
|
|
|
dataList = dataList.stream().sorted(
|
|
|
- (o1, o2) -> -Integer.compare(Integer.parseInt(o1.get("alarms").toString()), Integer.parseInt(o2.get("alarms").toString()))
|
|
|
+ (o1, o2) -> -Integer.compare((int) o1.get("alarms"), (int) o2.get("alarms"))
|
|
|
).collect(Collectors.toList());
|
|
|
} else {
|
|
|
|
|
|
dataList = dataList.stream().sorted(
|
|
|
- (o1, o2) -> -Integer.compare(Integer.parseInt(o1.get("value").toString()), Integer.parseInt(o2.get("value").toString()))
|
|
|
+ (o1, o2) -> -Float.compare((float) o1.get("value"), (float) o2.get("value"))
|
|
|
).collect(Collectors.toList());
|
|
|
}
|
|
|
-
|
|
|
- map.put("data", dataList);
|
|
|
- result.add(map);
|
|
|
+ if (dataList.size() > 0) {
|
|
|
+ map.put("data", dataList);
|
|
|
+ result.add(map);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return success(result);
|
|
@@ -98,14 +127,20 @@ public class RiskOtherController extends BaseController {
|
|
|
Map<String, Object> result = new HashMap<>(16);
|
|
|
List<String> xData = new ArrayList<>();
|
|
|
List<Float> curr = new ArrayList<>();
|
|
|
- LocalDate time = LocalDate.now().minusDays(31);
|
|
|
- for (int j = 0; j < 30; j++) {
|
|
|
- time = time.plusDays(1);
|
|
|
- xData.add(time.getMonthValue() + "-" + time.getDayOfMonth());
|
|
|
- Float score = Float.valueOf(new Random().nextInt(50) + 50);
|
|
|
- curr.add(score);
|
|
|
- }
|
|
|
-
|
|
|
+ LocalDateTime endTime = LocalDateTime.now();
|
|
|
+ LocalDateTime beginTime = endTime.minusDays(7);
|
|
|
+ Map<String, Object> params = new HashMap<>(16);
|
|
|
+ params.put("beginTime", beginTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ params.put("endTime", endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ BizObjMetricsData q = new BizObjMetricsData();
|
|
|
+ q.setObjMetricsId(id);
|
|
|
+ q.setParams(params);
|
|
|
+ List<BizObjMetricsData> list = dataService.selectBizObjMetricsDataList(q);
|
|
|
+ list.forEach(data -> {
|
|
|
+ Map<String, Object> map = new HashMap<>(16);
|
|
|
+ xData.add(DateUtils.dateTime(data.getCreateTime()));
|
|
|
+ curr.add(data.getdValue().floatValue());
|
|
|
+ });
|
|
|
result.put("time", xData);
|
|
|
result.put("data", curr);
|
|
|
return success(result);
|
|
@@ -114,34 +149,63 @@ public class RiskOtherController extends BaseController {
|
|
|
@ApiOperation("网络状况分析")
|
|
|
@GetMapping(value = "/network/{modelId}/{metricsId}")
|
|
|
public AjaxResult network(@PathVariable("modelId") Long modelId, @PathVariable("metricsId") Long metricsId) {
|
|
|
- BizModel model = bizModelService.selectBizModelByModelId(modelId);
|
|
|
- RiskMsConfig q = new RiskMsConfig();
|
|
|
- q.setConfigType("host");
|
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
|
- String[] objs = {"node1", "node2", "node3", "ecs4", "业务对象5", "虚拟主机6", "cluster7"};
|
|
|
- for (String obj : objs) {
|
|
|
- Map<String, Object> map = new HashMap<>(16);
|
|
|
- map.put("name", obj);
|
|
|
-
|
|
|
- List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
-
|
|
|
- LocalDateTime ed = LocalDateTime.now();
|
|
|
- LocalDateTime st = ed.minusDays(30);
|
|
|
- Random r = new Random();
|
|
|
- DecimalFormat df = new DecimalFormat("#0.00");
|
|
|
- do {
|
|
|
- Map<String, Object> dataMap = new HashMap<>(16);
|
|
|
- long time = st.toEpochSecond(ZoneOffset.ofHours(8)) * 1000;
|
|
|
- dataMap.put("time", time);
|
|
|
- float f = r.nextFloat() * 100;
|
|
|
- dataMap.put("value", Float.parseFloat(df.format(f)));
|
|
|
- st = st.plusDays(1);
|
|
|
- dataList.add(dataMap);
|
|
|
- } while (!st.isAfter(ed));
|
|
|
- map.put("data", dataList);
|
|
|
-
|
|
|
- result.add(map);
|
|
|
- }
|
|
|
+ modelDetailService.selectBizModelDetailList4ModelId(modelId).forEach(md -> {
|
|
|
+ Map<String, Object> objectMap = new HashMap<>(16);
|
|
|
+ objectMap.put("name", md.getBizObj().getObjName());
|
|
|
+ BizObjMetrics bom = new BizObjMetrics();
|
|
|
+ bom.setObjId(md.getObjId());
|
|
|
+ bom.setMetricsId(metricsId);
|
|
|
+ List<BizObjMetrics> oms = omService.selectBizObjMetricsList(bom);
|
|
|
+ if (oms.size() > 0) {
|
|
|
+ BizObjMetrics om = oms.get(0);
|
|
|
+ List<Map<String, Object>> trendList = new ArrayList<>();
|
|
|
+
|
|
|
+ LocalDateTime endTime = LocalDateTime.now();
|
|
|
+ LocalDateTime beginTime = endTime.minusDays(7);
|
|
|
+ Map<String, Object> params = new HashMap<>(16);
|
|
|
+ params.put("beginTime", beginTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ params.put("endTime", endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ BizObjMetricsData q = new BizObjMetricsData();
|
|
|
+ q.setObjMetricsId(om.getObjMetricsId());
|
|
|
+ q.setParams(params);
|
|
|
+ List<BizObjMetricsData> list = dataService.selectBizObjMetricsDataList(q);
|
|
|
+ list.forEach(data -> {
|
|
|
+ Map<String, Object> map = new HashMap<>(16);
|
|
|
+ map.put("time", data.getCreateTime());
|
|
|
+ map.put("value", data.getdValue().floatValue());
|
|
|
+ trendList.add(map);
|
|
|
+ });
|
|
|
+ objectMap.put("data", trendList);
|
|
|
+ result.add(objectMap);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+// String[] objs = {"node1", "node2", "node3", "ecs4", "业务对象5", "虚拟主机6", "cluster7"};
|
|
|
+// for (String obj : objs) {
|
|
|
+// Map<String, Object> map = new HashMap<>(16);
|
|
|
+// map.put("name", obj);
|
|
|
+//
|
|
|
+// List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
+//
|
|
|
+// LocalDateTime ed = LocalDateTime.now();
|
|
|
+// LocalDateTime st = ed.minusDays(30);
|
|
|
+// Random r = new Random();
|
|
|
+// DecimalFormat df = new DecimalFormat("#0.00");
|
|
|
+// do {
|
|
|
+// Map<String, Object> dataMap = new HashMap<>(16);
|
|
|
+// long time = st.toEpochSecond(ZoneOffset.ofHours(8)) * 1000;
|
|
|
+// dataMap.put("time", time);
|
|
|
+// float f = r.nextFloat() * 100;
|
|
|
+// dataMap.put("value", Float.parseFloat(df.format(f)));
|
|
|
+// st = st.plusDays(1);
|
|
|
+// dataList.add(dataMap);
|
|
|
+// } while (!st.isAfter(ed));
|
|
|
+// map.put("data", dataList);
|
|
|
+//
|
|
|
+// result.add(map);
|
|
|
+// }
|
|
|
|
|
|
return success(result);
|
|
|
}
|