use of com.usthe.common.entity.manager.Monitor in project hertzbeat by dromara.
the class MonitorServiceImpl method deleteMonitors.
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteMonitors(Set<Long> ids) throws RuntimeException {
List<Monitor> monitors = monitorDao.findMonitorsByIdIn(ids);
if (monitors != null) {
monitorDao.deleteAll(monitors);
paramDao.deleteParamsByMonitorIdIn(ids);
alertDefineBindDao.deleteAlertDefineMonitorBindsByMonitorIdIn(monitors.stream().map(Monitor::getId).collect(Collectors.toList()));
for (Monitor monitor : monitors) {
collectJobService.cancelAsyncCollectJob(monitor.getJobId());
}
}
}
use of com.usthe.common.entity.manager.Monitor in project hertzbeat by dromara.
the class DbAlertStoreHandlerImpl method store.
@Override
public void store(Alert alert) {
// todo Using the cache does not directly manipulate the library 使用缓存不直接操作库
Map<String, String> tags = alert.getTags();
String monitorIdStr = tags.get(CommonConstants.TAG_MONITOR_ID);
if (monitorIdStr == null) {
log.error("alert tags monitorId is null.");
return;
}
long monitorId = Long.parseLong(monitorIdStr);
Monitor monitor = monitorService.getMonitor(monitorId);
if (monitor == null) {
log.warn("Dispatch alarm the monitorId: {} not existed, ignored.", monitorId);
return;
}
if (monitor.getTags() != null) {
monitor.getTags().forEach(item -> {
tags.put(item.getName(), item.getValue());
});
}
if (!tags.containsKey(CommonConstants.TAG_MONITOR_NAME)) {
tags.put(CommonConstants.TAG_MONITOR_NAME, monitor.getName());
}
if (monitor.getStatus() == CommonConstants.UN_MANAGE_CODE) {
// 当监控未管理时 忽略静默其告警信息
return;
}
if (monitor.getStatus() == CommonConstants.AVAILABLE_CODE) {
if (CommonConstants.AVAILABLE.equals(alert.getTarget())) {
// Availability Alarm Need to change the monitoring status to unavailable
// 可用性告警 需变更监控状态为不可用
monitorService.updateMonitorStatus(monitor.getId(), CommonConstants.UN_AVAILABLE_CODE);
} else if (CommonConstants.REACHABLE.equals(alert.getTarget())) {
// Reachability alarm The monitoring status needs to be changed to unreachable
// 可达性告警 需变更监控状态为不可达
monitorService.updateMonitorStatus(monitor.getId(), CommonConstants.UN_REACHABLE_CODE);
}
} else {
// 若是恢复告警 需对监控状态进行恢复
if (alert.getStatus() == CommonConstants.ALERT_STATUS_CODE_RESTORED) {
monitorService.updateMonitorStatus(monitorId, CommonConstants.AVAILABLE_CODE);
}
}
// Alarm drop library 告警落库
alertService.addAlert(alert);
}
use of com.usthe.common.entity.manager.Monitor 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