Search in sources :

Example 11 with Job

use of com.usthe.common.entity.job.Job 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 12 with Job

use of com.usthe.common.entity.job.Job 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;
    }
}
Also used : MonitorDto(com.usthe.manager.pojo.dto.MonitorDto) Monitor(com.usthe.common.entity.manager.Monitor) Param(com.usthe.common.entity.manager.Param) Job(com.usthe.common.entity.job.Job) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with Job

use of com.usthe.common.entity.job.Job 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

Job (com.usthe.common.entity.job.Job)13 Metrics (com.usthe.common.entity.job.Metrics)9 Slf4j (lombok.extern.slf4j.Slf4j)8 Configmap (com.usthe.common.entity.job.Configmap)7 Monitor (com.usthe.common.entity.manager.Monitor)7 Param (com.usthe.common.entity.manager.Param)7 CollectJobService (com.usthe.collector.dispatch.entrance.internal.CollectJobService)6 CollectRep (com.usthe.common.entity.message.CollectRep)6 AesUtil (com.usthe.common.util.AesUtil)6 CommonConstants (com.usthe.common.util.CommonConstants)6 MonitorDao (com.usthe.manager.dao.MonitorDao)6 ParamDao (com.usthe.manager.dao.ParamDao)6 MonitorDto (com.usthe.manager.pojo.dto.MonitorDto)6 Collectors (java.util.stream.Collectors)6 AlertDefineBindDao (com.usthe.alert.dao.AlertDefineBindDao)5 ParamDefine (com.usthe.common.entity.manager.ParamDefine)5 Tag (com.usthe.common.entity.manager.Tag)5 IntervalExpressionUtil (com.usthe.common.util.IntervalExpressionUtil)5 IpDomainUtil (com.usthe.common.util.IpDomainUtil)5 SnowFlakeIdGenerator (com.usthe.common.util.SnowFlakeIdGenerator)5