Search in sources :

Example 1 with DelayStat

use of com.alibaba.otter.shared.common.model.statistics.delay.DelayStat in project otter by alibaba.

the class DelayStatRuleMonitor method explore.

@Override
public void explore(List<AlarmRule> rules) {
    if (CollectionUtils.isEmpty(rules)) {
        return;
    }
    // 进入到监控项级别的rule,pipelineId一定是相同的
    Long pipelineId = rules.get(0).getPipelineId();
    DelayStat delayStat = delayStatService.findRealtimeDelayStat(pipelineId);
    // seconds
    Long delayTime = 0L;
    Long delayUpdate = 0L;
    if (delayStat.getDelayTime() != null) {
        delayTime = delayStat.getDelayTime() / 1000;
    }
    if (delayStat.getGmtCreate() != null) {
        delayUpdate = (new Date().getTime() - delayStat.getGmtCreate().getTime()) / 1000;
    }
    boolean delayTimeFlag = false;
    boolean delayUpdateFlag = false;
    for (AlarmRule rule : rules) {
        if (rule.getMonitorName().isDelayTime()) {
            delayTimeFlag |= checkDelayTime(rule, delayTime);
            if (delayTimeFlag) {
                //如果出现超时,再check下是否因为最后更新时间过久了
                //检查delay统计的最后更新时间,这也做为delay监控的一部分
                delayUpdateFlag |= checkDelayTime(rule, delayUpdate);
            }
        }
    }
    if (delayTimeFlag && !delayUpdateFlag) {
        logRecordAlarm(pipelineId, MonitorName.DELAYTIME, String.format(DELAY_TIME_MESSAGE, pipelineId, delayTime));
    } else if (delayTimeFlag && delayUpdateFlag) {
        logRecordAlarm(pipelineId, MonitorName.DELAYTIME, String.format(DELAY_TIME_UPDATE_MESSAGE, pipelineId, delayTime, delayUpdate));
    } else if (delayUpdateFlag) {
        logRecordAlarm(pipelineId, MonitorName.DELAYTIME, String.format(DELAY_UPDATE_MESSAGE, pipelineId, delayUpdate));
    }
}
Also used : AlarmRule(com.alibaba.otter.shared.common.model.config.alarm.AlarmRule) DelayStat(com.alibaba.otter.shared.common.model.statistics.delay.DelayStat) Date(java.util.Date)

Example 2 with DelayStat

use of com.alibaba.otter.shared.common.model.statistics.delay.DelayStat in project otter by alibaba.

the class StatsRemoteServiceImpl method flushDelayStat.

private void flushDelayStat() {
    synchronized (delayStats) {
        // 需要做同步,避免delay数据丢失
        for (Map.Entry<Long, AvgStat> stat : delayStats.entrySet()) {
            if (stat.getValue().count.get() > 0) {
                DelayStat delay = new DelayStat();
                delay.setPipelineId(stat.getKey());
                delay.setDelayTime(stat.getValue().getAvg());
                delay.setDelayNumber(0L);
                delayStatService.createDelayStat(delay);
            }
        }
        delayStats.clear();
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) DelayStat(com.alibaba.otter.shared.common.model.statistics.delay.DelayStat) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with DelayStat

use of com.alibaba.otter.shared.common.model.statistics.delay.DelayStat in project otter by alibaba.

the class DelayStatServiceImpl method findRealtimeDelayStat.

/**
     * 通过pipeLineId得到一个以gmtCreate倒排序的第一条记录
     */
public DelayStat findRealtimeDelayStat(Long pipelineId) {
    Assert.assertNotNull(pipelineId);
    DelayStatDO delayStatDO = delayStatDao.findRealtimeDelayStat(pipelineId);
    DelayStat delayStat = new DelayStat();
    if (delayStatDO != null) {
        delayStat = delayStatDOToModel(delayStatDO);
    }
    return delayStat;
}
Also used : DelayStatDO(com.alibaba.otter.manager.biz.statistics.delay.dal.dataobject.DelayStatDO) TopDelayStat(com.alibaba.otter.manager.biz.statistics.delay.param.TopDelayStat) DelayStat(com.alibaba.otter.shared.common.model.statistics.delay.DelayStat)

Example 4 with DelayStat

use of com.alibaba.otter.shared.common.model.statistics.delay.DelayStat in project otter by alibaba.

the class DelayStatServiceImpl method listTimelineDelayStat.

/**
     * 列出pipeLineId下,start-end时间段下的delayStat
     */
public Map<Long, DelayStatInfo> listTimelineDelayStat(Long pipelineId, Date start, Date end) {
    Map<Long, DelayStatInfo> delayStatInfos = new LinkedHashMap<Long, DelayStatInfo>();
    List<DelayStatDO> delayStatDOs = delayStatDao.listTimelineDelayStatsByPipelineId(pipelineId, start, end);
    int size = delayStatDOs.size();
    int k = size - 1;
    for (Long i = start.getTime(); i <= end.getTime(); i += 60 * 1000) {
        DelayStatInfo delayStatInfo = new DelayStatInfo();
        List<DelayStat> delayStats = new ArrayList<DelayStat>();
        // 取出每个时间点i以内的数据,k是一个游标,每次遍历时前面已经取过了的数据就不用再遍历了
        for (int j = k; j >= 0; --j) {
            if ((i - delayStatDOs.get(j).getGmtModified().getTime() <= 60 * 1000) && (i - delayStatDOs.get(j).getGmtModified().getTime() >= 0)) {
                delayStats.add(delayStatDOToModel(delayStatDOs.get(j)));
                k = j - 1;
            } else // 如果不满足if条件,则后面的数据也不用再遍历
            {
                break;
            }
        }
        if (delayStats.size() > 0) {
            delayStatInfo.setItems(delayStats);
            delayStatInfos.put(i, delayStatInfo);
        }
    }
    return delayStatInfos;
}
Also used : ArrayList(java.util.ArrayList) DelayStatDO(com.alibaba.otter.manager.biz.statistics.delay.dal.dataobject.DelayStatDO) TopDelayStat(com.alibaba.otter.manager.biz.statistics.delay.param.TopDelayStat) DelayStat(com.alibaba.otter.shared.common.model.statistics.delay.DelayStat) DelayStatInfo(com.alibaba.otter.manager.biz.statistics.delay.param.DelayStatInfo) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with DelayStat

use of com.alibaba.otter.shared.common.model.statistics.delay.DelayStat in project otter by alibaba.

the class DelayStatServiceImpl method delayStatDOToModel.

/**
     * 用于DO对象转化为Model对象
     * 
     * @param delayStatDO
     * @return DelayStat
     */
private DelayStat delayStatDOToModel(DelayStatDO delayStatDO) {
    DelayStat delayStat = new DelayStat();
    delayStat.setId(delayStatDO.getId());
    delayStat.setDelayTime(delayStatDO.getDelayTime());
    delayStat.setDelayNumber(delayStatDO.getDelayNumber());
    delayStat.setPipelineId(delayStatDO.getPipelineId());
    delayStat.setGmtCreate(delayStatDO.getGmtCreate());
    delayStat.setGmtModified(delayStatDO.getGmtModified());
    return delayStat;
}
Also used : TopDelayStat(com.alibaba.otter.manager.biz.statistics.delay.param.TopDelayStat) DelayStat(com.alibaba.otter.shared.common.model.statistics.delay.DelayStat)

Aggregations

DelayStat (com.alibaba.otter.shared.common.model.statistics.delay.DelayStat)8 TopDelayStat (com.alibaba.otter.manager.biz.statistics.delay.param.TopDelayStat)3 DelayStatDO (com.alibaba.otter.manager.biz.statistics.delay.dal.dataobject.DelayStatDO)2 ThroughputCondition (com.alibaba.otter.manager.biz.statistics.throughput.param.ThroughputCondition)2 AlarmRule (com.alibaba.otter.shared.common.model.config.alarm.AlarmRule)2 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)2 ThroughputStat (com.alibaba.otter.shared.common.model.statistics.throughput.ThroughputStat)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 DelayStatInfo (com.alibaba.otter.manager.biz.statistics.delay.param.DelayStatInfo)1 MainStemEventData (com.alibaba.otter.shared.arbitrate.model.MainStemEventData)1 PositionEventData (com.alibaba.otter.shared.arbitrate.model.PositionEventData)1 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)1 DelayCount (com.alibaba.otter.shared.common.model.statistics.delay.DelayCount)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1