public Map<String, Double> findAppMachineNumber(int appDayId, Date start, Date end) { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); Map<Integer, String> map = MonitorDayAo.get().getKeyMap(); Set<Integer> keyList = new HashSet<Integer>(); for (Map.Entry<Integer, String> entry : map.entrySet()) { if (entry.getValue().startsWith("HOSTS_")) { keyList.add(entry.getKey()); } } Map<String, Double> mapMachine = new HashMap<String, Double>(); for (Integer keyId : keyList) { List<KeyValuePo> listQps = MonitorDayAo.get().findMonitorCountByDate(appDayId, keyId, start, end); for (KeyValuePo po : listQps) { String key = sdf.format(po.getCollectTime()); Double v = mapMachine.get(key); if (v == null) { mapMachine.put(key, Double.parseDouble(po.getValueStr())); } else { mapMachine.put(key, Double.parseDouble(po.getValueStr()) + v); } } } return mapMachine; }
/** * @param appId * @param date * @return */ public String findCappRtCountByDate(int appId, String date) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date c = sdf.parse(date); Calendar cal = Calendar.getInstance(); cal.setTime(c); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); Date colectDate = cal.getTime(); List<KeyValuePo> listPo = dao.findCappRtCountByTime(appId, colectDate); // 返回的是20:30~22:30每个key的平均值和key的列表 // 下面是对返回的20:30~22:30的记录进行平均, Double aveValue = 0d; int size = 0; for (KeyValuePo po : listPo) { Double value = Double.parseDouble(po.getValueStr()); if (value < 1000) { // 大于100的剔除掉 aveValue = Arith.add(aveValue, value); size++; } } if (size > 0) { aveValue = Arith.div(aveValue, size, 2); // 总调用量/接口数 return aveValue.toString(); } return "0"; }
/** * 这是提供给C应用查询qps的,返回C应用所有相关key的mData的一个平均值 * * @param appId * @param collectTime //yyyy-MM-dd * @return * @throws Exception */ public String findCappQpsCountByDate(Integer appId, String collectTime) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date c = sdf.parse(collectTime); Calendar cal = Calendar.getInstance(); cal.setTime(c); cal.set(Calendar.HOUR_OF_DAY, 20); cal.set(Calendar.MINUTE, 30); cal.set(Calendar.SECOND, 0); Date startDate = cal.getTime(); cal.set(Calendar.HOUR_OF_DAY, 22); cal.set(Calendar.MINUTE, 30); cal.set(Calendar.SECOND, 0); Date endDate = cal.getTime(); List<KeyValuePo> listPo = dao.findCappQpsCountByTime(appId, startDate, endDate); // 返回的是20:30~22:30每一分钟的记录 // 下面是对返回的20:30~22:30的记录进行平均, Double aveValue = 0d; int size = 0; for (KeyValuePo po : listPo) { Double value = Double.parseDouble(po.getValueStr()); aveValue = Arith.add(aveValue, value); size++; } if (size > 0) { aveValue = Arith.div(aveValue, size, 2); return aveValue.toString(); } return "0"; }
public String parseCenterAppQps(Integer appId, Integer keyId, String collectTime) { SimpleDateFormat sdf1 = new SimpleDateFormat("HHmm"); List<KeyValuePo> listPo = findMonitorDataListByTime(appId, keyId, collectTime); Double aveValue = 0d; int size = 0; for (KeyValuePo po : listPo) { Date date = po.getCollectTime(); Double value = Double.parseDouble(po.getValueStr()); int time = Integer.parseInt(sdf1.format(date)); if (time >= 2030 && time <= 2230) { aveValue = Arith.add(aveValue, value); size++; } } if (size > 0) { aveValue = Arith.div(aveValue, size, 2); return aveValue.toString(); } return "0"; }
public Map<Date, Integer> findAppHostCount(int appId, Integer[] keyIds, Date start, Date end) { Map<Date, Integer> map = new HashMap<Date, Integer>(); for (Integer keyId : keyIds) { List<KeyValuePo> list = dao.findMonitorCountByDate(appId, keyId, start, end); for (KeyValuePo po : list) { Integer n = map.get(po.getCollectTime()); if (n == null) { map.put(po.getCollectTime(), Integer.parseInt(po.getValueStr())); } else { map.put(po.getCollectTime(), n + Integer.parseInt(po.getValueStr())); } } } return map; }