feat: [manager,alert,collector,common]feature:Modify monitoring and add transaction support. Monitoring compatible with Chinese and English #wqh
This commit is contained in:
@@ -7,34 +7,43 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AlertDefineBind 数据库操作
|
* AlertDefineBind database operations 数据库操作
|
||||||
|
*
|
||||||
* @author tom
|
* @author tom
|
||||||
* @date 2021/12/9 10:03
|
* @date 2021/12/9 10:03
|
||||||
*/
|
*/
|
||||||
public interface AlertDefineBindDao extends JpaRepository<AlertDefineMonitorBind, Long>, JpaSpecificationExecutor<AlertDefineMonitorBind> {
|
public interface AlertDefineBindDao extends JpaRepository<AlertDefineMonitorBind, Long>, JpaSpecificationExecutor<AlertDefineMonitorBind> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Delete the alarm definition and monitor association based on the alarm definition ID
|
||||||
* 根据告警定义ID删除告警定义与监控关联
|
* 根据告警定义ID删除告警定义与监控关联
|
||||||
* @param alertDefineId 告警定义ID
|
*
|
||||||
|
* @param alertDefineId Alarm Definition ID 告警定义ID
|
||||||
*/
|
*/
|
||||||
void deleteAlertDefineBindsByAlertDefineIdEquals(Long alertDefineId);
|
void deleteAlertDefineBindsByAlertDefineIdEquals(Long alertDefineId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Deleting alarms based on monitoring IDs defines monitoring associations
|
||||||
* 根据监控ID删除告警定义监控关联
|
* 根据监控ID删除告警定义监控关联
|
||||||
* @param monitorId 监控ID
|
*
|
||||||
|
* @param monitorId Monitor Id 监控ID
|
||||||
*/
|
*/
|
||||||
void deleteAlertDefineMonitorBindsByMonitorIdEquals(Long monitorId);
|
void deleteAlertDefineMonitorBindsByMonitorIdEquals(Long monitorId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Delete alarm definition monitoring association based on monitoring ID list
|
||||||
* 根据监控ID列表删除告警定义监控关联
|
* 根据监控ID列表删除告警定义监控关联
|
||||||
* @param monitorIds 监控ID列表
|
*
|
||||||
|
* @param monitorIds Monitoring ID List 监控ID列表
|
||||||
*/
|
*/
|
||||||
void deleteAlertDefineMonitorBindsByMonitorIdIn(List<Long> monitorIds);
|
void deleteAlertDefineMonitorBindsByMonitorIdIn(List<Long> monitorIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Query monitoring related information based on alarm definition ID
|
||||||
* 根据告警定义ID查询监控关联信息
|
* 根据告警定义ID查询监控关联信息
|
||||||
* @param alertDefineId 告警定义ID
|
*
|
||||||
* @return 关联监控信息
|
* @param alertDefineId Alarm Definition ID 告警定义ID
|
||||||
|
* @return Associated monitoring information 关联监控信息
|
||||||
*/
|
*/
|
||||||
List<AlertDefineMonitorBind> getAlertDefineBindsByAlertDefineIdEquals(Long alertDefineId);
|
List<AlertDefineMonitorBind> getAlertDefineBindsByAlertDefineIdEquals(Long alertDefineId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,10 +27,11 @@ public class CollectJobService {
|
|||||||
private TimerDispatch timerDispatch;
|
private TimerDispatch timerDispatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Execute a one-time collection task and get the collected data response
|
||||||
* 执行一次性采集任务,获取采集数据响应
|
* 执行一次性采集任务,获取采集数据响应
|
||||||
*
|
*
|
||||||
* @param job 采集任务详情
|
* @param job Collect task details 采集任务详情
|
||||||
* @return 采集结果
|
* @return Collection results 采集结果
|
||||||
*/
|
*/
|
||||||
public List<CollectRep.MetricsData> collectSyncJobData(Job job) {
|
public List<CollectRep.MetricsData> collectSyncJobData(Job job) {
|
||||||
final List<CollectRep.MetricsData> metricsData = new LinkedList<>();
|
final List<CollectRep.MetricsData> metricsData = new LinkedList<>();
|
||||||
|
|||||||
@@ -35,10 +35,12 @@ public interface TimerDispatch {
|
|||||||
void cyclicJob(WheelTimerTask timerTask, long interval, TimeUnit timeUnit);
|
void cyclicJob(WheelTimerTask timerTask, long interval, TimeUnit timeUnit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Delete existing job
|
||||||
* 删除存在的job
|
* 删除存在的job
|
||||||
*
|
*
|
||||||
* @param jobId jobId
|
* @param jobId jobId
|
||||||
* @param isCyclic 是否是周期性任务,true是, false为临时性任务
|
* @param isCyclic Whether it is a periodic task, true is, false is a temporary task
|
||||||
|
* 是否是周期性任务,true是, false为临时性任务
|
||||||
*/
|
*/
|
||||||
void deleteJob(long jobId, boolean isCyclic);
|
void deleteJob(long jobId, boolean isCyclic);
|
||||||
|
|
||||||
|
|||||||
@@ -18,18 +18,22 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public class TimerDispatcher implements TimerDispatch {
|
public class TimerDispatcher implements TimerDispatch {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* time round schedule
|
||||||
* 时间轮调度
|
* 时间轮调度
|
||||||
*/
|
*/
|
||||||
private Timer wheelTimer;
|
private Timer wheelTimer;
|
||||||
/**
|
/**
|
||||||
|
* Existing periodic scheduled tasks
|
||||||
* 已存在的周期性调度任务
|
* 已存在的周期性调度任务
|
||||||
*/
|
*/
|
||||||
private Map<Long, Timeout> currentCyclicTaskMap;
|
private Map<Long, Timeout> currentCyclicTaskMap;
|
||||||
/**
|
/**
|
||||||
|
* Existing temporary scheduled tasks
|
||||||
* 已存在的临时性调度任务
|
* 已存在的临时性调度任务
|
||||||
*/
|
*/
|
||||||
private Map<Long, Timeout> currentTempTaskMap;
|
private Map<Long, Timeout> currentTempTaskMap;
|
||||||
/**
|
/**
|
||||||
|
* One-time task response listener holds
|
||||||
* 一次性任务响应监听器持有
|
* 一次性任务响应监听器持有
|
||||||
* jobId - listener
|
* jobId - listener
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ import java.util.Map;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Timer Task implementation
|
||||||
* TimerTask实现
|
* TimerTask实现
|
||||||
|
*
|
||||||
* @author tomsun28
|
* @author tomsun28
|
||||||
* @date 2021/11/1 17:18
|
* @date 2021/11/1 17:18
|
||||||
*/
|
*/
|
||||||
@@ -36,12 +38,15 @@ public class WheelTimerTask implements TimerTask {
|
|||||||
public WheelTimerTask(Job job) {
|
public WheelTimerTask(Job job) {
|
||||||
this.metricsTaskDispatch = SpringContextHolder.getBean(MetricsTaskDispatch.class);
|
this.metricsTaskDispatch = SpringContextHolder.getBean(MetricsTaskDispatch.class);
|
||||||
this.job = job;
|
this.job = job;
|
||||||
|
// The initialization job will monitor the actual parameter value and replace the collection field
|
||||||
// 初始化job 将监控实际参数值对采集字段进行替换
|
// 初始化job 将监控实际参数值对采集字段进行替换
|
||||||
initJobMetrics(job);
|
initJobMetrics(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Initialize job fill information
|
||||||
* 初始化job填充信息
|
* 初始化job填充信息
|
||||||
|
*
|
||||||
* @param job job
|
* @param job job
|
||||||
*/
|
*/
|
||||||
private void initJobMetrics(Job job) {
|
private void initJobMetrics(Job job) {
|
||||||
@@ -73,9 +78,10 @@ public class WheelTimerTask implements TimerTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* json参数替换
|
* json parameter replacement json参数替换
|
||||||
|
*
|
||||||
* @param jsonElement json
|
* @param jsonElement json
|
||||||
* @param configmap 参数map
|
* @param configmap parameter map 参数map
|
||||||
* @return json
|
* @return json
|
||||||
*/
|
*/
|
||||||
private JsonElement replaceSpecialValue(JsonElement jsonElement, Map<String, Configmap> configmap) {
|
private JsonElement replaceSpecialValue(JsonElement jsonElement, Map<String, Configmap> configmap) {
|
||||||
@@ -86,6 +92,7 @@ public class WheelTimerTask implements TimerTask {
|
|||||||
Map.Entry<String, JsonElement> entry = iterator.next();
|
Map.Entry<String, JsonElement> entry = iterator.next();
|
||||||
JsonElement element = entry.getValue();
|
JsonElement element = entry.getValue();
|
||||||
String key = entry.getKey();
|
String key = entry.getKey();
|
||||||
|
// Replace the attributes of the KEY-VALUE case such as http headers params
|
||||||
// 替换KEY-VALUE情况的属性 比如http headers params
|
// 替换KEY-VALUE情况的属性 比如http headers params
|
||||||
if (key != null && key.startsWith("^_^") && key.endsWith("^_^")) {
|
if (key != null && key.startsWith("^_^") && key.endsWith("^_^")) {
|
||||||
key = key.replaceAll("\\^_\\^", "");
|
key = key.replaceAll("\\^_\\^", "");
|
||||||
@@ -104,8 +111,10 @@ public class WheelTimerTask implements TimerTask {
|
|||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// Replace normal VALUE value
|
||||||
// 替换正常的VALUE值
|
// 替换正常的VALUE值
|
||||||
if (element.isJsonPrimitive()) {
|
if (element.isJsonPrimitive()) {
|
||||||
|
// Check if there are special characters Replace
|
||||||
// 判断是否含有特殊字符 替换
|
// 判断是否含有特殊字符 替换
|
||||||
String value = element.getAsString();
|
String value = element.getAsString();
|
||||||
if (value.startsWith("^_^") && value.endsWith("^_^")) {
|
if (value.startsWith("^_^") && value.endsWith("^_^")) {
|
||||||
@@ -129,6 +138,7 @@ public class WheelTimerTask implements TimerTask {
|
|||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
JsonElement element = iterator.next();
|
JsonElement element = iterator.next();
|
||||||
if (element.isJsonPrimitive()) {
|
if (element.isJsonPrimitive()) {
|
||||||
|
// Check if there are special characters Replace
|
||||||
// 判断是否含有特殊字符 替换
|
// 判断是否含有特殊字符 替换
|
||||||
String value = element.getAsString();
|
String value = element.getAsString();
|
||||||
if (value.startsWith("^_^") && value.endsWith("^_^")) {
|
if (value.startsWith("^_^") && value.endsWith("^_^")) {
|
||||||
|
|||||||
@@ -6,8 +6,12 @@ import lombok.Data;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Monitoring configuration parameter properties and values
|
||||||
* 监控配置参数属性及值
|
* 监控配置参数属性及值
|
||||||
|
* During the process, you need to replace the content with the identifier ^_^key^_^
|
||||||
|
* in the protocol configuration parameter with the real value in the configuration parameter
|
||||||
* 过程中需要将协议配置参数里面的标识符为^_^key^_^的内容替换为配置参数里的真实值
|
* 过程中需要将协议配置参数里面的标识符为^_^key^_^的内容替换为配置参数里的真实值
|
||||||
|
*
|
||||||
* @author tomsun28
|
* @author tomsun28
|
||||||
* @date 2021/10/29 22:04
|
* @date 2021/10/29 22:04
|
||||||
*/
|
*/
|
||||||
@@ -18,16 +22,20 @@ import lombok.NoArgsConstructor;
|
|||||||
public class Configmap {
|
public class Configmap {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Parameter key, replace the content with the identifier ^^_key_^^ in the protocol
|
||||||
|
* configuration parameter with the real value in the configuration parameter
|
||||||
|
* <p>
|
||||||
* 参数key,将协议配置参数里面的标识符为^^_key_^^的内容替换为配置参数里的真实值
|
* 参数key,将协议配置参数里面的标识符为^^_key_^^的内容替换为配置参数里的真实值
|
||||||
*/
|
*/
|
||||||
private String key;
|
private String key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 参数value
|
* parameter value 参数value
|
||||||
*/
|
*/
|
||||||
private Object value;
|
private Object value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Parameter type 0: number 1: string 2: encrypted string 3: json string mapped by map
|
||||||
* 参数类型 0:数字 1:字符串 2:加密串 3:map映射的json串
|
* 参数类型 0:数字 1:字符串 2:加密串 3:map映射的json串
|
||||||
* number,string,secret
|
* number,string,secret
|
||||||
* 数字,非加密字符串,加密字符串
|
* 数字,非加密字符串,加密字符串
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ import java.util.Set;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Collect task details
|
||||||
* 采集任务详情
|
* 采集任务详情
|
||||||
|
*
|
||||||
* @author tomsun28
|
* @author tomsun28
|
||||||
* @date 2021/10/17 21:19
|
* @date 2021/10/17 21:19
|
||||||
*/
|
*/
|
||||||
@@ -35,61 +37,72 @@ public class Job {
|
|||||||
private static final String AVAILABILITY = "availability";
|
private static final String AVAILABILITY = "availability";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 任务ID
|
* Task id 任务ID
|
||||||
*/
|
*/
|
||||||
private long id;
|
private long id;
|
||||||
/**
|
/**
|
||||||
|
* Monitoring ID Application ID
|
||||||
* 监控ID 应用ID
|
* 监控ID 应用ID
|
||||||
*/
|
*/
|
||||||
private long monitorId;
|
private long monitorId;
|
||||||
/**
|
/**
|
||||||
* 监控的大类别
|
* Large categories of monitoring 监控的大类别
|
||||||
|
* service-application service monitoring db-database monitoring custom-custom monitoring os-operating system monitoring
|
||||||
* service-应用服务监控 db-数据库监控 custom-自定义监控 os-操作系统监控
|
* service-应用服务监控 db-数据库监控 custom-自定义监控 os-操作系统监控
|
||||||
*/
|
*/
|
||||||
private String category;
|
private String category;
|
||||||
/**
|
/**
|
||||||
|
* Type of monitoring eg: linux | mysql | jvm
|
||||||
* 监控的类型 eg: linux | mysql | jvm
|
* 监控的类型 eg: linux | mysql | jvm
|
||||||
*/
|
*/
|
||||||
private String app;
|
private String app;
|
||||||
/**
|
/**
|
||||||
* 监控类型的国际化名称
|
* The internationalized name of the monitoring type 监控类型的国际化名称
|
||||||
* zh-CN: PING连通性
|
* zh-CN: PING连通性
|
||||||
* en-US: PING CONNECT
|
* en-US: PING CONNECT
|
||||||
*/
|
*/
|
||||||
private Map<String, String> name;
|
private Map<String, String> name;
|
||||||
/**
|
/**
|
||||||
|
* Task dispatch start timestamp
|
||||||
* 任务派发开始时间戳
|
* 任务派发开始时间戳
|
||||||
*/
|
*/
|
||||||
private long timestamp;
|
private long timestamp;
|
||||||
/**
|
/**
|
||||||
|
* Task collection time interval (unit: second) eg: 30,60,600
|
||||||
* 任务采集时间间隔(单位秒) eg: 30,60,600
|
* 任务采集时间间隔(单位秒) eg: 30,60,600
|
||||||
*/
|
*/
|
||||||
private long interval = 600L;
|
private long interval = 600L;
|
||||||
/**
|
/**
|
||||||
|
* Whether it is a recurring periodic task true is yes, false is no
|
||||||
* 是否是循环周期性任务 true为是,false为否
|
* 是否是循环周期性任务 true为是,false为否
|
||||||
*/
|
*/
|
||||||
private boolean isCyclic = false;
|
private boolean isCyclic = false;
|
||||||
/**
|
/**
|
||||||
|
* Indicator group configuration eg: cpu memory
|
||||||
* 指标组配置 eg: cpu memory
|
* 指标组配置 eg: cpu memory
|
||||||
*/
|
*/
|
||||||
private List<Metrics> metrics;
|
private List<Metrics> metrics;
|
||||||
/**
|
/**
|
||||||
|
* Monitoring configuration parameter properties and values eg: username password timeout host
|
||||||
* 监控配置参数属性及值 eg: username password timeout host
|
* 监控配置参数属性及值 eg: username password timeout host
|
||||||
*/
|
*/
|
||||||
private List<Configmap> configmap;
|
private List<Configmap> configmap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* collector use - timestamp when the task was scheduled by the time wheel
|
||||||
* collector使用 - 任务被时间轮开始调度的时间戳
|
* collector使用 - 任务被时间轮开始调度的时间戳
|
||||||
*/
|
*/
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private transient long dispatchTime;
|
private transient long dispatchTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* collector use - task version, this field is not stored in etcd
|
||||||
* collector使用 - 任务版本,此字段不存储于etcd
|
* collector使用 - 任务版本,此字段不存储于etcd
|
||||||
*/
|
*/
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private transient long version;
|
private transient long version;
|
||||||
/**
|
/**
|
||||||
|
* collector usage - metric group task execution priority view
|
||||||
* collector使用 - 指标组任务执行优先级视图
|
* collector使用 - 指标组任务执行优先级视图
|
||||||
* 0 - availability
|
* 0 - availability
|
||||||
* 1 - cpu | memory
|
* 1 - cpu | memory
|
||||||
@@ -103,27 +116,32 @@ public class Job {
|
|||||||
private transient List<Set<Metrics>> priorMetrics;
|
private transient List<Set<Metrics>> priorMetrics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* collector use - Temporarily store one-time task indicator group response data
|
||||||
* collector使用 - 临时存储一次性任务指标组响应数据
|
* collector使用 - 临时存储一次性任务指标组响应数据
|
||||||
*/
|
*/
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private transient List<CollectRep.MetricsData> responseDataTemp;
|
private transient List<CollectRep.MetricsData> responseDataTemp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* collector uses - construct to initialize metrics group execution view
|
||||||
* collector使用 - 构造初始化指标组执行视图
|
* collector使用 - 构造初始化指标组执行视图
|
||||||
*/
|
*/
|
||||||
public synchronized void constructPriorMetrics() {
|
public synchronized void constructPriorMetrics() {
|
||||||
Map<Byte, List<Metrics>> map = metrics.stream()
|
Map<Byte, List<Metrics>> map = metrics.stream()
|
||||||
.peek(metric -> {
|
.peek(metric -> {
|
||||||
|
// Determine whether to configure aliasFields If not, configure the default
|
||||||
// 判断是否配置aliasFields 没有则配置默认
|
// 判断是否配置aliasFields 没有则配置默认
|
||||||
if (metric.getAliasFields() == null || metric.getAliasFields().isEmpty()) {
|
if (metric.getAliasFields() == null || metric.getAliasFields().isEmpty()) {
|
||||||
metric.setAliasFields(metric.getFields().stream().map(Metrics.Field::getField).collect(Collectors.toList()));
|
metric.setAliasFields(metric.getFields().stream().map(Metrics.Field::getField).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
// Set the default indicator group execution priority, if not filled, the default last priority
|
||||||
// 设置默认的指标组执行优先级,不填则默认最后优先级
|
// 设置默认的指标组执行优先级,不填则默认最后优先级
|
||||||
if (metric.getPriority() == null) {
|
if (metric.getPriority() == null) {
|
||||||
metric.setPriority(Byte.MAX_VALUE);
|
metric.setPriority(Byte.MAX_VALUE);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect(Collectors.groupingBy(Metrics::getPriority));
|
.collect(Collectors.groupingBy(Metrics::getPriority));
|
||||||
|
// Construct a linked list of task execution order of the indicator group
|
||||||
// 构造指标组任务执行顺序链表
|
// 构造指标组任务执行顺序链表
|
||||||
priorMetrics = new LinkedList<>();
|
priorMetrics = new LinkedList<>();
|
||||||
map.values().forEach(metric -> {
|
map.values().forEach(metric -> {
|
||||||
@@ -141,12 +159,18 @@ public class Job {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* collector use - to get the next set of priority metric group tasks
|
||||||
* collector使用 - 获取下一组优先级的指标组任务
|
* collector使用 - 获取下一组优先级的指标组任务
|
||||||
* @param metrics 当前指标组
|
*
|
||||||
* @param first 是否是第一次获取
|
* @param metrics Current indicator group 当前指标组
|
||||||
* @return 指标组任务
|
* @param first Is it the first time to get 是否是第一次获取
|
||||||
|
* @return Metric Group Tasks 指标组任务
|
||||||
|
* Returning null means: the job has been completed, and the collection of all indicator groups has ended
|
||||||
* 返回null表示:job已完成,所有指标组采集结束
|
* 返回null表示:job已完成,所有指标组采集结束
|
||||||
|
* Returning the empty set indicates that there are still indicator group collection tasks at the current
|
||||||
|
* level that have not been completed,and the next level indicator group task collection cannot be performed.
|
||||||
* 返回empty的集合表示:当前级别下还有指标组采集任务未结束,无法进行下一级别的指标组任务采集
|
* 返回empty的集合表示:当前级别下还有指标组采集任务未结束,无法进行下一级别的指标组任务采集
|
||||||
|
* Returns a set of data representation: get the next set of priority index group tasks
|
||||||
* 返回有数据集合表示:获取到下一组优先级的指标组任务
|
* 返回有数据集合表示:获取到下一组优先级的指标组任务
|
||||||
*/
|
*/
|
||||||
public synchronized Set<Metrics> getNextCollectMetrics(Metrics metrics, boolean first) {
|
public synchronized Set<Metrics> getNextCollectMetrics(Metrics metrics, boolean first) {
|
||||||
@@ -189,7 +213,7 @@ public class Job {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Job clone() {
|
public Job clone() {
|
||||||
// 深度克隆
|
// deep clone 深度克隆
|
||||||
return GsonUtil.fromJson(GsonUtil.toJson(this), Job.class);
|
return GsonUtil.fromJson(GsonUtil.toJson(this), Job.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Details of the collection of indicators collected by monitoring
|
||||||
|
* eg: cpu | memory | health
|
||||||
* 监控采集的指标集合详情 eg: cpu | memory | health
|
* 监控采集的指标集合详情 eg: cpu | memory | health
|
||||||
|
*
|
||||||
* @author tomsun28
|
* @author tomsun28
|
||||||
* @date 2021/10/17 21:24
|
* @date 2021/10/17 21:24
|
||||||
*/
|
*/
|
||||||
@@ -26,6 +29,7 @@ import java.util.Objects;
|
|||||||
public class Metrics {
|
public class Metrics {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* public property-name eg: cpu | memory | health
|
||||||
* 公共属性-名称 eg: cpu | memory | health
|
* 公共属性-名称 eg: cpu | memory | health
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
@@ -34,20 +38,27 @@ public class Metrics {
|
|||||||
*/
|
*/
|
||||||
private String protocol;
|
private String protocol;
|
||||||
/**
|
/**
|
||||||
|
* Range (0-127) indicator group scheduling priority, the smaller the value, the higher the priority
|
||||||
|
* The collection task of the next priority indicator group will be scheduled only after the scheduled collection with the higher priority is completed.
|
||||||
|
* The default priority of the availability indicator group is 0, and the range of other common indicator groups is 1-127, that is,
|
||||||
|
* the subsequent indicator group tasks will only be scheduled after the availability is collected successfully.
|
||||||
* 范围(0-127)指标组调度优先级,数值越小优先级越高
|
* 范围(0-127)指标组调度优先级,数值越小优先级越高
|
||||||
* 优先级高的调度采集完成后才会调度下一优先级的指标组采集任务
|
* 优先级高的调度采集完成后才会调度下一优先级的指标组采集任务
|
||||||
* 可用性指标组(availability)默认优先级为0,其它普通指标组范围为1-127,即需要等availability采集成功后才会调度后面的指标组任务
|
* 可用性指标组(availability)默认优先级为0,其它普通指标组范围为1-127,即需要等availability采集成功后才会调度后面的指标组任务
|
||||||
*/
|
*/
|
||||||
private Byte priority;
|
private Byte priority;
|
||||||
/**
|
/**
|
||||||
|
* Public attribute - collection and monitoring final result attribute set eg: speed | times | size
|
||||||
* 公共属性-采集监控的最终结果属性集合 eg: speed | times | size
|
* 公共属性-采集监控的最终结果属性集合 eg: speed | times | size
|
||||||
*/
|
*/
|
||||||
private List<Field> fields;
|
private List<Field> fields;
|
||||||
/**
|
/**
|
||||||
|
* Public attribute - collection and monitoring pre-query attribute set eg: size1 | size2 | speedSize
|
||||||
* 公共属性-采集监控的前置查询属性集合 eg: size1 | size2 | speedSize
|
* 公共属性-采集监控的前置查询属性集合 eg: size1 | size2 | speedSize
|
||||||
*/
|
*/
|
||||||
private List<String> aliasFields;
|
private List<String> aliasFields;
|
||||||
/**
|
/**
|
||||||
|
* Public attribute - expression calculation, map the pre-query attribute (pre Fields) with the final attribute (fields), and calculate the final attribute (fields) value
|
||||||
* 公共属性-表达式计算,将前置查询属性(preFields)与最终属性(fields)映射,计算出最终属性(fields)值
|
* 公共属性-表达式计算,将前置查询属性(preFields)与最终属性(fields)映射,计算出最终属性(fields)值
|
||||||
* eg: size = size1 + size2, speed = speedSize
|
* eg: size = size1 + size2, speed = speedSize
|
||||||
* https://www.yuque.com/boyan-avfmj/aviatorscript/ban32m
|
* https://www.yuque.com/boyan-avfmj/aviatorscript/ban32m
|
||||||
@@ -55,26 +66,32 @@ public class Metrics {
|
|||||||
private List<String> calculates;
|
private List<String> calculates;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Monitoring configuration information using the http protocol
|
||||||
* 使用http协议的监控配置信息
|
* 使用http协议的监控配置信息
|
||||||
*/
|
*/
|
||||||
private HttpProtocol http;
|
private HttpProtocol http;
|
||||||
/**
|
/**
|
||||||
|
* Monitoring configuration information for ping using the icmp protocol
|
||||||
* 使用icmp协议进行ping的监控配置信息
|
* 使用icmp协议进行ping的监控配置信息
|
||||||
*/
|
*/
|
||||||
private IcmpProtocol icmp;
|
private IcmpProtocol icmp;
|
||||||
/**
|
/**
|
||||||
|
* Monitoring configuration information using the telnet protocol
|
||||||
* 使用telnet协议的监控配置信息
|
* 使用telnet协议的监控配置信息
|
||||||
*/
|
*/
|
||||||
private TelnetProtocol telnet;
|
private TelnetProtocol telnet;
|
||||||
/**
|
/**
|
||||||
|
* Use tcp or ucp implemented by socket for service port detection configuration information
|
||||||
* 使用socket实现的tcp或ucp进行服务端口探测配置信息
|
* 使用socket实现的tcp或ucp进行服务端口探测配置信息
|
||||||
*/
|
*/
|
||||||
private TcpUdpProtocol tcpUdp;
|
private TcpUdpProtocol tcpUdp;
|
||||||
/**
|
/**
|
||||||
|
* Database configuration information implemented using the public jdbc specification
|
||||||
* 使用公共的jdbc规范实现的数据库配置信息
|
* 使用公共的jdbc规范实现的数据库配置信息
|
||||||
*/
|
*/
|
||||||
private JdbcProtocol jdbc;
|
private JdbcProtocol jdbc;
|
||||||
/**
|
/**
|
||||||
|
* Monitoring configuration information using the public ssh protocol
|
||||||
* 使用公共的ssh协议的监控配置信息
|
* 使用公共的ssh协议的监控配置信息
|
||||||
*/
|
*/
|
||||||
private SshProtocol ssh;
|
private SshProtocol ssh;
|
||||||
@@ -101,18 +118,22 @@ public class Metrics {
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public static class Field {
|
public static class Field {
|
||||||
/**
|
/**
|
||||||
|
* Indicator name
|
||||||
* 指标名称
|
* 指标名称
|
||||||
*/
|
*/
|
||||||
private String field;
|
private String field;
|
||||||
/**
|
/**
|
||||||
|
* Indicator type 0-number: number 1-string: string
|
||||||
* 指标类型 0-number:数字 1-string:字符串
|
* 指标类型 0-number:数字 1-string:字符串
|
||||||
*/
|
*/
|
||||||
private byte type = 1;
|
private byte type = 1;
|
||||||
/**
|
/**
|
||||||
|
* Whether this field is the instance primary key
|
||||||
* 此字段是否为实例主键
|
* 此字段是否为实例主键
|
||||||
*/
|
*/
|
||||||
private boolean instance = false;
|
private boolean instance = false;
|
||||||
/**
|
/**
|
||||||
|
* Indicator unit
|
||||||
* 指标单位
|
* 指标单位
|
||||||
*/
|
*/
|
||||||
private String unit;
|
private String unit;
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ import static io.swagger.annotations.ApiModelProperty.AccessMode.READ_ONLY;
|
|||||||
import static io.swagger.annotations.ApiModelProperty.AccessMode.READ_WRITE;
|
import static io.swagger.annotations.ApiModelProperty.AccessMode.READ_WRITE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Monitor parameter values
|
||||||
* 监控参数值
|
* 监控参数值
|
||||||
|
*
|
||||||
* @author tomsun28
|
* @author tomsun28
|
||||||
* @date 2021/11/13 22:19
|
* @date 2021/11/13 22:19
|
||||||
*/
|
*/
|
||||||
@@ -33,21 +35,26 @@ import static io.swagger.annotations.ApiModelProperty.AccessMode.READ_WRITE;
|
|||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@ApiModel(description = "参数实体")
|
@ApiModel(description = "嗯: Parameter Entity,zh: 参数实体")
|
||||||
public class Param {
|
public class Param {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parameter primary key index ID
|
||||||
|
*/
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@ApiModelProperty(value = "参数主键索引ID", example = "87584674384", accessMode = READ_ONLY, position = 0)
|
@ApiModelProperty(value = "参数主键索引ID", example = "87584674384", accessMode = READ_ONLY, position = 0)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Monitor ID
|
||||||
* 监控ID
|
* 监控ID
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "监控ID", example = "875846754543", accessMode = READ_WRITE, position = 1)
|
@ApiModelProperty(value = "监控ID", example = "875846754543", accessMode = READ_WRITE, position = 1)
|
||||||
private Long monitorId;
|
private Long monitorId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Parameter Field Identifier
|
||||||
* 参数字段标识符
|
* 参数字段标识符
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "参数标识符字段", example = "port", accessMode = READ_WRITE, position = 2)
|
@ApiModelProperty(value = "参数标识符字段", example = "port", accessMode = READ_WRITE, position = 2)
|
||||||
@@ -56,6 +63,7 @@ public class Param {
|
|||||||
private String field;
|
private String field;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Param Value
|
||||||
* 参数值
|
* 参数值
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "参数值", example = "8080", accessMode = READ_WRITE, position = 3)
|
@ApiModelProperty(value = "参数值", example = "8080", accessMode = READ_WRITE, position = 3)
|
||||||
@@ -63,6 +71,7 @@ public class Param {
|
|||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Parameter type 0: number 1: string 2: encrypted string 3: json string mapped by map
|
||||||
* 参数类型 0:数字 1:字符串 2:加密串 3:map映射的json串
|
* 参数类型 0:数字 1:字符串 2:加密串 3:map映射的json串
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "参数类型 0:数字 1:字符串 2:加密串 3:map映射的json串", accessMode = READ_WRITE, position = 4)
|
@ApiModelProperty(value = "参数类型 0:数字 1:字符串 2:加密串 3:map映射的json串", accessMode = READ_WRITE, position = 4)
|
||||||
@@ -71,6 +80,7 @@ public class Param {
|
|||||||
private byte type;
|
private byte type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Record Creation Time
|
||||||
* 记录创建时间
|
* 记录创建时间
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "记录创建时间(毫秒时间戳)", example = "1612198922000", accessMode = READ_ONLY, position = 5)
|
@ApiModelProperty(value = "记录创建时间(毫秒时间戳)", example = "1612198922000", accessMode = READ_ONLY, position = 5)
|
||||||
@@ -78,6 +88,7 @@ public class Param {
|
|||||||
private LocalDateTime gmtCreate;
|
private LocalDateTime gmtCreate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Record the latest modification time
|
||||||
* 记录最新修改时间
|
* 记录最新修改时间
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "记录最新修改时间(毫秒时间戳)", example = "1612198444000", accessMode = READ_ONLY, position = 6)
|
@ApiModelProperty(value = "记录最新修改时间(毫秒时间戳)", example = "1612198444000", accessMode = READ_ONLY, position = 6)
|
||||||
|
|||||||
@@ -1,175 +1,208 @@
|
|||||||
package com.usthe.common.util;
|
package com.usthe.common.util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Public Constant
|
||||||
* 公共常量
|
* 公共常量
|
||||||
|
*
|
||||||
* @author tomsun28
|
* @author tomsun28
|
||||||
* @date 2021/11/14 12:06
|
* @date 2021/11/14 12:06
|
||||||
*/
|
*/
|
||||||
public interface CommonConstants {
|
public interface CommonConstants {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Response status code: generic success
|
||||||
* 响应状态码: 通用成功
|
* 响应状态码: 通用成功
|
||||||
*/
|
*/
|
||||||
byte SUCCESS_CODE = 0x00;
|
byte SUCCESS_CODE = 0x00;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Response status code: generic failure
|
||||||
* 响应状态码: 通用失败
|
* 响应状态码: 通用失败
|
||||||
*/
|
*/
|
||||||
byte FAIL_CODE = 0x0F;
|
byte FAIL_CODE = 0x0F;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Response status code: Parameter verification failed
|
||||||
* 响应状态码: 参数校验失败
|
* 响应状态码: 参数校验失败
|
||||||
*/
|
*/
|
||||||
byte PARAM_INVALID_CODE = 0x01;
|
byte PARAM_INVALID_CODE = 0x01;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Response Status Code: Probe Failed
|
||||||
* 响应状态码: 探测失败
|
* 响应状态码: 探测失败
|
||||||
*/
|
*/
|
||||||
byte DETECT_FAILED_CODE = 0x02;
|
byte DETECT_FAILED_CODE = 0x02;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Response status code: monitoring does not exist
|
||||||
* 响应状态码: 监控不存在
|
* 响应状态码: 监控不存在
|
||||||
*/
|
*/
|
||||||
byte MONITOR_NOT_EXIST_CODE = 0x03;
|
byte MONITOR_NOT_EXIST_CODE = 0x03;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Response Status Code: Monitor Service Conflict
|
||||||
* 响应状态码: 监控服务冲突
|
* 响应状态码: 监控服务冲突
|
||||||
*/
|
*/
|
||||||
byte MONITOR_CONFLICT_CODE = 0x04;
|
byte MONITOR_CONFLICT_CODE = 0x04;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Response status code: Incorrect login account password
|
||||||
* 响应状态码: 登录账户密码错误
|
* 响应状态码: 登录账户密码错误
|
||||||
*/
|
*/
|
||||||
byte MONITOR_LOGIN_FAILED_CODE = 0x05;
|
byte MONITOR_LOGIN_FAILED_CODE = 0x05;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Response status code: Registration failed exception
|
||||||
* 响应状态码: 注册失败异常
|
* 响应状态码: 注册失败异常
|
||||||
*/
|
*/
|
||||||
byte MONITOR_REGISTER_FAILED_CODE = 0x06;
|
byte MONITOR_REGISTER_FAILED_CODE = 0x06;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Monitoring Status Code: Unmanaged
|
||||||
* 监控状态码: 未管理
|
* 监控状态码: 未管理
|
||||||
*/
|
*/
|
||||||
byte UN_MANAGE_CODE = 0x00;
|
byte UN_MANAGE_CODE = 0x00;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Monitoring Status Code: Available
|
||||||
* 监控状态码: 可用
|
* 监控状态码: 可用
|
||||||
*/
|
*/
|
||||||
byte AVAILABLE_CODE = 0x01;
|
byte AVAILABLE_CODE = 0x01;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Monitoring Status Code: Not Available
|
||||||
* 监控状态码: 不可用
|
* 监控状态码: 不可用
|
||||||
*/
|
*/
|
||||||
byte UN_AVAILABLE_CODE = 0x02;
|
byte UN_AVAILABLE_CODE = 0x02;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Monitoring Status Code: Unreachable
|
||||||
* 监控状态码: 不可达
|
* 监控状态码: 不可达
|
||||||
*/
|
*/
|
||||||
byte UN_REACHABLE_CODE = 0x03;
|
byte UN_REACHABLE_CODE = 0x03;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Monitoring Status Code: Pending
|
||||||
* 监控状态码: 挂起
|
* 监控状态码: 挂起
|
||||||
*/
|
*/
|
||||||
byte SUSPENDING_CODE = 0x04;
|
byte SUSPENDING_CODE = 0x04;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Alarm status: 0 - normal alarm (to be processed)
|
||||||
* 告警状态: 0-正常告警(待处理)
|
* 告警状态: 0-正常告警(待处理)
|
||||||
*/
|
*/
|
||||||
byte ALERT_STATUS_CODE_PENDING = 0x00;
|
byte ALERT_STATUS_CODE_PENDING = 0x00;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Alarm Status: 1 - Threshold triggered but not reached the number of alarms
|
||||||
* 告警状态: 1-阈值触发但未达到告警次数
|
* 告警状态: 1-阈值触发但未达到告警次数
|
||||||
*/
|
*/
|
||||||
byte ALERT_STATUS_CODE_NOT_REACH = 0x01;
|
byte ALERT_STATUS_CODE_NOT_REACH = 0x01;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Alarm Status: 2-Restore Alarm
|
||||||
* 告警状态: 2-恢复告警
|
* 告警状态: 2-恢复告警
|
||||||
*/
|
*/
|
||||||
byte ALERT_STATUS_CODE_RESTORED = 0x02;
|
byte ALERT_STATUS_CODE_RESTORED = 0x02;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Alert Status: 3-Handled
|
||||||
* 告警状态: 3-已处理
|
* 告警状态: 3-已处理
|
||||||
*/
|
*/
|
||||||
byte ALERT_STATUS_CODE_SOLVED = 0x03;
|
byte ALERT_STATUS_CODE_SOLVED = 0x03;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Alarm level: 0: high-emergency-emergency-red
|
||||||
* 告警级别: 0:高-emergency-紧急告警-红色
|
* 告警级别: 0:高-emergency-紧急告警-红色
|
||||||
*/
|
*/
|
||||||
byte ALERT_PRIORITY_CODE_EMERGENCY = 0x00;
|
byte ALERT_PRIORITY_CODE_EMERGENCY = 0x00;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Alarm severity: 1: medium-critical-critical alarm-orange
|
||||||
* 告警级别: 1:中-critical-严重告警-橙色
|
* 告警级别: 1:中-critical-严重告警-橙色
|
||||||
*/
|
*/
|
||||||
byte ALERT_PRIORITY_CODE_CRITICAL = 0x01;
|
byte ALERT_PRIORITY_CODE_CRITICAL = 0x01;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Warning level: 2: low-warning-warning warning-yellow
|
||||||
* 告警级别: 2:低-warning-警告告警-黄色
|
* 告警级别: 2:低-warning-警告告警-黄色
|
||||||
*/
|
*/
|
||||||
byte ALERT_PRIORITY_CODE_WARNING = 0x02;
|
byte ALERT_PRIORITY_CODE_WARNING = 0x02;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Field parameter type: number
|
||||||
* 字段参数类型: 数字
|
* 字段参数类型: 数字
|
||||||
*/
|
*/
|
||||||
byte TYPE_NUMBER = 0;
|
byte TYPE_NUMBER = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Field parameter type: String
|
||||||
* 字段参数类型: 字符串
|
* 字段参数类型: 字符串
|
||||||
*/
|
*/
|
||||||
byte TYPE_STRING = 1;
|
byte TYPE_STRING = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Field parameter type: encrypted string
|
||||||
* 字段参数类型: 加密字符串
|
* 字段参数类型: 加密字符串
|
||||||
*/
|
*/
|
||||||
byte TYPE_SECRET = 2;
|
byte TYPE_SECRET = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Collection indicator value: null placeholder for empty value
|
||||||
* 采集指标值:null空值占位符
|
* 采集指标值:null空值占位符
|
||||||
*/
|
*/
|
||||||
String NULL_VALUE = " ";
|
String NULL_VALUE = " ";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Availability Object
|
||||||
* 可用性对象
|
* 可用性对象
|
||||||
*/
|
*/
|
||||||
String AVAILABLE = "available";
|
String AVAILABLE = "available";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 可达性对象
|
* Reachability Object可达性对象
|
||||||
*/
|
*/
|
||||||
String REACHABLE = "reachable";
|
String REACHABLE = "reachable";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Parameter Type Number
|
||||||
* 参数类型 数字
|
* 参数类型 数字
|
||||||
*/
|
*/
|
||||||
byte PARAM_TYPE_NUMBER = 0;
|
byte PARAM_TYPE_NUMBER = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Parameter Type String
|
||||||
* 参数类型 字符串
|
* 参数类型 字符串
|
||||||
*/
|
*/
|
||||||
byte PARAM_TYPE_STRING = 1;
|
byte PARAM_TYPE_STRING = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Parameter Type Password
|
||||||
* 参数类型 密码
|
* 参数类型 密码
|
||||||
*/
|
*/
|
||||||
byte PARAM_TYPE_PASSWORD = 2;
|
byte PARAM_TYPE_PASSWORD = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Authentication type Account password
|
||||||
* 认证类型 账户密码
|
* 认证类型 账户密码
|
||||||
*/
|
*/
|
||||||
byte AUTH_TYPE_PASSWORD = 1;
|
byte AUTH_TYPE_PASSWORD = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Authentication type GITHUB three-party login
|
||||||
* 认证类型 GITHUB三方登录
|
* 认证类型 GITHUB三方登录
|
||||||
*/
|
*/
|
||||||
byte AUTH_TYPE_GITHUB = 2;
|
byte AUTH_TYPE_GITHUB = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Authentication type WeChat three-party login
|
||||||
* 认证类型 微信三方登录
|
* 认证类型 微信三方登录
|
||||||
*/
|
*/
|
||||||
byte AUTH_TYPE_WEIXIN = 3;
|
byte AUTH_TYPE_WEIXIN = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Authentication type GITEE three-party login
|
||||||
* 认证类型 GITEE三方登录
|
* 认证类型 GITEE三方登录
|
||||||
*/
|
*/
|
||||||
byte AUTH_TYPE_GITEE = 5;
|
byte AUTH_TYPE_GITEE = 5;
|
||||||
|
|||||||
@@ -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.common.entity.manager.Monitor;
|
||||||
import com.usthe.manager.pojo.dto.MonitorDto;
|
import com.usthe.manager.pojo.dto.MonitorDto;
|
||||||
import com.usthe.manager.service.MonitorService;
|
import com.usthe.manager.service.MonitorService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@@ -23,11 +24,13 @@ import static com.usthe.common.util.CommonConstants.MONITOR_NOT_EXIST_CODE;
|
|||||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Monitoring management API
|
||||||
* 监控管理API
|
* 监控管理API
|
||||||
|
*
|
||||||
* @author tomsun28
|
* @author tomsun28
|
||||||
* @date 2021/11/14 10:57
|
* @date 2021/11/14 10:57
|
||||||
*/
|
*/
|
||||||
@Api(tags = "监控管理API")
|
@Api(tags = "en: Monitoring management API,zh: 监控管理API")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(path = "/monitor", produces = {APPLICATION_JSON_VALUE})
|
@RequestMapping(path = "/monitor", produces = {APPLICATION_JSON_VALUE})
|
||||||
public class MonitorController {
|
public class MonitorController {
|
||||||
@@ -36,12 +39,12 @@ public class MonitorController {
|
|||||||
private MonitorService monitorService;
|
private MonitorService monitorService;
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ApiOperation(value = "新增监控", notes = "新增一个监控应用")
|
@ApiOperation(value = "Add a monitoring application", notes = "新增一个监控应用")
|
||||||
public ResponseEntity<Message<Void>> addNewMonitor(@Valid @RequestBody MonitorDto monitorDto) {
|
public ResponseEntity<Message<Void>> addNewMonitor(@Valid @RequestBody MonitorDto monitorDto) {
|
||||||
// 校验请求数据
|
// Verify request data 校验请求数据
|
||||||
monitorService.validate(monitorDto, false);
|
monitorService.validate(monitorDto, false);
|
||||||
if (monitorDto.isDetected()) {
|
if (monitorDto.isDetected()) {
|
||||||
// 进行探测
|
// Probe 进行探测
|
||||||
monitorService.detectMonitor(monitorDto.getMonitor(), monitorDto.getParams());
|
monitorService.detectMonitor(monitorDto.getMonitor(), monitorDto.getParams());
|
||||||
}
|
}
|
||||||
monitorService.addMonitor(monitorDto.getMonitor(), monitorDto.getParams());
|
monitorService.addMonitor(monitorDto.getMonitor(), monitorDto.getParams());
|
||||||
@@ -49,12 +52,12 @@ public class MonitorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@ApiOperation(value = "修改监控", notes = "修改一个已存在监控应用")
|
@ApiOperation(value = "Modify an existing monitoring application", notes = "修改一个已存在监控应用")
|
||||||
public ResponseEntity<Message<Void>> modifyMonitor(@Valid @RequestBody MonitorDto monitorDto) {
|
public ResponseEntity<Message<Void>> modifyMonitor(@Valid @RequestBody MonitorDto monitorDto) {
|
||||||
// 校验请求数据
|
// Verify request data 校验请求数据
|
||||||
monitorService.validate(monitorDto, true);
|
monitorService.validate(monitorDto, true);
|
||||||
if (monitorDto.isDetected()) {
|
if (monitorDto.isDetected()) {
|
||||||
// 进行探测
|
// Probe 进行探测
|
||||||
monitorService.detectMonitor(monitorDto.getMonitor(), monitorDto.getParams());
|
monitorService.detectMonitor(monitorDto.getMonitor(), monitorDto.getParams());
|
||||||
}
|
}
|
||||||
monitorService.modifyMonitor(monitorDto.getMonitor(), monitorDto.getParams());
|
monitorService.modifyMonitor(monitorDto.getMonitor(), monitorDto.getParams());
|
||||||
@@ -62,9 +65,10 @@ public class MonitorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(path = "/{id}")
|
@GetMapping(path = "/{id}")
|
||||||
@ApiOperation(value = "查询监控", notes = "根据监控ID获取监控信息")
|
@ApiOperation(value = "Obtain monitoring information based on monitoring ID", notes = "根据监控ID获取监控信息")
|
||||||
public ResponseEntity<Message<MonitorDto>> getMonitor(
|
public ResponseEntity<Message<MonitorDto>> getMonitor(
|
||||||
@ApiParam(value = "监控ID", example = "6565463543") @PathVariable("id") final long id) {
|
@ApiParam(value = "监控ID", example = "6565463543") @PathVariable("id") final long id) {
|
||||||
|
// Get monitoring information
|
||||||
// 获取监控信息
|
// 获取监控信息
|
||||||
MonitorDto monitorDto = monitorService.getMonitorDto(id);
|
MonitorDto monitorDto = monitorService.getMonitorDto(id);
|
||||||
Message.MessageBuilder<MonitorDto> messageBuilder = Message.builder();
|
Message.MessageBuilder<MonitorDto> messageBuilder = Message.builder();
|
||||||
@@ -77,16 +81,20 @@ public class MonitorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping(path = "/{id}")
|
@DeleteMapping(path = "/{id}")
|
||||||
@ApiOperation(value = "删除监控", notes = "根据监控ID删除监控应用,监控不存在也是删除成功")
|
@ApiOperation(value = "Delete monitoring application based on monitoring ID", notes = "根据监控ID删除监控应用")
|
||||||
public ResponseEntity<Message<Void>> deleteMonitor(
|
public ResponseEntity<Message<Void>> deleteMonitor(
|
||||||
@ApiParam(value = "监控ID", example = "6565463543") @PathVariable("id") final long id) {
|
@ApiParam(value = "en: Monitor ID,zh: 监控ID", example = "6565463543") @PathVariable("id") final long id) {
|
||||||
// 删除监控,监控不存在或删除成功都返回成功
|
// delete monitor 删除监控
|
||||||
|
Monitor monitor = monitorService.getMonitor(id);
|
||||||
|
if (monitor == null) {
|
||||||
|
return ResponseEntity.ok(new Message<>("The specified monitoring was not queried, please check whether the parameters are correct"));
|
||||||
|
}
|
||||||
monitorService.deleteMonitor(id);
|
monitorService.deleteMonitor(id);
|
||||||
return ResponseEntity.ok(new Message<>("Delete success"));
|
return ResponseEntity.ok(new Message<>("Delete success"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(path = "/detect")
|
@PostMapping(path = "/detect")
|
||||||
@ApiOperation(value = "探测监控", notes = "根据监控信息去对此监控进行可用性探测")
|
@ApiOperation(value = "Perform availability detection on this monitoring based on monitoring information", notes = "根据监控信息去对此监控进行可用性探测")
|
||||||
public ResponseEntity<Message<Void>> detectMonitor(@Valid @RequestBody MonitorDto monitorDto) {
|
public ResponseEntity<Message<Void>> detectMonitor(@Valid @RequestBody MonitorDto monitorDto) {
|
||||||
monitorService.validate(monitorDto, null);
|
monitorService.validate(monitorDto, null);
|
||||||
monitorService.detectMonitor(monitorDto.getMonitor(), monitorDto.getParams());
|
monitorService.detectMonitor(monitorDto.getMonitor(), monitorDto.getParams());
|
||||||
|
|||||||
@@ -8,27 +8,34 @@ import java.util.Set;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ParamDao 数据库操作
|
* ParamDao 数据库操作
|
||||||
|
*
|
||||||
* @author tomsun28
|
* @author tomsun28
|
||||||
* @date 2021/11/14 11:26
|
* @date 2021/11/14 11:26
|
||||||
*/
|
*/
|
||||||
public interface ParamDao extends JpaRepository<Param, Long> {
|
public interface ParamDao extends JpaRepository<Param, Long> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Query the list of parameters associated with the monitoring ID'
|
||||||
* 根据监控ID查询与之关联的参数列表
|
* 根据监控ID查询与之关联的参数列表
|
||||||
* @param monitorId 监控ID
|
*
|
||||||
* @return 参数值列表
|
* @param monitorId Monitor ID 监控ID
|
||||||
|
* @return list of parameter values 参数值列表
|
||||||
*/
|
*/
|
||||||
List<Param> findParamsByMonitorId(long monitorId);
|
List<Param> findParamsByMonitorId(long monitorId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Remove the parameter list associated with the monitoring ID based on it
|
||||||
* 根据监控ID删除与之关联的参数列表
|
* 根据监控ID删除与之关联的参数列表
|
||||||
* @param monitorId 监控ID
|
*
|
||||||
|
* @param monitorId Monitor Id 监控ID
|
||||||
*/
|
*/
|
||||||
void deleteParamsByMonitorId(long monitorId);
|
void deleteParamsByMonitorId(long monitorId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Remove the parameter list associated with the monitoring ID list based on it
|
||||||
* 根据监控ID列表删除与之关联的参数列表
|
* 根据监控ID列表删除与之关联的参数列表
|
||||||
* @param monitorIds 监控ID列表
|
*
|
||||||
|
* @param monitorIds Monitoring ID List 监控ID列表
|
||||||
*/
|
*/
|
||||||
void deleteParamsByMonitorIdIn(Set<Long> monitorIds);
|
void deleteParamsByMonitorIdIn(Set<Long> monitorIds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,15 +14,18 @@ import static io.swagger.annotations.ApiModelProperty.AccessMode.READ_ONLY;
|
|||||||
import static io.swagger.annotations.ApiModelProperty.AccessMode.READ_WRITE;
|
import static io.swagger.annotations.ApiModelProperty.AccessMode.READ_WRITE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Monitoring Information External Interaction Entities
|
||||||
* 监控信息对外交互实体
|
* 监控信息对外交互实体
|
||||||
|
*
|
||||||
* @author tomsun28
|
* @author tomsun28
|
||||||
* @date 2021/11/14 10:13
|
* @date 2021/11/14 10:13
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@ApiModel(description = "监控信息实体")
|
@ApiModel(description = "en: Monitoring information entities,zh: 监控信息实体")
|
||||||
public class MonitorDto {
|
public class MonitorDto {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Monitoring entity
|
||||||
* 监控实体
|
* 监控实体
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "监控实体", accessMode = READ_WRITE, position = 0)
|
@ApiModelProperty(value = "监控实体", accessMode = READ_WRITE, position = 0)
|
||||||
@@ -31,17 +34,22 @@ public class MonitorDto {
|
|||||||
private Monitor monitor;
|
private Monitor monitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 参数
|
* Params 参数
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "监控参数", accessMode = READ_WRITE, position = 1)
|
@ApiModelProperty(value = "监控参数", accessMode = READ_WRITE, position = 1)
|
||||||
@NotNull
|
@NotNull
|
||||||
@Valid
|
@Valid
|
||||||
private List<Param> params;
|
private List<Param> params;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of indicator groups
|
||||||
|
* 指标组列表
|
||||||
|
*/
|
||||||
@ApiModelProperty(value = "指标组列表", accessMode = READ_ONLY, position = 2)
|
@ApiModelProperty(value = "指标组列表", accessMode = READ_ONLY, position = 2)
|
||||||
private List<String> metrics;
|
private List<String> metrics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Whether to detect
|
||||||
* 是否探测
|
* 是否探测
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "是否进行探测", accessMode = READ_WRITE, position = 3)
|
@ApiModelProperty(value = "是否进行探测", accessMode = READ_WRITE, position = 3)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 监控类型管理接口
|
* 监控类型管理接口
|
||||||
|
*
|
||||||
* @author tomsun28
|
* @author tomsun28
|
||||||
* @date 2021/11/14 17:12
|
* @date 2021/11/14 17:12
|
||||||
*/
|
*/
|
||||||
@@ -16,21 +17,26 @@ public interface AppService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据监控类型查询定义的参数结构
|
* 根据监控类型查询定义的参数结构
|
||||||
|
*
|
||||||
* @param app 监控类型
|
* @param app 监控类型
|
||||||
* @return 参数结构列表
|
* @return 参数结构列表
|
||||||
*/
|
*/
|
||||||
List<ParamDefine> getAppParamDefines(String app);
|
List<ParamDefine> getAppParamDefines(String app);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get monitor structure definition based on monitor type name
|
||||||
* 根据监控类型名称获取监控结构定义
|
* 根据监控类型名称获取监控结构定义
|
||||||
* @param app 监控类型名称
|
*
|
||||||
* @return 监控结构定义
|
* @param app Monitoring type name 监控类型名称
|
||||||
* @throws IllegalArgumentException 当不存在即不支持对应名称的监控类型时抛出
|
* @return Monitoring Structure Definition 监控结构定义
|
||||||
|
* @throws IllegalArgumentException Thrown when there is no monitoring type with the corresponding name that is not supported
|
||||||
|
* 当不存在即不支持对应名称的监控类型时抛出
|
||||||
*/
|
*/
|
||||||
Job getAppDefine(String app) throws IllegalArgumentException;
|
Job getAppDefine(String app) throws IllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取定义的监控I18N资源
|
* 获取定义的监控I18N资源
|
||||||
|
*
|
||||||
* @param lang 语言类型
|
* @param lang 语言类型
|
||||||
* @return I18N资源
|
* @return I18N资源
|
||||||
*/
|
*/
|
||||||
@@ -38,6 +44,7 @@ public interface AppService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询所有监控的类型-指标组-指标层级
|
* 查询所有监控的类型-指标组-指标层级
|
||||||
|
*
|
||||||
* @param lang 语言
|
* @param lang 语言
|
||||||
* @return 层级信息
|
* @return 层级信息
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -23,46 +23,50 @@ public interface MonitorService {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Monitoring Availability Probes
|
||||||
* 监控可用性探测
|
* 监控可用性探测
|
||||||
*
|
*
|
||||||
* @param monitor 监控实体信息
|
* @param monitor Monitoring entity information 监控实体信息
|
||||||
* @param params 参数信息
|
* @param params Parameter information 参数信息
|
||||||
* @throws MonitorDetectException 探测失败抛出
|
* @throws MonitorDetectException Probe failure throws 探测失败抛出
|
||||||
*/
|
*/
|
||||||
void detectMonitor(Monitor monitor, List<Param> params) throws MonitorDetectException;
|
void detectMonitor(Monitor monitor, List<Param> params) throws MonitorDetectException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增监控
|
* Add monitoring 新增监控
|
||||||
*
|
*
|
||||||
* @param monitor 监控实体
|
* @param monitor Monitoring Entity 监控实体
|
||||||
* @param params 参数信息
|
* @param params Parameter information 参数信息
|
||||||
* @throws RuntimeException 新增过程异常抛出
|
* @throws RuntimeException Add process exception throw 新增过程异常抛出
|
||||||
*/
|
*/
|
||||||
void addMonitor(Monitor monitor, List<Param> params) throws RuntimeException;
|
void addMonitor(Monitor monitor, List<Param> params) throws RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Verify the correctness of request data parameters
|
||||||
* 校验请求数据参数正确性
|
* 校验请求数据参数正确性
|
||||||
*
|
*
|
||||||
* @param monitorDto monitorDto
|
* @param monitorDto monitorDto
|
||||||
* @param isModify 是否是修改监控
|
* @param isModify Whether it is a modification monitoring 是否是修改监控
|
||||||
* @throws IllegalArgumentException 校验参数错误抛出
|
* @throws IllegalArgumentException Validation parameter error thrown 校验参数错误抛出
|
||||||
*/
|
*/
|
||||||
void validate(MonitorDto monitorDto, Boolean isModify) throws IllegalArgumentException;
|
void validate(MonitorDto monitorDto, Boolean isModify) throws IllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Modify update monitoring
|
||||||
* 修改更新监控
|
* 修改更新监控
|
||||||
*
|
*
|
||||||
* @param monitor 监控实体
|
* @param monitor Monitor Entity 监控实体
|
||||||
* @param params 参数信息
|
* @param params Parameter information 参数信息
|
||||||
* @throws RuntimeException 修改过程中异常抛出
|
* @throws RuntimeException Exception thrown during modification 修改过程中异常抛出
|
||||||
*/
|
*/
|
||||||
void modifyMonitor(Monitor monitor, List<Param> params) throws RuntimeException;
|
void modifyMonitor(Monitor monitor, List<Param> params) throws RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Delete Monitor
|
||||||
* 删除监控
|
* 删除监控
|
||||||
*
|
*
|
||||||
* @param id 监控ID
|
* @param id Monitor ID 监控ID
|
||||||
* @throws RuntimeException 删除过程中异常抛出
|
* @throws RuntimeException Exception thrown during deletion 删除过程中异常抛出
|
||||||
*/
|
*/
|
||||||
void deleteMonitor(long id) throws RuntimeException;
|
void deleteMonitor(long id) throws RuntimeException;
|
||||||
|
|
||||||
|
|||||||
@@ -81,11 +81,13 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
List<Configmap> configmaps = params.stream().map(param ->
|
List<Configmap> configmaps = params.stream().map(param ->
|
||||||
new Configmap(param.getField(), param.getValue(), param.getType())).collect(Collectors.toList());
|
new Configmap(param.getField(), param.getValue(), param.getType())).collect(Collectors.toList());
|
||||||
appDefine.setConfigmap(configmaps);
|
appDefine.setConfigmap(configmaps);
|
||||||
|
// To detect availability, you only need to collect the set of availability indicators with a priority of 0.
|
||||||
// 探测可用性只需要采集优先级为0的可用性指标集合
|
// 探测可用性只需要采集优先级为0的可用性指标集合
|
||||||
List<Metrics> availableMetrics = appDefine.getMetrics().stream()
|
List<Metrics> availableMetrics = appDefine.getMetrics().stream()
|
||||||
.filter(item -> item.getPriority() == 0).collect(Collectors.toList());
|
.filter(item -> item.getPriority() == 0).collect(Collectors.toList());
|
||||||
appDefine.setMetrics(availableMetrics);
|
appDefine.setMetrics(availableMetrics);
|
||||||
List<CollectRep.MetricsData> collectRep = collectJobService.collectSyncJobData(appDefine);
|
List<CollectRep.MetricsData> collectRep = collectJobService.collectSyncJobData(appDefine);
|
||||||
|
// If the detection result fails, a detection exception is thrown
|
||||||
// 判断探测结果 失败则抛出探测异常
|
// 判断探测结果 失败则抛出探测异常
|
||||||
if (collectRep == null || collectRep.isEmpty()) {
|
if (collectRep == null || collectRep.isEmpty()) {
|
||||||
throw new MonitorDetectException("No collector response");
|
throw new MonitorDetectException("No collector response");
|
||||||
@@ -98,9 +100,9 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void addMonitor(Monitor monitor, List<Param> params) throws RuntimeException {
|
public void addMonitor(Monitor monitor, List<Param> params) throws RuntimeException {
|
||||||
// 申请 monitor id
|
// Apply for monitor id 申请 monitor id
|
||||||
long monitorId = SnowFlakeIdGenerator.generateId();
|
long monitorId = SnowFlakeIdGenerator.generateId();
|
||||||
// 构造采集任务Job实体
|
// Construct the collection task Job entity 构造采集任务Job实体
|
||||||
Job appDefine = appService.getAppDefine(monitor.getApp());
|
Job appDefine = appService.getAppDefine(monitor.getApp());
|
||||||
appDefine.setMonitorId(monitorId);
|
appDefine.setMonitorId(monitorId);
|
||||||
appDefine.setInterval(monitor.getIntervals());
|
appDefine.setInterval(monitor.getIntervals());
|
||||||
@@ -111,8 +113,10 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
return new Configmap(param.getField(), param.getValue(), param.getType());
|
return new Configmap(param.getField(), param.getValue(), param.getType());
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
appDefine.setConfigmap(configmaps);
|
appDefine.setConfigmap(configmaps);
|
||||||
|
// Send the collection task to get the job ID
|
||||||
// 下发采集任务得到jobId
|
// 下发采集任务得到jobId
|
||||||
long jobId = collectJobService.addAsyncCollectJob(appDefine);
|
long jobId = collectJobService.addAsyncCollectJob(appDefine);
|
||||||
|
// Brush the library after the download is successful
|
||||||
// 下发成功后刷库
|
// 下发成功后刷库
|
||||||
try {
|
try {
|
||||||
monitor.setId(monitorId);
|
monitor.setId(monitorId);
|
||||||
@@ -122,6 +126,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
paramDao.saveAll(params);
|
paramDao.saveAll(params);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
|
// Repository brushing abnormally cancels the previously delivered task
|
||||||
// 刷库异常取消之前的下发任务
|
// 刷库异常取消之前的下发任务
|
||||||
collectJobService.cancelAsyncCollectJob(jobId);
|
collectJobService.cancelAsyncCollectJob(jobId);
|
||||||
throw new MonitorDatabaseException(e.getMessage());
|
throw new MonitorDatabaseException(e.getMessage());
|
||||||
@@ -131,6 +136,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public void validate(MonitorDto monitorDto, Boolean isModify) throws IllegalArgumentException {
|
public void validate(MonitorDto monitorDto, Boolean isModify) throws IllegalArgumentException {
|
||||||
|
// The request monitoring parameter matches the monitoring parameter definition mapping check
|
||||||
// 请求监控参数与监控参数定义映射校验匹配
|
// 请求监控参数与监控参数定义映射校验匹配
|
||||||
Monitor monitor = monitorDto.getMonitor();
|
Monitor monitor = monitorDto.getMonitor();
|
||||||
monitor.setHost(monitor.getHost().trim());
|
monitor.setHost(monitor.getHost().trim());
|
||||||
@@ -143,7 +149,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
param.setValue(value);
|
param.setValue(value);
|
||||||
})
|
})
|
||||||
.collect(Collectors.toMap(Param::getField, param -> param));
|
.collect(Collectors.toMap(Param::getField, param -> param));
|
||||||
// 校验名称唯一性
|
// Check name uniqueness 校验名称唯一性
|
||||||
if (isModify != null) {
|
if (isModify != null) {
|
||||||
Optional<Monitor> monitorOptional = monitorDao.findMonitorByNameEquals(monitor.getName());
|
Optional<Monitor> monitorOptional = monitorDao.findMonitorByNameEquals(monitor.getName());
|
||||||
if (monitorOptional.isPresent()) {
|
if (monitorOptional.isPresent()) {
|
||||||
@@ -158,7 +164,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 参数定义结构校验
|
// Parameter definition structure verification 参数定义结构校验
|
||||||
List<ParamDefine> paramDefines = appService.getAppParamDefines(monitorDto.getMonitor().getApp());
|
List<ParamDefine> paramDefines = appService.getAppParamDefines(monitorDto.getMonitor().getApp());
|
||||||
if (paramDefines != null) {
|
if (paramDefines != null) {
|
||||||
for (ParamDefine paramDefine : paramDefines) {
|
for (ParamDefine paramDefine : paramDefines) {
|
||||||
@@ -204,6 +210,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "password":
|
case "password":
|
||||||
|
// The plaintext password needs to be encrypted for transmission and storage
|
||||||
// 明文密码需加密传输存储
|
// 明文密码需加密传输存储
|
||||||
String passwordValue = param.getValue();
|
String passwordValue = param.getValue();
|
||||||
if (!AesUtil.isCiphertext(passwordValue)) {
|
if (!AesUtil.isCiphertext(passwordValue)) {
|
||||||
@@ -213,7 +220,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
param.setType(CommonConstants.PARAM_TYPE_PASSWORD);
|
param.setType(CommonConstants.PARAM_TYPE_PASSWORD);
|
||||||
break;
|
break;
|
||||||
case "boolean":
|
case "boolean":
|
||||||
// boolean校验
|
// boolean check
|
||||||
String booleanValue = param.getValue();
|
String booleanValue = param.getValue();
|
||||||
try {
|
try {
|
||||||
Boolean.parseBoolean(booleanValue);
|
Boolean.parseBoolean(booleanValue);
|
||||||
@@ -223,7 +230,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "radio":
|
case "radio":
|
||||||
// radio单选值校验
|
// radio single value check radio单选值校验
|
||||||
List<ParamDefine.Option> options = paramDefine.getOptions();
|
List<ParamDefine.Option> options = paramDefine.getOptions();
|
||||||
boolean invalid = true;
|
boolean invalid = true;
|
||||||
if (options != null) {
|
if (options != null) {
|
||||||
@@ -245,7 +252,8 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
case "key-value":
|
case "key-value":
|
||||||
// todo key-value校验
|
// todo key-value校验
|
||||||
break;
|
break;
|
||||||
// todo 更多参数定义与实际值格式校验
|
// todo More parameter definitions and actual value format verification
|
||||||
|
// 更多参数定义与实际值格式校验
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("ParamDefine type " + paramDefine.getType() + " is invalid.");
|
throw new IllegalArgumentException("ParamDefine type " + paramDefine.getType() + " is invalid.");
|
||||||
}
|
}
|
||||||
@@ -255,8 +263,10 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void modifyMonitor(Monitor monitor, List<Param> params) throws RuntimeException {
|
public void modifyMonitor(Monitor monitor, List<Param> params) throws RuntimeException {
|
||||||
long monitorId = monitor.getId();
|
long monitorId = monitor.getId();
|
||||||
|
// Check to determine whether the monitor corresponding to the monitor Id exists
|
||||||
// 查判断monitorId对应的此监控是否存在
|
// 查判断monitorId对应的此监控是否存在
|
||||||
Optional<Monitor> queryOption = monitorDao.findById(monitorId);
|
Optional<Monitor> queryOption = monitorDao.findById(monitorId);
|
||||||
if (!queryOption.isPresent()) {
|
if (!queryOption.isPresent()) {
|
||||||
@@ -264,9 +274,11 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
}
|
}
|
||||||
Monitor preMonitor = queryOption.get();
|
Monitor preMonitor = queryOption.get();
|
||||||
if (!preMonitor.getApp().equals(monitor.getApp())) {
|
if (!preMonitor.getApp().equals(monitor.getApp())) {
|
||||||
|
// The type of monitoring cannot be modified
|
||||||
// 监控的类型不能修改
|
// 监控的类型不能修改
|
||||||
throw new IllegalArgumentException("Can not modify monitor's app type");
|
throw new IllegalArgumentException("Can not modify monitor's app type");
|
||||||
}
|
}
|
||||||
|
// Construct the collection task Job entity
|
||||||
// 构造采集任务Job实体
|
// 构造采集任务Job实体
|
||||||
Job appDefine = appService.getAppDefine(monitor.getApp());
|
Job appDefine = appService.getAppDefine(monitor.getApp());
|
||||||
appDefine.setId(preMonitor.getJobId());
|
appDefine.setId(preMonitor.getJobId());
|
||||||
@@ -277,14 +289,16 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
List<Configmap> configmaps = params.stream().map(param ->
|
List<Configmap> configmaps = params.stream().map(param ->
|
||||||
new Configmap(param.getField(), param.getValue(), param.getType())).collect(Collectors.toList());
|
new Configmap(param.getField(), param.getValue(), param.getType())).collect(Collectors.toList());
|
||||||
appDefine.setConfigmap(configmaps);
|
appDefine.setConfigmap(configmaps);
|
||||||
// 更新采集任务
|
// After the update is successfully released, refresh the library
|
||||||
collectJobService.updateAsyncCollectJob(appDefine);
|
|
||||||
// 下发更新成功后刷库
|
// 下发更新成功后刷库
|
||||||
try {
|
try {
|
||||||
monitor.setJobId(preMonitor.getJobId());
|
monitor.setJobId(preMonitor.getJobId());
|
||||||
monitor.setStatus(preMonitor.getStatus());
|
monitor.setStatus(preMonitor.getStatus());
|
||||||
monitorDao.save(monitor);
|
monitorDao.save(monitor);
|
||||||
paramDao.saveAll(params);
|
paramDao.saveAll(params);
|
||||||
|
// Update the collection task after the storage is completed
|
||||||
|
// 入库完成后更新采集任务
|
||||||
|
collectJobService.updateAsyncCollectJob(appDefine);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
throw new MonitorDatabaseException(e.getMessage());
|
throw new MonitorDatabaseException(e.getMessage());
|
||||||
|
|||||||
Reference in New Issue
Block a user