Search in sources :

Example 6 with Configmap

use of com.usthe.common.entity.job.Configmap in project hertzbeat by dromara.

the class MonitorServiceImpl method enableManageMonitors.

@Override
public void enableManageMonitors(HashSet<Long> ids) {
    // Update monitoring status Add corresponding monitoring periodic task
    // 更新监控状态 新增对应的监控周期性任务
    List<Monitor> unManagedMonitors = monitorDao.findMonitorsByIdIn(ids).stream().filter(monitor -> monitor.getStatus() == CommonConstants.UN_MANAGE_CODE && monitor.getJobId() != null).peek(monitor -> monitor.setStatus(CommonConstants.AVAILABLE_CODE)).collect(Collectors.toList());
    if (!unManagedMonitors.isEmpty()) {
        monitorDao.saveAll(unManagedMonitors);
        for (Monitor monitor : unManagedMonitors) {
            // Construct the collection task Job entity
            // 构造采集任务Job实体
            Job appDefine = appService.getAppDefine(monitor.getApp());
            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);
            // Issue collection tasks       下发采集任务
            collectJobService.addAsyncCollectJob(appDefine);
        }
    }
}
Also used : java.util(java.util) CommonConstants(com.usthe.common.util.CommonConstants) MonitorDao(com.usthe.manager.dao.MonitorDao) ParamDefine(com.usthe.common.entity.manager.ParamDefine) MonitorDatabaseException(com.usthe.manager.support.exception.MonitorDatabaseException) Configmap(com.usthe.common.entity.job.Configmap) Autowired(org.springframework.beans.factory.annotation.Autowired) Param(com.usthe.common.entity.manager.Param) IntervalExpressionUtil(com.usthe.common.util.IntervalExpressionUtil) MonitorService(com.usthe.manager.service.MonitorService) Job(com.usthe.common.entity.job.Job) AppCount(com.usthe.manager.pojo.dto.AppCount) Tag(com.usthe.common.entity.manager.Tag) Service(org.springframework.stereotype.Service) MonitorDto(com.usthe.manager.pojo.dto.MonitorDto) CollectRep(com.usthe.common.entity.message.CollectRep) ParamDao(com.usthe.manager.dao.ParamDao) Monitor(com.usthe.common.entity.manager.Monitor) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) IpDomainUtil(com.usthe.common.util.IpDomainUtil) Slf4j(lombok.extern.slf4j.Slf4j) AlertDefineBindDao(com.usthe.alert.dao.AlertDefineBindDao) SnowFlakeIdGenerator(com.usthe.common.util.SnowFlakeIdGenerator) Specification(org.springframework.data.jpa.domain.Specification) AppService(com.usthe.manager.service.AppService) AesUtil(com.usthe.common.util.AesUtil) CollectJobService(com.usthe.collector.dispatch.entrance.internal.CollectJobService) MonitorDetectException(com.usthe.manager.support.exception.MonitorDetectException) Metrics(com.usthe.common.entity.job.Metrics) Transactional(org.springframework.transaction.annotation.Transactional) Monitor(com.usthe.common.entity.manager.Monitor) Configmap(com.usthe.common.entity.job.Configmap) Param(com.usthe.common.entity.manager.Param) Job(com.usthe.common.entity.job.Job)

Example 7 with Configmap

use of com.usthe.common.entity.job.Configmap 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);
        }
    }
}
Also used : ParamDao(com.usthe.manager.dao.ParamDao) Order(org.springframework.core.annotation.Order) Arrays(java.util.Arrays) MonitorDao(com.usthe.manager.dao.MonitorDao) GsonUtil(com.usthe.common.util.GsonUtil) Configmap(com.usthe.common.entity.job.Configmap) Monitor(com.usthe.common.entity.manager.Monitor) Autowired(org.springframework.beans.factory.annotation.Autowired) Param(com.usthe.common.entity.manager.Param) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Job(com.usthe.common.entity.job.Job) Service(org.springframework.stereotype.Service) CommandLineRunner(org.springframework.boot.CommandLineRunner) CollectJobService(com.usthe.collector.dispatch.entrance.internal.CollectJobService) Monitor(com.usthe.common.entity.manager.Monitor) Configmap(com.usthe.common.entity.job.Configmap) Param(com.usthe.common.entity.manager.Param) Job(com.usthe.common.entity.job.Job)

Aggregations

Configmap (com.usthe.common.entity.job.Configmap)7 Job (com.usthe.common.entity.job.Job)6 Collectors (java.util.stream.Collectors)6 Slf4j (lombok.extern.slf4j.Slf4j)6 CollectJobService (com.usthe.collector.dispatch.entrance.internal.CollectJobService)5 Metrics (com.usthe.common.entity.job.Metrics)5 Monitor (com.usthe.common.entity.manager.Monitor)5 Param (com.usthe.common.entity.manager.Param)5 AesUtil (com.usthe.common.util.AesUtil)5 CommonConstants (com.usthe.common.util.CommonConstants)5 MonitorDao (com.usthe.manager.dao.MonitorDao)5 ParamDao (com.usthe.manager.dao.ParamDao)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Service (org.springframework.stereotype.Service)5 AlertDefineBindDao (com.usthe.alert.dao.AlertDefineBindDao)4 ParamDefine (com.usthe.common.entity.manager.ParamDefine)4 Tag (com.usthe.common.entity.manager.Tag)4 CollectRep (com.usthe.common.entity.message.CollectRep)4 IntervalExpressionUtil (com.usthe.common.util.IntervalExpressionUtil)4 IpDomainUtil (com.usthe.common.util.IpDomainUtil)4