Search in sources :

Example 1 with AppClientCostTimeTotalStat

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

the class ClientReportCostDistriServiceImpl method batchSave.

@Override
public void batchSave(ClientReportBean clientReportBean) {
    try {
        // 1.client上报
        final String clientIp = clientReportBean.getClientIp();
        final long collectTime = clientReportBean.getCollectTime();
        final long reportTime = clientReportBean.getReportTimeStamp();
        final List<Map<String, Object>> datas = clientReportBean.getDatas();
        if (datas == null || datas.isEmpty()) {
            logger.warn("datas field {} is empty", clientReportBean);
            return;
        }
        // 2.结果集
        List<AppClientCostTimeStat> appClientCostTimeStatList = new ArrayList<AppClientCostTimeStat>();
        // 3.解析结果
        for (Map<String, Object> map : datas) {
            Integer clientDataType = MapUtils.getInteger(map, ClientReportConstant.CLIENT_DATA_TYPE, -1);
            ClientCollectDataTypeEnum clientCollectDataTypeEnum = ClientCollectDataTypeEnum.MAP.get(clientDataType);
            if (clientCollectDataTypeEnum == null) {
                continue;
            }
            if (ClientCollectDataTypeEnum.COST_TIME_DISTRI_TYPE.equals(clientCollectDataTypeEnum)) {
                AppClientCostTimeStat appClientCostTimeStat = generate(clientIp, collectTime, reportTime, map);
                if (appClientCostTimeStat != null) {
                    appClientCostTimeStatList.add(appClientCostTimeStat);
                }
            }
        }
        if (CollectionUtils.isNotEmpty(appClientCostTimeStatList)) {
            // 4.批量保存
            appClientCostTimeStatDao.batchSave(appClientCostTimeStatList);
            // 5.合并app统计结果
            List<AppClientCostTimeTotalStat> appClientCostTimeTotalStatList = mergeAppClientCostTimeStat(appClientCostTimeStatList);
            if (CollectionUtils.isNotEmpty(appClientCostTimeTotalStatList)) {
                appClientCostTimeTotalStatDao.batchSave(appClientCostTimeTotalStatList);
            }
            // 6.保存应用下节点和客户端关系
            appInstanceClientRelationService.batchSave(appClientCostTimeStatList);
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : ClientCollectDataTypeEnum(com.sohu.tv.jedis.stat.enums.ClientCollectDataTypeEnum) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) AppClientCostTimeStat(com.sohu.cache.entity.AppClientCostTimeStat) AppClientCostTimeTotalStat(com.sohu.cache.entity.AppClientCostTimeTotalStat)

Example 2 with AppClientCostTimeTotalStat

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

the class ClientReportCostDistriServiceImpl method mergeAppClientCostTimeStat.

/**
     * 合并以app为单位的
     * @param appClientCostTimeStatList
     */
private List<AppClientCostTimeTotalStat> mergeAppClientCostTimeStat(List<AppClientCostTimeStat> appClientCostTimeStatList) {
    // 1. merge后的结果
    List<AppClientCostTimeTotalStat> resultList = new ArrayList<AppClientCostTimeTotalStat>();
    // 2. 以appid_command_collectTime为key,拆分appClientCostTimeStatList
    Map<String, List<AppClientCostTimeStat>> map = new HashMap<String, List<AppClientCostTimeStat>>();
    for (AppClientCostTimeStat appClientCostTimeStat : appClientCostTimeStatList) {
        long appId = appClientCostTimeStat.getAppId();
        String command = appClientCostTimeStat.getCommand();
        long collectTime = appClientCostTimeStat.getCollectTime();
        String key = appId + "_" + command + "_" + collectTime;
        if (map.containsKey(key)) {
            map.get(key).add(appClientCostTimeStat);
        } else {
            List<AppClientCostTimeStat> list = new ArrayList<AppClientCostTimeStat>();
            list.add(appClientCostTimeStat);
            map.put(key, list);
        }
    }
    // 3.生成结果
    for (Entry<String, List<AppClientCostTimeStat>> entry : map.entrySet()) {
        String key = entry.getKey();
        String[] items = key.split("_");
        long appId = NumberUtils.toLong(items[0]);
        String command = items[1];
        long collectTime = NumberUtils.toLong(items[2]);
        double totalCost = 0.0;
        long totalCount = 0;
        int median = 0;
        int ninetyPercentMax = 0;
        int ninetyNinePercentMax = 0;
        int hundredMax = 0;
        String maxInstanceHost = "";
        int maxInstancePort = 0;
        long maxInstanceId = 0;
        String maxClientIp = "";
        double mean = 0.0;
        for (AppClientCostTimeStat appClientCostTimeStat : entry.getValue()) {
            AppClientCostTimeTotalStat appClientCostTimeTotalStat = AppClientCostTimeTotalStat.getFromAppClientCostTimeStat(appClientCostTimeStat);
            totalCost += appClientCostTimeTotalStat.getTotalCost();
            totalCount += appClientCostTimeTotalStat.getTotalCount();
            if (appClientCostTimeTotalStat.getMedian() > median) {
                median = appClientCostTimeTotalStat.getMedian();
            }
            if (appClientCostTimeTotalStat.getNinetyPercentMax() > ninetyPercentMax) {
                ninetyPercentMax = appClientCostTimeTotalStat.getNinetyPercentMax();
            }
            if (appClientCostTimeTotalStat.getNinetyNinePercentMax() > ninetyNinePercentMax) {
                ninetyNinePercentMax = appClientCostTimeTotalStat.getNinetyNinePercentMax();
            }
            if (appClientCostTimeTotalStat.getHundredMax() > hundredMax) {
                hundredMax = appClientCostTimeTotalStat.getHundredMax();
                maxInstanceHost = appClientCostTimeTotalStat.getMaxInstanceHost();
                maxInstancePort = appClientCostTimeTotalStat.getMaxInstancePort();
                maxInstanceId = appClientCostTimeTotalStat.getMaxInstanceId();
                maxClientIp = appClientCostTimeTotalStat.getMaxClientIp();
            }
        }
        DecimalFormat df = new DecimalFormat("0.00");
        totalCost = NumberUtils.toDouble(df.format(totalCost));
        //平均值
        if (totalCount > 0) {
            mean = totalCost / totalCount;
            mean = NumberUtils.toDouble(df.format(mean));
        }
        //添加到结果集
        resultList.add(new AppClientCostTimeTotalStat(-1, appId, collectTime, new Date(), command, totalCount, totalCost, median, mean, ninetyPercentMax, ninetyNinePercentMax, hundredMax, maxInstanceHost, maxInstancePort, maxInstanceId, maxClientIp));
    }
    return resultList;
}
Also used : HashMap(java.util.HashMap) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) Date(java.util.Date) ArrayList(java.util.ArrayList) List(java.util.List) AppClientCostTimeStat(com.sohu.cache.entity.AppClientCostTimeStat) AppClientCostTimeTotalStat(com.sohu.cache.entity.AppClientCostTimeTotalStat)

Example 3 with AppClientCostTimeTotalStat

use of com.sohu.cache.entity.AppClientCostTimeTotalStat 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

AppClientCostTimeTotalStat (com.sohu.cache.entity.AppClientCostTimeTotalStat)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 AppClientCostTimeStat (com.sohu.cache.entity.AppClientCostTimeStat)2 Date (java.util.Date)2 Map (java.util.Map)2 JSONObject (com.alibaba.fastjson.JSONObject)1 AppDesc (com.sohu.cache.entity.AppDesc)1 AppInstanceClientRelation (com.sohu.cache.entity.AppInstanceClientRelation)1 ClientCollectDataTypeEnum (com.sohu.tv.jedis.stat.enums.ClientCollectDataTypeEnum)1 DecimalFormat (java.text.DecimalFormat)1 ParseException (java.text.ParseException)1 List (java.util.List)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1