[monitor]优化去除Kafka etcd依赖

This commit is contained in:
tomsun28
2022-01-29 17:11:22 +08:00
parent 6f8e400cab
commit 739dcd6308
60 changed files with 3136 additions and 707 deletions

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>monitor</artifactId>
<groupId>com.usthe.tancloud</groupId>
<version>1.0-SNAPSHOT</version>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>manager</artifactId>
@@ -22,25 +22,25 @@
<dependency>
<groupId>com.usthe.tancloud</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- scheduler -->
<dependency>
<groupId>com.usthe.tancloud</groupId>
<artifactId>scheduler</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0</version>
</dependency>
<!-- data warehouse -->
<dependency>
<groupId>com.usthe.tancloud</groupId>
<artifactId>warehouse</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0</version>
</dependency>
<!-- alerter -->
<dependency>
<groupId>com.usthe.tancloud</groupId>
<artifactId>alerter</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0</version>
</dependency>
<!-- collector -->
<dependency>
<groupId>com.usthe.tancloud</groupId>
<artifactId>collector</artifactId>
<version>1.0</version>
</dependency>
<!-- spring -->
<dependency>
@@ -123,6 +123,7 @@
<include>sureness.yml</include>
<include>banner.txt</include>
<include>db/**</include>
<include>define/**</include>
</includes>
</resource>
</resources>
@@ -167,7 +168,7 @@
</goals>
<configuration>
<descriptors>
<descriptor>../assembly/server/assembly.xml</descriptor>
<descriptor>../script/assembly/server/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>

View File

@@ -1,5 +1,6 @@
package com.usthe.manager.service.impl;
import com.usthe.collector.dispatch.entrance.internal.CollectJobService;
import com.usthe.common.entity.job.Configmap;
import com.usthe.common.entity.job.Job;
import com.usthe.common.entity.job.Metrics;
@@ -20,7 +21,6 @@ import com.usthe.manager.service.AppService;
import com.usthe.manager.service.MonitorService;
import com.usthe.manager.support.exception.MonitorDatabaseException;
import com.usthe.manager.support.exception.MonitorDetectException;
import com.usthe.scheduler.JobScheduling;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@@ -52,7 +52,7 @@ public class MonitorServiceImpl implements MonitorService {
private AppService appService;
@Autowired
private JobScheduling jobScheduling;
private CollectJobService collectJobService;
@Autowired
private MonitorDao monitorDao;
@@ -74,7 +74,7 @@ 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);
List<CollectRep.MetricsData> collectRep = jobScheduling.addSyncCollectJob(appDefine);
List<CollectRep.MetricsData> collectRep = collectJobService.collectSyncJobData(appDefine);
// 判断探测结果 失败则抛出探测异常
if (collectRep == null || collectRep.isEmpty()) {
throw new MonitorDetectException("No collector response");
@@ -101,7 +101,7 @@ public class MonitorServiceImpl implements MonitorService {
}).collect(Collectors.toList());
appDefine.setConfigmap(configmaps);
// 下发采集任务得到jobId
long jobId = jobScheduling.addAsyncCollectJob(appDefine);
long jobId = collectJobService.addAsyncCollectJob(appDefine);
// 下发成功后刷库
try {
monitor.setId(monitorId);
@@ -112,7 +112,7 @@ public class MonitorServiceImpl implements MonitorService {
} catch (Exception e) {
log.error(e.getMessage(), e);
// 刷库异常取消之前的下发任务
jobScheduling.cancelAsyncCollectJob(jobId);
collectJobService.cancelAsyncCollectJob(jobId);
throw new MonitorDatabaseException(e.getMessage());
}
}
@@ -225,7 +225,7 @@ public class MonitorServiceImpl implements MonitorService {
new Configmap(param.getField(), param.getValue(), param.getType())).collect(Collectors.toList());
appDefine.setConfigmap(configmaps);
// 更新采集任务
jobScheduling.updateAsyncCollectJob(appDefine);
collectJobService.updateAsyncCollectJob(appDefine);
// 下发更新成功后刷库
try {
monitor.setJobId(preMonitor.getJobId());
@@ -246,7 +246,7 @@ public class MonitorServiceImpl implements MonitorService {
Monitor monitor = monitorOptional.get();
monitorDao.deleteById(id);
paramDao.deleteParamsByMonitorId(id);
jobScheduling.cancelAsyncCollectJob(monitor.getJobId());
collectJobService.cancelAsyncCollectJob(monitor.getJobId());
}
}
@@ -258,7 +258,7 @@ public class MonitorServiceImpl implements MonitorService {
monitorDao.deleteAll(monitors);
paramDao.deleteParamsByMonitorIdIn(ids);
for (Monitor monitor : monitors) {
jobScheduling.cancelAsyncCollectJob(monitor.getJobId());
collectJobService.cancelAsyncCollectJob(monitor.getJobId());
}
}
}
@@ -299,7 +299,7 @@ public class MonitorServiceImpl implements MonitorService {
if (!managedMonitors.isEmpty()) {
monitorDao.saveAll(managedMonitors);
for (Monitor monitor : managedMonitors) {
jobScheduling.cancelAsyncCollectJob(monitor.getJobId());
collectJobService.cancelAsyncCollectJob(monitor.getJobId());
}
}
}
@@ -326,7 +326,7 @@ public class MonitorServiceImpl implements MonitorService {
new Configmap(param.getField(), param.getValue(), param.getType())).collect(Collectors.toList());
appDefine.setConfigmap(configmaps);
// 下发采集任务
jobScheduling.addAsyncCollectJob(appDefine);
collectJobService.addAsyncCollectJob(appDefine);
}
}
}

View File

@@ -4,7 +4,6 @@ package com.usthe.manager.support;
import com.usthe.common.entity.dto.Message;
import com.usthe.manager.support.exception.MonitorDatabaseException;
import com.usthe.manager.support.exception.MonitorDetectException;
import com.usthe.scheduler.ScheduleException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DataAccessException;
import org.springframework.http.HttpStatus;
@@ -133,23 +132,6 @@ public class GlobalExceptionHandler {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(message);
}
/**
* 处理分发调度器异常问题
* @param exception 调度器异常问题
* @return response
*/
@ExceptionHandler(ScheduleException.class)
@ResponseBody
ResponseEntity<Message<Void>> handleScheduleException(ScheduleException exception) {
String errorMessage = "scheduler warning";
if (exception != null) {
errorMessage = exception.getMessage();
}
log.warn("[scheduler warning]-{}", errorMessage);
Message<Void> message = Message.<Void>builder().msg(errorMessage).code(MONITOR_CONFLICT_CODE).build();
return ResponseEntity.status(HttpStatus.CONFLICT).body(message);
}
/**
* handler the exception thrown for datastore error
* @param exception datastore exception