[manager] 监控类型指标组指标层级接口
This commit is contained in:
@@ -16,6 +16,7 @@ import javax.persistence.Id;
|
|||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.validation.constraints.Max;
|
import javax.validation.constraints.Max;
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@@ -43,14 +44,17 @@ public class AlertDefine {
|
|||||||
|
|
||||||
@ApiModelProperty(value = "配置告警的监控类型", example = "linux", accessMode = READ_WRITE, position = 1)
|
@ApiModelProperty(value = "配置告警的监控类型", example = "linux", accessMode = READ_WRITE, position = 1)
|
||||||
@Length(max = 100)
|
@Length(max = 100)
|
||||||
|
@NotNull
|
||||||
private String app;
|
private String app;
|
||||||
|
|
||||||
@ApiModelProperty(value = "配置告警的指标集合", example = "cpu", accessMode = READ_WRITE, position = 2)
|
@ApiModelProperty(value = "配置告警的指标集合", example = "cpu", accessMode = READ_WRITE, position = 2)
|
||||||
@Length(max = 100)
|
@Length(max = 100)
|
||||||
|
@NotNull
|
||||||
private String metric;
|
private String metric;
|
||||||
|
|
||||||
@ApiModelProperty(value = "配置告警的指标", example = "usage", accessMode = READ_WRITE, position = 3)
|
@ApiModelProperty(value = "配置告警的指标", example = "usage", accessMode = READ_WRITE, position = 3)
|
||||||
@Length(max = 100)
|
@Length(max = 100)
|
||||||
|
@NotNull
|
||||||
private String field;
|
private String field;
|
||||||
|
|
||||||
@ApiModelProperty(value = "是否是默认预置告警", example = "false", accessMode = READ_WRITE, position = 4)
|
@ApiModelProperty(value = "是否是默认预置告警", example = "false", accessMode = READ_WRITE, position = 4)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.usthe.manager.controller;
|
package com.usthe.manager.controller;
|
||||||
|
|
||||||
import com.usthe.common.entity.dto.Message;
|
import com.usthe.common.entity.dto.Message;
|
||||||
|
import com.usthe.manager.pojo.dto.Hierarchy;
|
||||||
import com.usthe.manager.pojo.entity.ParamDefine;
|
import com.usthe.manager.pojo.entity.ParamDefine;
|
||||||
import com.usthe.manager.service.AppService;
|
import com.usthe.manager.service.AppService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@@ -11,6 +12,7 @@ import org.springframework.http.ResponseEntity;
|
|||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -38,11 +40,18 @@ public class AppController {
|
|||||||
return ResponseEntity.ok(new Message<>(paramDefines));
|
return ResponseEntity.ok(new Message<>(paramDefines));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping(path = "/hierarchy")
|
||||||
@ApiOperation(value = "查询全部层级的监控类型", notes = "查询所有监控类型,以层级结构输出")
|
@ApiOperation(value = "查询全部层级的监控类型", notes = "查询所有监控类型,以层级结构输出")
|
||||||
public ResponseEntity<Message<Object>> queryAppsHierarchy() {
|
public ResponseEntity<Message<List<Hierarchy>>> queryAppsHierarchy(
|
||||||
|
@ApiParam(value = "语言类型", example = "zh-CN", defaultValue = "zh-CN")
|
||||||
return null;
|
@RequestParam(name = "lang", required = false) String lang) {
|
||||||
|
if (lang == null || "".equals(lang)) {
|
||||||
|
lang = "zh-CN";
|
||||||
|
}
|
||||||
|
lang = lang.equalsIgnoreCase("zh-cn")? "zh-CN" : lang;
|
||||||
|
lang = lang.equalsIgnoreCase("en-us")? "en-US" : lang;
|
||||||
|
List<Hierarchy> appHierarchies = appService.getAllAppHierarchy(lang);
|
||||||
|
return ResponseEntity.ok(new Message<>(appHierarchies));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.usthe.manager.pojo.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static io.swagger.annotations.ApiModelProperty.AccessMode.READ_WRITE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 层级关系结构
|
||||||
|
* eg: 监控类型指标组指标信息层级关系
|
||||||
|
* @author tom
|
||||||
|
* @date 2021/12/12 16:23
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
public class Hierarchy {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "属性值", example = "linux", accessMode = READ_WRITE, position = 0)
|
||||||
|
String value;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "属性国际化标签", example = "Linux系统", accessMode = READ_WRITE, position = 1)
|
||||||
|
String label;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否是叶子节点", example = "true", accessMode = READ_WRITE, position = 2)
|
||||||
|
Boolean isLeaf = false;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "下一关联层级", accessMode = READ_WRITE, position = 3)
|
||||||
|
private List<Hierarchy> children;
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.usthe.manager.service;
|
package com.usthe.manager.service;
|
||||||
|
|
||||||
import com.usthe.common.entity.job.Job;
|
import com.usthe.common.entity.job.Job;
|
||||||
|
import com.usthe.manager.pojo.dto.Hierarchy;
|
||||||
import com.usthe.manager.pojo.entity.ParamDefine;
|
import com.usthe.manager.pojo.entity.ParamDefine;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -34,4 +35,12 @@ public interface AppService {
|
|||||||
* @return I18N资源
|
* @return I18N资源
|
||||||
*/
|
*/
|
||||||
Map<String, String> getI18nResources(String lang);
|
Map<String, String> getI18nResources(String lang);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有监控的类型-指标组-指标层级
|
||||||
|
* @param lang 语言
|
||||||
|
* @return 层级信息
|
||||||
|
*/
|
||||||
|
List<Hierarchy> getAllAppHierarchy(String lang);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.usthe.manager.service.impl;
|
package com.usthe.manager.service.impl;
|
||||||
|
|
||||||
import com.usthe.common.entity.job.Job;
|
import com.usthe.common.entity.job.Job;
|
||||||
|
import com.usthe.common.entity.job.Metrics;
|
||||||
import com.usthe.manager.dao.ParamDefineDao;
|
import com.usthe.manager.dao.ParamDefineDao;
|
||||||
|
import com.usthe.manager.pojo.dto.Hierarchy;
|
||||||
import com.usthe.manager.pojo.dto.ParamDefineDto;
|
import com.usthe.manager.pojo.dto.ParamDefineDto;
|
||||||
import com.usthe.manager.pojo.entity.ParamDefine;
|
import com.usthe.manager.pojo.entity.ParamDefine;
|
||||||
import com.usthe.manager.service.AppService;
|
import com.usthe.manager.service.AppService;
|
||||||
@@ -19,6 +21,7 @@ import java.io.IOException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -76,6 +79,46 @@ public class AppServiceImpl implements AppService, CommandLineRunner {
|
|||||||
return i18nMap;
|
return i18nMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Hierarchy> getAllAppHierarchy(String lang) {
|
||||||
|
List<Hierarchy> hierarchies = new LinkedList<>();
|
||||||
|
for (Job job : appDefines.values()) {
|
||||||
|
Hierarchy hierarchyApp = new Hierarchy();
|
||||||
|
hierarchyApp.setValue(job.getApp());
|
||||||
|
Map<String, String> nameMap = job.getName();
|
||||||
|
if (nameMap != null) {
|
||||||
|
String i18nName = nameMap.get(lang);
|
||||||
|
if (i18nName == null) {
|
||||||
|
i18nName = nameMap.values().stream().findFirst().get();
|
||||||
|
}
|
||||||
|
hierarchyApp.setLabel(i18nName);
|
||||||
|
}
|
||||||
|
List<Hierarchy> hierarchyMetricList = new LinkedList<>();
|
||||||
|
if (job.getMetrics() != null) {
|
||||||
|
for (Metrics metrics : job.getMetrics()) {
|
||||||
|
Hierarchy hierarchyMetric = new Hierarchy();
|
||||||
|
hierarchyMetric.setValue(metrics.getName());
|
||||||
|
hierarchyMetric.setLabel(metrics.getName());
|
||||||
|
List<Hierarchy> hierarchyFieldList = new LinkedList<>();
|
||||||
|
if (metrics.getFields() != null) {
|
||||||
|
for (Metrics.Field field : metrics.getFields()) {
|
||||||
|
Hierarchy hierarchyField = new Hierarchy();
|
||||||
|
hierarchyField.setValue(field.getField());
|
||||||
|
hierarchyField.setLabel(field.getField());
|
||||||
|
hierarchyField.setIsLeaf(true);
|
||||||
|
hierarchyFieldList.add(hierarchyField);
|
||||||
|
}
|
||||||
|
hierarchyMetric.setChildren(hierarchyFieldList);
|
||||||
|
}
|
||||||
|
hierarchyMetricList.add(hierarchyMetric);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hierarchyApp.setChildren(hierarchyMetricList);
|
||||||
|
hierarchies.add(hierarchyApp);
|
||||||
|
}
|
||||||
|
return hierarchies;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String... args) throws Exception {
|
public void run(String... args) throws Exception {
|
||||||
// 读取app定义配置加载到内存中 define/app/*.yml
|
// 读取app定义配置加载到内存中 define/app/*.yml
|
||||||
|
|||||||
Reference in New Issue
Block a user