コード例 #1
1
 /** 值分布日期格式 */
 private TimeBetween fillWithValueDistriTime(HttpServletRequest request, Model model)
     throws ParseException {
   final String valueDistriDateFormat = "yyyy-MM-dd";
   String valueDistriStartDateParam = request.getParameter("valueDistriStartDate");
   String valueDistriEndDateParam = request.getParameter("valueDistriEndDate");
   Date startDate;
   Date endDate;
   if (StringUtils.isBlank(valueDistriStartDateParam)
       || StringUtils.isBlank(valueDistriEndDateParam)) {
     // 如果为空默认取昨天和今天
     SimpleDateFormat sdf = new SimpleDateFormat(valueDistriDateFormat);
     startDate = sdf.parse(sdf.format(new Date()));
     endDate = DateUtils.addDays(startDate, 1);
     valueDistriStartDateParam = DateUtil.formatDate(startDate, valueDistriDateFormat);
     valueDistriEndDateParam = DateUtil.formatDate(endDate, valueDistriDateFormat);
   } else {
     endDate = DateUtil.parse(valueDistriEndDateParam, valueDistriDateFormat);
     startDate = DateUtil.parse(valueDistriStartDateParam, valueDistriDateFormat);
     // 限制不能超过1天
     if (endDate.getTime() - startDate.getTime() > TimeUnit.DAYS.toMillis(1)) {
       startDate = DateUtils.addDays(endDate, -1);
     }
   }
   // 前端需要
   model.addAttribute("valueDistriStartDate", valueDistriStartDateParam);
   model.addAttribute("valueDistriEndDate", valueDistriEndDateParam);
   // 查询后台需要
   long startTime = NumberUtils.toLong(DateUtil.formatDate(startDate, COLLECT_TIME_FORMAT));
   long endTime = NumberUtils.toLong(DateUtil.formatDate(endDate, COLLECT_TIME_FORMAT));
   return new TimeBetween(startTime, endTime, startDate, endDate);
 }
コード例 #2
0
  /**
   * 获取指定时间内某个命令某个客户端和实例的统计数据
   *
   * @param appId
   */
  @RequestMapping("/getAppClientInstanceCommandCost")
  public ModelAndView doGetAppClientInstanceCommandCost(
      HttpServletRequest request, HttpServletResponse response, Model model) throws ParseException {
    final String costDistriDateFormat = "yyyy-MM-dd";
    long appId = NumberUtils.toLong(request.getParameter("appId"));
    // 时间转换
    String costDistriStartDate = request.getParameter("costDistriStartDate");
    String costDistriEndDate = request.getParameter("costDistriEndDate");
    Date startDate = DateUtil.parse(costDistriStartDate, costDistriDateFormat);
    Date endDate = DateUtil.parse(costDistriEndDate, costDistriDateFormat);
    long startTime = NumberUtils.toLong(DateUtil.formatDate(startDate, COLLECT_TIME_FORMAT));
    long endTime = NumberUtils.toLong(DateUtil.formatDate(endDate, COLLECT_TIME_FORMAT));

    String firstCommand = request.getParameter("firstCommand");
    long instanceId = NumberUtils.toLong(request.getParameter("instanceId"));
    String clientIp = request.getParameter("clientIp");

    // 客户端和实例统计
    List<AppClientCostTimeStat> clientInstanceChartStatList =
        clientReportCostDistriService.getAppCommandClientToInstanceStat(
            appId, firstCommand, instanceId, clientIp, startTime, endTime);
    // 缩减字段
    List<Map<String, Object>> clientInstanceStat = new ArrayList<Map<String, Object>>();
    for (AppClientCostTimeStat appClientCostTimeStat : clientInstanceChartStatList) {
      Map<String, Object> map = new HashMap<String, Object>();
      map.put("timeStamp", appClientCostTimeStat.getTimeStamp());
      map.put("count", appClientCostTimeStat.getCount());
      map.put("mean", appClientCostTimeStat.getMean());
      map.put("median", appClientCostTimeStat.getMedian());
      map.put("max90", appClientCostTimeStat.getNinetyPercentMax());
      map.put("max99", appClientCostTimeStat.getNinetyNinePercentMax());
      map.put("max100", appClientCostTimeStat.getHundredMax());
      clientInstanceStat.add(map);
    }
    // 生成数据map json
    Map<String, Object> resultMap = new HashMap<String, Object>();
    resultMap.put("clientInstanceStat", clientInstanceStat);
    sendMessage(response, JSONObject.toJSONString(resultMap));
    return null;
  }