use of com.alibaba.otter.manager.biz.statistics.delay.param.DelayStatInfo 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;
}
use of com.alibaba.otter.manager.biz.statistics.delay.param.DelayStatInfo in project otter by alibaba.
the class AnalysisDelayStat method execute.
public void execute(@Param("d5221") String startTime, @Param("d5222") String endTime, @Param("pipelineId") Long pipelineId, HttpSession session, Context context) throws Exception {
Date end = null;
Date start = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
if (StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)) {
start = new Date(System.currentTimeMillis() / 60000 * 60000 - 24 * 60 * 60 * 1000);
end = new Date(System.currentTimeMillis() / 60000 * 60000);
} else {
// 当前24小时,时间取整分钟
sdf.setLenient(false);
if (null != startTime && null != endTime) {
start = sdf.parse(startTime);
end = sdf.parse(endTime);
}
}
Channel channel = channelService.findByPipelineId(pipelineId);
Map<Long, DelayStatInfo> delayStatInfos = new HashMap<Long, DelayStatInfo>();
if (null != start && null != end) {
delayStatInfos = delayStatService.listTimelineDelayStat(pipelineId, start, end);
}
Double delayAvg = 0.0;
for (DelayStatInfo info : delayStatInfos.values()) {
delayAvg += info.getAvgDelayTime();
}
if (delayStatInfos.size() != 0) {
delayAvg = delayAvg / (1.0 * delayStatInfos.size());
}
context.put("delayStatInfos", delayStatInfos);
context.put("delayAvg", delayAvg);
context.put("channel", channel);
context.put("pipelineId", pipelineId);
context.put("start", sdf.format(start));
context.put("end", sdf.format(end));
}
Aggregations