|
@@ -1,14 +1,24 @@
|
|
|
package com.jjt.biz.controller;
|
|
|
|
|
|
+import com.jjt.biz.domain.BizObjMetrics;
|
|
|
+import com.jjt.biz.domain.IndexMetrics;
|
|
|
+import com.jjt.biz.service.IBizObjMetricsService;
|
|
|
+import com.jjt.biz.service.IIndexMetricsService;
|
|
|
import com.jjt.common.core.controller.BaseController;
|
|
|
import com.jjt.common.core.domain.AjaxResult;
|
|
|
+import com.jjt.common.core.page.TableDataInfo;
|
|
|
+import com.jjt.common.utils.DateUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
-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 org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneOffset;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 业务对象Controller
|
|
@@ -20,16 +30,222 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
@RestController
|
|
|
@RequestMapping("/index")
|
|
|
public class IndexController extends BaseController {
|
|
|
+ @Resource
|
|
|
+ private IIndexMetricsService imService;
|
|
|
+ @Resource
|
|
|
+ private IBizObjMetricsService omService;
|
|
|
+
|
|
|
+ String[] MODEL_NAMES = {"市场服务", "市场出清", "信息发布", "市场合规", "市场结算"};
|
|
|
+
|
|
|
+ @ApiOperation("巡检提示")
|
|
|
+ @GetMapping("/hl/check")
|
|
|
+ public AjaxResult hlCheck() {
|
|
|
+ Map<String, Object> result = new HashMap<>(16);
|
|
|
+ result.put("time", DateUtils.getTime());
|
|
|
+ result.put("model", 5);
|
|
|
+ result.put("metrics", new Random().nextInt(200));
|
|
|
+ result.put("problem", new Random().nextInt(80));
|
|
|
+ return AjaxResult.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("当前健康度")
|
|
|
+ @GetMapping("/hl/curr")
|
|
|
+ public AjaxResult hlCurr() {
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ for (int i = 0; i < MODEL_NAMES.length; i++) {
|
|
|
+ Map<String, Object> map = new HashMap<>(16);
|
|
|
+ map.put("name", MODEL_NAMES[i]);
|
|
|
+ Float score = Float.valueOf(new Random().nextInt(50) + 50);
|
|
|
+ map.put("score", score);
|
|
|
+ result.add(map);
|
|
|
+ }
|
|
|
+ return AjaxResult.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("应用健康趋势-按月")
|
|
|
+ @GetMapping("/hl/month/{date}")
|
|
|
+ public AjaxResult hlMonth(@ApiParam(value = "时间 yyyy-mm", required = true) @PathVariable("date") String date) {
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ int year = Integer.parseInt(date.split("-")[0]);
|
|
|
+ int month = Integer.parseInt(date.split("-")[1]);
|
|
|
+ LocalDate localDate = LocalDate.of(year, month, 1);
|
|
|
+ for (int i = 0; i < MODEL_NAMES.length; i++) {
|
|
|
+ Map<String, Object> map = new HashMap<>(16);
|
|
|
+ map.put("name", MODEL_NAMES[i]);
|
|
|
+ List<String> times = new ArrayList<>();
|
|
|
+ List<Float> scores = new ArrayList<>();
|
|
|
+ for (int j = 0; j < localDate.lengthOfMonth(); j++) {
|
|
|
+ times.add((j + 1) + "");
|
|
|
+ Float score = Float.valueOf(new Random().nextInt(50) + 50);
|
|
|
+ scores.add(score);
|
|
|
+ }
|
|
|
+ map.put("time", times);
|
|
|
+ map.put("score", scores);
|
|
|
+ result.add(map);
|
|
|
+ }
|
|
|
+ return success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("应用健康趋势-按天")
|
|
|
+ @GetMapping("/hl/day/{date}")
|
|
|
+ public AjaxResult hlDay(@ApiParam(value = "时间(yyyy-mm-dd", required = true) @PathVariable("date") Date date) {
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ for (int i = 0; i < MODEL_NAMES.length; i++) {
|
|
|
+ Map<String, Object> map = new HashMap<>(16);
|
|
|
+ map.put("name", MODEL_NAMES[i]);
|
|
|
+ List<String> times = new ArrayList<>();
|
|
|
+ List<Float> scores = new ArrayList<>();
|
|
|
+ for (int j = 0; j < 24; j++) {
|
|
|
+ times.add(j + "");
|
|
|
+ Float score = Float.valueOf(new Random().nextInt(50) + 50);
|
|
|
+ scores.add(score);
|
|
|
+ }
|
|
|
+ map.put("time", times);
|
|
|
+ map.put("score", scores);
|
|
|
+ result.add(map);
|
|
|
+ }
|
|
|
+ return success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("运行风险预测结果")
|
|
|
+ @GetMapping("/risk")
|
|
|
+ public AjaxResult risk() {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+ String[] objs = {"出清node1", "出清ecs", "业务应用3", "业务应用4", "业务应用5", "业务应用6", "业务应用7"};
|
|
|
+ String[] ms = {"cpu使用率", "慢访问次数", "GC次数", "空间交换", "打开文件数", "交换分区访问"};
|
|
|
+ Random random = new Random();
|
|
|
+ int x = objs.length * ms.length;
|
|
|
+ int xx = x / 2;
|
|
|
+ int max = random.nextInt(xx) + 12;
|
|
|
+ int num = 0;
|
|
|
+ for (int i = 0; i < max; i++) {
|
|
|
+ boolean flag = random.nextInt(888) % 2 == 0;
|
|
|
+ int mi = random.nextInt(ms.length - 1);
|
|
|
+ Map<String, Object> map = new HashMap<>(16);
|
|
|
+ String objName = objs[i % 6];
|
|
|
+ String metricsName = ms[mi];
|
|
|
+ map.put("objName", objName);
|
|
|
+ map.put("metricsName", metricsName);
|
|
|
+ String status = "1";
|
|
|
+ if (flag) {
|
|
|
+ //风险
|
|
|
+ num++;
|
|
|
+ status = "2";
|
|
|
+ }
|
|
|
+ map.put("status", status);
|
|
|
+ list.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ result.put("num", num);
|
|
|
+ result.put("data", list);
|
|
|
+ return success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("业务访问报错排名")
|
|
|
+ @GetMapping("/biz/access")
|
|
|
+ public AjaxResult access() {
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ String[] names = {"市场出清/mysql", "市场出清/redis", "市场出清/user", "市场服务/auth", "市场结算/mysql"};
|
|
|
+ Random random = new Random();
|
|
|
+ for (int i = 0; i < names.length; i++) {
|
|
|
+ Map<String, Object> map = new HashMap<>(16);
|
|
|
+ map.put("name", names[i]);
|
|
|
+ map.put("total", random.nextInt(500) + 500);
|
|
|
+ map.put("error", random.nextInt(20));
|
|
|
+ result.add(map);
|
|
|
+ }
|
|
|
+ return success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("组件告警数排名")
|
|
|
+ @GetMapping("/obj/alarm")
|
|
|
+ public AjaxResult alarm() {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ String[] names = {"市场服务node-1", "市场出清后台应用", "市场合规cluster1", "市场合规cluster2", "信息发布cluster1"};
|
|
|
+ result.put("curr", new Random().nextInt(50) + 1);
|
|
|
+ Random random = new Random();
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < names.length; i++) {
|
|
|
+ Map<String, Object> map = new HashMap<>(16);
|
|
|
+ map.put("name", names[i]);
|
|
|
+ map.put("alarm", random.nextInt(500) + 500);
|
|
|
+ list.add(map);
|
|
|
+ }
|
|
|
+ result.put("data", list);
|
|
|
+ return success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("指标配置列表")
|
|
|
+ @GetMapping("/ms/config/list")
|
|
|
+ public AjaxResult configList() {
|
|
|
+ List<IndexMetrics> list = imService.selectIndexMetricsList(new IndexMetrics());
|
|
|
+ return AjaxResult.success(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("重点指标运行趋势列表")
|
|
|
+ @GetMapping("/ms/trend")
|
|
|
+ public AjaxResult msList() {
|
|
|
+ List<IndexMetrics> list = imService.selectIndexMetricsList(new IndexMetrics());
|
|
|
+ list.forEach(im -> {
|
|
|
+ Random r = new Random();
|
|
|
+ DecimalFormat df = new DecimalFormat("#0.00");
|
|
|
+ im.setValue(Float.parseFloat(df.format(r.nextFloat() * 100)));
|
|
|
+ });
|
|
|
+ return AjaxResult.success(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("重点指标运行趋势图")
|
|
|
+ @GetMapping("/ms/trend/{objMetricsId}")
|
|
|
+ public AjaxResult msChat(@PathVariable("objMetricsId") Long objMetricsId) {
|
|
|
+ List<Map<String, Object>> trendList = new ArrayList<>();
|
|
|
+ LocalDateTime ed = LocalDateTime.now();
|
|
|
+ LocalDateTime st = ed.minusDays(7);
|
|
|
+ Random r = new Random();
|
|
|
+ DecimalFormat df = new DecimalFormat("#0.00");
|
|
|
+ do {
|
|
|
+ Map<String, Object> map = new HashMap<>(16);
|
|
|
+ long time = st.toEpochSecond(ZoneOffset.ofHours(8)) * 1000;
|
|
|
+ map.put("time", time);
|
|
|
+ float f = r.nextFloat() * 100;
|
|
|
+ map.put("value", Float.parseFloat(df.format(f)));
|
|
|
+ st = st.plusMinutes(5);
|
|
|
+ trendList.add(map);
|
|
|
+ } while (!st.isAfter(ed));
|
|
|
+ return AjaxResult.success(trendList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("指标配置--选择指标列表")
|
|
|
+ @GetMapping("/ms/config/select")
|
|
|
+ public TableDataInfo list(BizObjMetrics bizObjMetrics) {
|
|
|
+ startPage();
|
|
|
+ List<BizObjMetrics> list = omService.selectBizObjMetricsList(bizObjMetrics);
|
|
|
+ return getDataTable(list);
|
|
|
+ }
|
|
|
|
|
|
- @ApiOperation("选择模板")
|
|
|
- @GetMapping("/tpl/select/{objId}")
|
|
|
- public AjaxResult select(@ApiParam(value = "对象ID", required = true) @PathVariable("objId") Long objId) {
|
|
|
+ @ApiOperation("指标配置--添加指标")
|
|
|
+ @GetMapping("/ms/config/add")
|
|
|
+ public AjaxResult selectAdd(@ApiParam(value = "指标ID数组", required = true) Long[] ids) {
|
|
|
+ for (int i = 0; i < ids.length; i++) {
|
|
|
+ Long id = ids[i];
|
|
|
+ IndexMetrics im = new IndexMetrics();
|
|
|
+ im.setObjMetricsId(id);
|
|
|
+ List list = imService.selectIndexMetricsList(im);
|
|
|
+ if (list.size() == 0) {
|
|
|
+ BizObjMetrics bom = omService.selectBizObjMetricsByObjMetricsId(id);
|
|
|
+ im.setObjId(bom.getObjId());
|
|
|
+ im.setObjName(bom.getObjName());
|
|
|
+ im.setMetricsId(bom.getMetricsId());
|
|
|
+ im.setMetricsName(bom.getMetricsName());
|
|
|
+ imService.insertIndexMetrics(im);
|
|
|
+ }
|
|
|
+ }
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
|
- @ApiOperation("添加模板")
|
|
|
- @GetMapping("/tpl/add/{objId}")
|
|
|
- public AjaxResult add(@ApiParam(value = "对象ID", required = true) @PathVariable("objId") Long objId, @ApiParam(value = "指标ID数组", required = true) Long[] tplIds) {
|
|
|
- return success();
|
|
|
+ @ApiOperation("指标配置--删除指标")
|
|
|
+ @DeleteMapping("/ms/config/del/{imIds}")
|
|
|
+ public AjaxResult configDel(@ApiParam(value = "指标imId", required = true) @PathVariable Long[] imIds) {
|
|
|
+ return AjaxResult.success(imService.deleteIndexMetricsByImIds(imIds));
|
|
|
}
|
|
|
}
|