|
|
@@ -80,11 +80,13 @@ public class MonitorServiceImpl implements MonitorService {
|
|
|
List<Configmap> configmaps = params.stream().map(param ->
|
|
|
new Configmap(param.getField(), param.getValue(), param.getType())).collect(Collectors.toList());
|
|
|
appDefine.setConfigmap(configmaps);
|
|
|
+ // To detect availability, you only need to collect the set of availability indicators with a priority of 0.
|
|
|
// 探测可用性只需要采集优先级为0的可用性指标集合
|
|
|
List<Metrics> availableMetrics = appDefine.getMetrics().stream()
|
|
|
.filter(item -> item.getPriority() == 0).collect(Collectors.toList());
|
|
|
appDefine.setMetrics(availableMetrics);
|
|
|
List<CollectRep.MetricsData> collectRep = collectJobService.collectSyncJobData(appDefine);
|
|
|
+ // If the detection result fails, a detection exception is thrown
|
|
|
// 判断探测结果 失败则抛出探测异常
|
|
|
if (collectRep == null || collectRep.isEmpty()) {
|
|
|
throw new MonitorDetectException("No collector response");
|
|
|
@@ -97,9 +99,9 @@ public class MonitorServiceImpl implements MonitorService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void addMonitor(Monitor monitor, List<Param> params) throws RuntimeException {
|
|
|
- // 申请 monitor id
|
|
|
+ // Apply for monitor id 申请 monitor id
|
|
|
long monitorId = SnowFlakeIdGenerator.generateId();
|
|
|
- // 构造采集任务Job实体
|
|
|
+ // Construct the collection task Job entity 构造采集任务Job实体
|
|
|
Job appDefine = appService.getAppDefine(monitor.getApp());
|
|
|
appDefine.setMonitorId(monitorId);
|
|
|
appDefine.setInterval(monitor.getIntervals());
|
|
|
@@ -110,8 +112,10 @@ public class MonitorServiceImpl implements MonitorService {
|
|
|
return new Configmap(param.getField(), param.getValue(), param.getType());
|
|
|
}).collect(Collectors.toList());
|
|
|
appDefine.setConfigmap(configmaps);
|
|
|
+ // Send the collection task to get the job ID
|
|
|
// 下发采集任务得到jobId
|
|
|
long jobId = collectJobService.addAsyncCollectJob(appDefine);
|
|
|
+ // Brush the library after the download is successful
|
|
|
// 下发成功后刷库
|
|
|
try {
|
|
|
monitor.setId(monitorId);
|
|
|
@@ -121,6 +125,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|
|
paramDao.saveAll(params);
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage(), e);
|
|
|
+ // Repository brushing abnormally cancels the previously delivered task
|
|
|
// 刷库异常取消之前的下发任务
|
|
|
collectJobService.cancelAsyncCollectJob(jobId);
|
|
|
throw new MonitorDatabaseException(e.getMessage());
|
|
|
@@ -130,6 +135,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|
|
@Override
|
|
|
@Transactional(readOnly = true)
|
|
|
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.setHost(monitor.getHost().trim());
|
|
|
@@ -142,7 +148,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|
|
param.setValue(value);
|
|
|
})
|
|
|
.collect(Collectors.toMap(Param::getField, param -> param));
|
|
|
- // 校验名称唯一性
|
|
|
+ // Check name uniqueness 校验名称唯一性
|
|
|
if (isModify != null) {
|
|
|
Optional<Monitor> monitorOptional = monitorDao.findMonitorByNameEquals(monitor.getName());
|
|
|
if (monitorOptional.isPresent()) {
|
|
|
@@ -157,7 +163,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 参数定义结构校验
|
|
|
+ // Parameter definition structure verification 参数定义结构校验
|
|
|
List<ParamDefine> paramDefines = appService.getAppParamDefines(monitorDto.getMonitor().getApp());
|
|
|
if (paramDefines != null) {
|
|
|
for (ParamDefine paramDefine : paramDefines) {
|
|
|
@@ -203,6 +209,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|
|
}
|
|
|
break;
|
|
|
case "password":
|
|
|
+ // The plaintext password needs to be encrypted for transmission and storage
|
|
|
// 明文密码需加密传输存储
|
|
|
String passwordValue = param.getValue();
|
|
|
if (!AesUtil.isCiphertext(passwordValue)) {
|
|
|
@@ -212,7 +219,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|
|
param.setType(CommonConstants.PARAM_TYPE_PASSWORD);
|
|
|
break;
|
|
|
case "boolean":
|
|
|
- // boolean校验
|
|
|
+ // boolean check
|
|
|
String booleanValue = param.getValue();
|
|
|
try {
|
|
|
Boolean.parseBoolean(booleanValue);
|
|
|
@@ -222,7 +229,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|
|
}
|
|
|
break;
|
|
|
case "radio":
|
|
|
- // radio单选值校验
|
|
|
+ // radio single value check radio单选值校验
|
|
|
List<ParamDefine.Option> options = paramDefine.getOptions();
|
|
|
boolean invalid = true;
|
|
|
if (options != null) {
|
|
|
@@ -244,7 +251,8 @@ public class MonitorServiceImpl implements MonitorService {
|
|
|
case "key-value":
|
|
|
// todo key-value校验
|
|
|
break;
|
|
|
- // todo 更多参数定义与实际值格式校验
|
|
|
+ // todo More parameter definitions and actual value format verification
|
|
|
+ // 更多参数定义与实际值格式校验
|
|
|
default:
|
|
|
throw new IllegalArgumentException("ParamDefine type " + paramDefine.getType() + " is invalid.");
|
|
|
}
|
|
|
@@ -254,8 +262,10 @@ public class MonitorServiceImpl implements MonitorService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void modifyMonitor(Monitor monitor, List<Param> params) throws RuntimeException {
|
|
|
long monitorId = monitor.getId();
|
|
|
+ // Check to determine whether the monitor corresponding to the monitor Id exists
|
|
|
// 查判断monitorId对应的此监控是否存在
|
|
|
Optional<Monitor> queryOption = monitorDao.findById(monitorId);
|
|
|
if (!queryOption.isPresent()) {
|
|
|
@@ -263,9 +273,11 @@ public class MonitorServiceImpl implements MonitorService {
|
|
|
}
|
|
|
Monitor preMonitor = queryOption.get();
|
|
|
if (!preMonitor.getApp().equals(monitor.getApp())) {
|
|
|
+ // The type of monitoring cannot be modified
|
|
|
// 监控的类型不能修改
|
|
|
throw new IllegalArgumentException("Can not modify monitor's app type");
|
|
|
}
|
|
|
+ // Construct the collection task Job entity
|
|
|
// 构造采集任务Job实体
|
|
|
Job appDefine = appService.getAppDefine(monitor.getApp());
|
|
|
appDefine.setId(preMonitor.getJobId());
|
|
|
@@ -276,14 +288,16 @@ public class MonitorServiceImpl implements MonitorService {
|
|
|
List<Configmap> configmaps = params.stream().map(param ->
|
|
|
new Configmap(param.getField(), param.getValue(), param.getType())).collect(Collectors.toList());
|
|
|
appDefine.setConfigmap(configmaps);
|
|
|
- // 更新采集任务
|
|
|
- collectJobService.updateAsyncCollectJob(appDefine);
|
|
|
+ // After the update is successfully released, refresh the library
|
|
|
// 下发更新成功后刷库
|
|
|
try {
|
|
|
monitor.setJobId(preMonitor.getJobId());
|
|
|
monitor.setStatus(preMonitor.getStatus());
|
|
|
monitorDao.save(monitor);
|
|
|
paramDao.saveAll(params);
|
|
|
+ // Update the collection task after the storage is completed
|
|
|
+ // 入库完成后更新采集任务
|
|
|
+ collectJobService.updateAsyncCollectJob(appDefine);
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage(), e);
|
|
|
throw new MonitorDatabaseException(e.getMessage());
|