Search in sources :

Example 1 with MonitorDetectException

use of com.usthe.manager.support.exception.MonitorDetectException in project hertzbeat by dromara.

the class MonitorServiceImpl method detectMonitor.

@Override
@Transactional(readOnly = true)
public void detectMonitor(Monitor monitor, List<Param> params) throws MonitorDetectException {
    Long monitorId = monitor.getId();
    if (monitorId == null || monitorId == 0) {
        monitorId = MONITOR_ID_TMP;
    }
    Job appDefine = appService.getAppDefine(monitor.getApp());
    appDefine.setMonitorId(monitorId);
    appDefine.setCyclic(false);
    appDefine.setTimestamp(System.currentTimeMillis());
    List<Configmap> configmaps = params.stream().map(param -> new Configmap(param.getField(), param.getValue(), param.getType())).collect(Collectors.toList());
    appDefine.setConfigmap(configmaps);
    // To detect availability, you only need to collect the set of availability indicators with a priority of 0.
    // 探测可用性只需要采集优先级为0的可用性指标集合
    List<Metrics> availableMetrics = appDefine.getMetrics().stream().filter(item -> item.getPriority() == 0).collect(Collectors.toList());
    appDefine.setMetrics(availableMetrics);
    List<CollectRep.MetricsData> collectRep = collectJobService.collectSyncJobData(appDefine);
    // 判断探测结果 失败则抛出探测异常
    if (collectRep == null || collectRep.isEmpty()) {
        throw new MonitorDetectException("No collector response");
    }
    if (collectRep.get(0).getCode() != CollectRep.Code.SUCCESS) {
        throw new MonitorDetectException(collectRep.get(0).getMsg());
    }
}
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) Metrics(com.usthe.common.entity.job.Metrics) MonitorDetectException(com.usthe.manager.support.exception.MonitorDetectException) Configmap(com.usthe.common.entity.job.Configmap) Job(com.usthe.common.entity.job.Job) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AlertDefineBindDao (com.usthe.alert.dao.AlertDefineBindDao)1 CollectJobService (com.usthe.collector.dispatch.entrance.internal.CollectJobService)1 Configmap (com.usthe.common.entity.job.Configmap)1 Job (com.usthe.common.entity.job.Job)1 Metrics (com.usthe.common.entity.job.Metrics)1 Monitor (com.usthe.common.entity.manager.Monitor)1 Param (com.usthe.common.entity.manager.Param)1 ParamDefine (com.usthe.common.entity.manager.ParamDefine)1 Tag (com.usthe.common.entity.manager.Tag)1 CollectRep (com.usthe.common.entity.message.CollectRep)1 AesUtil (com.usthe.common.util.AesUtil)1 CommonConstants (com.usthe.common.util.CommonConstants)1 IntervalExpressionUtil (com.usthe.common.util.IntervalExpressionUtil)1 IpDomainUtil (com.usthe.common.util.IpDomainUtil)1 SnowFlakeIdGenerator (com.usthe.common.util.SnowFlakeIdGenerator)1 MonitorDao (com.usthe.manager.dao.MonitorDao)1 ParamDao (com.usthe.manager.dao.ParamDao)1 AppCount (com.usthe.manager.pojo.dto.AppCount)1 MonitorDto (com.usthe.manager.pojo.dto.MonitorDto)1 AppService (com.usthe.manager.service.AppService)1