Search in sources :

Example 1 with AppInstanceClientRelation

use of com.sohu.cache.entity.AppInstanceClientRelation in project cachecloud by sohutv.

the class AppClientDataShowController method doCostDistribute.

/**
     * 应用客户端耗时统计
     */
@RequestMapping("/costDistribute")
public ModelAndView doCostDistribute(HttpServletRequest request, HttpServletResponse response, Model model) {
    // 1.应用信息
    Long appId = NumberUtils.toLong(request.getParameter("appId"));
    if (appId <= 0) {
        return new ModelAndView("");
    }
    AppDesc appDesc = appService.getByAppId(appId);
    model.addAttribute("appDesc", appDesc);
    model.addAttribute("appId", appId);
    // 2.获取时间区间
    TimeBetween timeBetween = new TimeBetween();
    try {
        timeBetween = fillWithCostDateFormat(request, model);
    } catch (ParseException e) {
        logger.error(e.getMessage(), e);
    }
    long startTime = timeBetween.getStartTime();
    long endTime = timeBetween.getEndTime();
    Date startDate = timeBetween.getStartDate();
    // 3.所有命令和第一个命令
    List<String> allCommands = clientReportCostDistriService.getAppDistinctCommand(appId, startTime, endTime);
    model.addAttribute("allCommands", allCommands);
    // 4.所有客户端和实例对应关系
    List<AppInstanceClientRelation> appInstanceClientRelationList = appInstanceClientRelationService.getAppInstanceClientRelationList(appId, startDate);
    model.addAttribute("appInstanceClientRelationList", appInstanceClientRelationList);
    String firstCommand = request.getParameter("firstCommand");
    if (StringUtils.isBlank(firstCommand) && CollectionUtils.isNotEmpty(allCommands)) {
        firstCommand = allCommands.get(0);
        model.addAttribute("firstCommand", firstCommand);
    } else {
        model.addAttribute("firstCommand", firstCommand);
    }
    // 5.1 应用下客户端和实例的全局耗时统计列表
    List<AppClientCostTimeTotalStat> appChartStatList = clientReportCostDistriService.getAppClientCommandTotalStat(appId, firstCommand, startTime, endTime);
    Map<String, Object> resultMap = new HashMap<String, Object>();
    // 5.2 简化字段
    List<Map<String, Object>> app = new ArrayList<Map<String, Object>>();
    for (AppClientCostTimeTotalStat appClientCostTimeTotalStat : appChartStatList) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("timeStamp", appClientCostTimeTotalStat.getTimeStamp());
        map.put("count", appClientCostTimeTotalStat.getTotalCount());
        map.put("mean", appClientCostTimeTotalStat.getMean());
        map.put("median", appClientCostTimeTotalStat.getMedian());
        map.put("max90", appClientCostTimeTotalStat.getNinetyPercentMax());
        map.put("max99", appClientCostTimeTotalStat.getNinetyNinePercentMax());
        map.put("max100", appClientCostTimeTotalStat.getHundredMax());
        map.put("maxInst", appClientCostTimeTotalStat.getMaxInstanceHost() + ":" + appClientCostTimeTotalStat.getMaxInstancePort());
        map.put("maxClient", appClientCostTimeTotalStat.getMaxClientIp());
        app.add(map);
    }
    resultMap.put("app", app);
    model.addAttribute("appChartStatListJson", JSONObject.toJSONString(resultMap));
    return new ModelAndView("client/clientCostDistribute");
}
Also used : HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) AppDesc(com.sohu.cache.entity.AppDesc) Date(java.util.Date) AppInstanceClientRelation(com.sohu.cache.entity.AppInstanceClientRelation) JSONObject(com.alibaba.fastjson.JSONObject) ParseException(java.text.ParseException) HashMap(java.util.HashMap) Map(java.util.Map) AppClientCostTimeTotalStat(com.sohu.cache.entity.AppClientCostTimeTotalStat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)1 AppClientCostTimeTotalStat (com.sohu.cache.entity.AppClientCostTimeTotalStat)1 AppDesc (com.sohu.cache.entity.AppDesc)1 AppInstanceClientRelation (com.sohu.cache.entity.AppInstanceClientRelation)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1