/** 值分布日期格式 */
 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);
 }
Exemplo n.º 2
0
  @RequestMapping("/index")
  public ModelAndView index(
      HttpServletRequest request,
      HttpServletResponse response,
      Model model,
      Integer admin,
      Long instanceId,
      Long appId,
      String tabTag) {

    String startDateParam = request.getParameter("startDate");
    String endDateParam = request.getParameter("endDate");

    if (StringUtils.isBlank(startDateParam) || StringUtils.isBlank(endDateParam)) {
      Date endDate = new Date();
      Date startDate = DateUtils.addDays(endDate, -1);
      startDateParam = DateUtil.formatDate(startDate, "yyyyMMdd");
      endDateParam = DateUtil.formatDate(endDate, "yyyyMMdd");
    }
    model.addAttribute("startDate", startDateParam);
    model.addAttribute("endDate", endDateParam);

    if (instanceId != null && instanceId > 0) {
      model.addAttribute("instanceId", instanceId);
      InstanceInfo instanceInfo = instanceStatsCenter.getInstanceInfo(instanceId);

      if (instanceInfo == null) {
        model.addAttribute("type", -1);
      } else {
        if (appId != null && appId > 0) {
          model.addAttribute("appId", appId);
        } else {
          model.addAttribute("appId", instanceInfo.getAppId());
        }
        model.addAttribute("type", instanceInfo.getType());
      }
    } else {

    }
    if (tabTag != null) {
      model.addAttribute("tabTag", tabTag);
    }
    return new ModelAndView("instance/instanceIndex");
  }
  /**
   * 获取指定时间内某个命令某个客户端和实例的统计数据
   *
   * @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;
  }
Exemplo n.º 4
0
  @RequestMapping("/stat")
  public ModelAndView stat(
      HttpServletRequest request,
      HttpServletResponse response,
      Model model,
      Integer admin,
      Long instanceId) {

    String startDateParam = request.getParameter("startDate");
    String endDateParam = request.getParameter("endDate");

    if (StringUtils.isBlank(startDateParam) || StringUtils.isBlank(endDateParam)) {
      Date endDate = new Date();
      Date startDate = DateUtils.addDays(endDate, -1);
      startDateParam = DateUtil.formatDate(startDate, "yyyyMMdd");
      endDateParam = DateUtil.formatDate(endDate, "yyyyMMdd");
    }
    model.addAttribute("startDate", startDateParam);
    model.addAttribute("endDate", endDateParam);

    if (instanceId != null && instanceId > 0) {
      model.addAttribute("instanceId", instanceId);
      InstanceInfo instanceInfo = instanceStatsCenter.getInstanceInfo(instanceId);
      model.addAttribute("instanceInfo", instanceInfo);
      model.addAttribute("appId", instanceInfo.getAppId());
      model.addAttribute("appDetail", appStatsCenter.getAppDetail(instanceInfo.getAppId()));
      InstanceStats instanceStats = instanceStatsCenter.getInstanceStats(instanceId);
      model.addAttribute("instanceStats", instanceStats);
      List<AppCommandStats> topLimitAppCommandStatsList =
          appStatsCenter.getTopLimitAppCommandStatsList(
              instanceInfo.getAppId(),
              Long.parseLong(startDateParam) * 10000,
              Long.parseLong(endDateParam) * 10000,
              5);
      model.addAttribute("appCommandStats", topLimitAppCommandStatsList);
    }
    return new ModelAndView("instance/instanceStat");
  }
Exemplo n.º 5
0
  /**
   * 获取某个命令时间分布图
   *
   * @param instanceId 实例id
   * @param commandName 命令名称
   * @throws java.text.ParseException
   */
  @RequestMapping("/getCommandStatsV2")
  public ModelAndView getCommandStatsV2(
      HttpServletRequest request,
      HttpServletResponse response,
      Model model,
      Long instanceId,
      String commandName)
      throws ParseException {
    String startDateParam = request.getParameter("startDate");
    String endDateParam = request.getParameter("endDate");

    if (StringUtils.isBlank(startDateParam) || StringUtils.isBlank(endDateParam)) {
      Date endDate = new Date();
      Date startDate = DateUtils.addDays(endDate, -1);
      startDateParam = DateUtil.formatDate(startDate, "yyyyMMdd");
      endDateParam = DateUtil.formatDate(endDate, "yyyyMMdd");
    }
    model.addAttribute("startDate", startDateParam);
    model.addAttribute("endDate", endDateParam);

    Date startDate = DateUtil.parseYYYYMMdd(startDateParam);
    Date endDate = DateUtil.parseYYYYMMdd(endDateParam);
    if (instanceId != null) {
      long firstDayBegin = NumberUtils.toLong(DateUtil.formatYYYYMMdd(startDate) + "0000");
      long firstDayEnd = NumberUtils.toLong(DateUtil.formatYYYYMMdd(startDate) + "2359");
      long secondDayBegin = NumberUtils.toLong(DateUtil.formatYYYYMMdd(endDate) + "0000");
      long secondDayEnd = NumberUtils.toLong(DateUtil.formatYYYYMMdd(endDate) + "2359");
      long bt = System.currentTimeMillis();
      List<InstanceCommandStats> instanceCommandStatsListFirst =
          instanceStatsCenter.getCommandStatsList(
              instanceId, firstDayBegin, firstDayEnd, commandName);
      List<InstanceCommandStats> instanceCommandStatsListSecond =
          instanceStatsCenter.getCommandStatsList(
              instanceId, secondDayBegin, secondDayEnd, commandName);
      long et = System.currentTimeMillis() - bt;
      Map<String, InstanceCommandStats> cmdStatsFirst = new HashMap<String, InstanceCommandStats>();
      Map<String, InstanceCommandStats> cmdStatsSecond =
          new HashMap<String, InstanceCommandStats>();

      for (InstanceCommandStats first : instanceCommandStatsListFirst) {
        cmdStatsFirst.put(first.getCollectTime() + "", first);
      }
      for (InstanceCommandStats second : instanceCommandStatsListSecond) {
        cmdStatsSecond.put(second.getCollectTime() + "", second);
      }

      SplineChartEntity splineChartEntity = new SplineChartEntity();
      String container = request.getParameter("container");
      if (container != null) {
        splineChartEntity.renderTo(container);
      }
      model.addAttribute("chart", splineChartEntity);
      splineChartEntity.putTitle(
          ChartKeysUtil.TitleKey.TEXT.getKey(),
          "命令:" + commandName + " 的比较曲线【" + startDateParam + "】-【" + endDateParam + "】");
      splineChartEntity.setYAxisTitle("y");
      List<Long> data1 = new ArrayList<Long>();
      List<Long> data2 = new ArrayList<Long>();
      Map<String, Object> marker = new HashMap<String, Object>();
      marker.put("radius", 1);
      Map<String, Object> serie1 = new HashMap<String, Object>();
      serie1.put("name", startDateParam);
      serie1.put("data", data1);
      serie1.put("marker", marker);
      Map<String, Object> serie2 = new HashMap<String, Object>();
      serie2.put("name", endDateParam);
      serie2.put("data", data2);
      serie2.put("marker", marker);
      splineChartEntity.putSeries(serie1);
      splineChartEntity.putSeries(serie2);
      List<Object> x = new LinkedList<Object>();
      for (int i = 0; i < 1440; i += 1) {
        Date date = DateUtils.addMinutes(startDate, i);
        String s = DateUtil.formatHHMM(date);
        if (cmdStatsFirst.containsKey(startDateParam + s)) {
          data1.add(cmdStatsFirst.get(startDateParam + s).getCommandCount());
        } else {
          data1.add(0l);
        }
        if (cmdStatsSecond.containsKey(endDateParam + s)) {
          data2.add(cmdStatsSecond.get(endDateParam + s).getCommandCount());
        } else {
          data2.add(0l);
        }

        x.add(s);
      }
      splineChartEntity.setXAxisCategories(x);
    }
    return new ModelAndView("");
  }