use of com.usthe.common.entity.manager.Param in project hertzbeat by dromara.
the class MonitorServiceImpl method getMonitorDto.
@Override
@Transactional(readOnly = true)
public MonitorDto getMonitorDto(long id) throws RuntimeException {
Optional<Monitor> monitorOptional = monitorDao.findById(id);
if (monitorOptional.isPresent()) {
Monitor monitor = monitorOptional.get();
MonitorDto monitorDto = new MonitorDto();
monitorDto.setMonitor(monitor);
List<Param> params = paramDao.findParamsByMonitorId(id);
monitorDto.setParams(params);
Job job = appService.getAppDefine(monitor.getApp());
List<String> metrics = job.getMetrics().stream().map(Metrics::getName).collect(Collectors.toList());
monitorDto.setMetrics(metrics);
return monitorDto;
} else {
return null;
}
}
use of com.usthe.common.entity.manager.Param in project hertzbeat by dromara.
the class JobSchedulerInit method run.
@Override
public void run(String... args) throws Exception {
// 读取数据库已经添加应用 构造采集任务
List<Monitor> monitors = monitorDao.findMonitorsByStatusNotInAndAndJobIdNotNull(Arrays.asList((byte) 0, (byte) 4));
for (Monitor monitor : monitors) {
try {
// 构造采集任务Job实体
Job appDefine = appService.getAppDefine(monitor.getApp());
// todo 这里暂时是深拷贝处理
appDefine = GsonUtil.fromJson(GsonUtil.toJson(appDefine), Job.class);
appDefine.setId(monitor.getJobId());
appDefine.setMonitorId(monitor.getId());
appDefine.setInterval(monitor.getIntervals());
appDefine.setCyclic(true);
appDefine.setTimestamp(System.currentTimeMillis());
List<Param> params = paramDao.findParamsByMonitorId(monitor.getId());
List<Configmap> configmaps = params.stream().map(param -> new Configmap(param.getField(), param.getValue(), param.getType())).collect(Collectors.toList());
appDefine.setConfigmap(configmaps);
// 下发采集任务
collectJobService.addAsyncCollectJob(appDefine);
} catch (Exception e) {
log.error("init monitor job: {} error,continue next monitor", monitor, e);
}
}
}
Aggregations