Search in sources :

Example 6 with Param

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;
    }
}
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 7 with Param

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);
        }
    }
}
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)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 Configmap (com.usthe.common.entity.job.Configmap)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 Slf4j (lombok.extern.slf4j.Slf4j)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Service (org.springframework.stereotype.Service)6 Transactional (org.springframework.transaction.annotation.Transactional)6 AlertDefineBindDao (com.usthe.alert.dao.AlertDefineBindDao)5 Metrics (com.usthe.common.entity.job.Metrics)5 ParamDefine (com.usthe.common.entity.manager.ParamDefine)5 Tag (com.usthe.common.entity.manager.Tag)5 CollectRep (com.usthe.common.entity.message.CollectRep)5 AesUtil (com.usthe.common.util.AesUtil)5 CommonConstants (com.usthe.common.util.CommonConstants)5