Search in sources :

Example 6 with AppDetailVO

use of com.sohu.cache.web.vo.AppDetailVO in project cachecloud by sohutv.

the class AppController method appStat.

/**
     * 应用统计相关
     *
     * @param appId 应用id
     * @return
     * @throws ParseException
     */
@RequestMapping("/stat")
public ModelAndView appStat(HttpServletRequest request, HttpServletResponse response, Model model, Long appId) throws ParseException {
    String startDateParam = request.getParameter("startDate");
    String endDateParam = request.getParameter("endDate");
    /** 1.获取app的VO */
    AppDetailVO appDetail = appStatsCenter.getAppDetail(appId);
    model.addAttribute("appDetail", appDetail);
    /** 2. 时间. */
    Date startDate;
    Date endDate;
    if (StringUtils.isBlank(startDateParam) || StringUtils.isBlank(endDateParam)) {
        startDate = new Date();
        endDate = DateUtils.addDays(startDate, 1);
    } else {
        endDate = DateUtil.parseYYYY_MM_dd(endDateParam);
        startDate = DateUtil.parseYYYY_MM_dd(startDateParam);
    }
    Date yesterDay = DateUtils.addDays(startDate, -1);
    long beginTime = NumberUtils.toLong(DateUtil.formatYYYYMMddHHMM(startDate));
    long endTime = NumberUtils.toLong(DateUtil.formatYYYYMMddHHMM(endDate));
    model.addAttribute("startDate", startDateParam);
    model.addAttribute("endDate", endDateParam);
    model.addAttribute("yesterDay", DateUtil.formatDate(yesterDay, "yyyy-MM-dd"));
    // 3.是否超过1天
    if (endDate.getTime() - startDate.getTime() > TimeUnit.DAYS.toMillis(1)) {
        model.addAttribute("betweenOneDay", 0);
    } else {
        model.addAttribute("betweenOneDay", 1);
    }
    // 4. top5命令
    List<AppCommandStats> top5Commands = appStatsCenter.getTopLimitAppCommandStatsList(appId, beginTime, endTime, 5);
    model.addAttribute("top5Commands", top5Commands);
    // 5.峰值
    List<AppCommandStats> top5ClimaxList = new ArrayList<AppCommandStats>();
    if (CollectionUtils.isNotEmpty(top5Commands)) {
        for (AppCommandStats appCommandStats : top5Commands) {
            AppCommandStats temp = appStatsCenter.getCommandClimax(appId, beginTime, endTime, appCommandStats.getCommandName());
            if (temp != null) {
                top5ClimaxList.add(temp);
            }
        }
    }
    model.addAttribute("top5ClimaxList", top5ClimaxList);
    model.addAttribute("appId", appId);
    return new ModelAndView("app/appStat");
}
Also used : AppDetailVO(com.sohu.cache.web.vo.AppDetailVO) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with AppDetailVO

use of com.sohu.cache.web.vo.AppDetailVO in project cachecloud by sohutv.

the class AppDailyDataCenterImpl method generateAppDaily.

@Override
public AppDailyData generateAppDaily(long appId, Date startDate, Date endDate) {
    Assert.isTrue(appId > 0L);
    AppDetailVO appDetailVO = appStatsCenter.getAppDetail(appId);
    if (appDetailVO == null) {
        logger.error("appId={} not exist", appId);
        return null;
    }
    AppDesc appDesc = appDetailVO.getAppDesc();
    if (appDesc.isOffline()) {
        return null;
    }
    if (appDesc.isTest()) {
        return null;
    }
    AppDailyData appDailyData = new AppDailyData();
    appDailyData.setStartDate(startDate);
    appDailyData.setEndDate(endDate);
    // 应用详情
    appDailyData.setAppDetailVO(appDetailVO);
    // 慢查询
    int slowLogCount = getSlowLogCount(appId, startDate, endDate);
    appDailyData.setSlowLogCount(slowLogCount);
    // 客户端异常数
    int clientExceptionCount = getClientExceptionCount(appId, startDate, endDate);
    appDailyData.setClientExceptionCount(clientExceptionCount);
    // 客户端值分布
    Map<String, Long> valueSizeDistributeCountMap = getAppClientValueSizeDistributeCountMap(appId, startDate, endDate);
    appDailyData.setValueSizeDistributeCountMap(valueSizeDistributeCountMap);
    // 应用相关统计
    Map<String, Object> appMinuteStatMap = getAppMinuteStat(appId, startDate, endDate);
    appDailyData.setMaxMinuteClientCount(MapUtils.getIntValue(appMinuteStatMap, "maxClientCount"));
    appDailyData.setAvgMinuteClientCount(MapUtils.getIntValue(appMinuteStatMap, "avgClientCount"));
    appDailyData.setMaxMinuteCommandCount(MapUtils.getIntValue(appMinuteStatMap, "maxCommandCount"));
    appDailyData.setAvgMinuteCommandCount(MapUtils.getIntValue(appMinuteStatMap, "avgCommandCount"));
    appDailyData.setMaxMinuteHitRatio(remainNumberTwoPoint(MapUtils.getDoubleValue(appMinuteStatMap, "maxHitRatio") * 100.0));
    appDailyData.setMinMinuteHitRatio(remainNumberTwoPoint(MapUtils.getDoubleValue(appMinuteStatMap, "minHitRatio") * 100.0));
    appDailyData.setAvgHitRatio(remainNumberTwoPoint(MapUtils.getDoubleValue(appMinuteStatMap, "avgHitRatio") * 100.0));
    appDailyData.setAvgUsedMemory(MapUtils.getLongValue(appMinuteStatMap, "avgUsedMemory") / 1024 / 1024);
    appDailyData.setMaxUsedMemory(MapUtils.getLongValue(appMinuteStatMap, "maxUsedMemory") / 1024 / 1024);
    appDailyData.setExpiredKeysCount(MapUtils.getIntValue(appMinuteStatMap, "expiredKeys"));
    appDailyData.setEvictedKeysCount(MapUtils.getIntValue(appMinuteStatMap, "evictedKeys"));
    appDailyData.setAvgMinuteNetOutputByte(remainNumberTwoPoint(MapUtils.getDoubleValue(appMinuteStatMap, "avgNetInputByte") / 1024.0 / 1024.0));
    appDailyData.setMaxMinuteNetOutputByte(remainNumberTwoPoint(MapUtils.getDoubleValue(appMinuteStatMap, "maxNetInputByte") / 1024.0 / 1024.0));
    appDailyData.setAvgMinuteNetInputByte(remainNumberTwoPoint(MapUtils.getDoubleValue(appMinuteStatMap, "avgNetOutputByte") / 1024.0 / 1024.0));
    appDailyData.setMaxMinuteNetInputByte(remainNumberTwoPoint(MapUtils.getDoubleValue(appMinuteStatMap, "maxNetOutputByte") / 1024.0 / 1024.0));
    appDailyData.setAvgObjectSize(MapUtils.getIntValue(appMinuteStatMap, "avgObjectSize"));
    appDailyData.setMaxObjectSize(MapUtils.getIntValue(appMinuteStatMap, "maxObjectSize"));
    return appDailyData;
}
Also used : AppDetailVO(com.sohu.cache.web.vo.AppDetailVO) AppDesc(com.sohu.cache.entity.AppDesc) AppDailyData(com.sohu.cache.entity.AppDailyData)

Example 8 with AppDetailVO

use of com.sohu.cache.web.vo.AppDetailVO in project cachecloud by sohutv.

the class AppMemInspector method inspect.

@Override
public boolean inspect(Map<InspectParamEnum, Object> paramMap) {
    Long appId = MapUtils.getLong(paramMap, InspectParamEnum.SPLIT_KEY);
    List<AppDesc> appDescList = new ArrayList<AppDesc>();
    AppDesc app = appDao.getAppDescById(appId);
    if (app != null) {
        appDescList.add(app);
    }
    if (CollectionUtils.isEmpty(appDescList)) {
        logger.error("appList is empty, appId={}", appId);
        return true;
    }
    for (AppDesc appDesc : appDescList) {
        //测试不检查
        if (appDesc.getIsTest() == 1) {
            continue;
        }
        long checkAppId = appDesc.getAppId();
        AppDetailVO appDetailVO = appStatsCenter.getAppDetail(checkAppId);
        if (appDetailVO == null) {
            continue;
        }
        double appMemUsePercent = appDetailVO.getMemUsePercent();
        int appUseSetMemAlertValue = appDesc.getMemAlertValue();
        // 先检查应用的内存使用率是否超过阀值,如果没有再检查分片
        if (appMemUsePercent > appUseSetMemAlertValue) {
            // 报警
            alertAppMemUse(appDetailVO);
        } else {
            List<InstanceInfo> appInstanceInfoList = (List<InstanceInfo>) paramMap.get(InspectParamEnum.INSTANCE_LIST);
            if (CollectionUtils.isNotEmpty(appInstanceInfoList)) {
                for (InstanceInfo instanceInfo : appInstanceInfoList) {
                    if (instanceInfo == null) {
                        continue;
                    }
                    if (!TypeUtil.isRedisType(instanceInfo.getType())) {
                        continue;
                    }
                    // 忽略sentinel观察者
                    if (TypeUtil.isRedisSentinel(instanceInfo.getType())) {
                        continue;
                    }
                    long instanceId = instanceInfo.getId();
                    InstanceStats instanceStats = instanceStatsCenter.getInstanceStats(instanceId);
                    if (instanceStats == null) {
                        continue;
                    }
                    double instanceMemUsePercent = instanceStats.getMemUsePercent();
                    // 大于标准值
                    if (instanceMemUsePercent > appUseSetMemAlertValue) {
                        alertInstanceMemUse(instanceStats, appDetailVO);
                    }
                }
            }
        }
    }
    return true;
}
Also used : InstanceStats(com.sohu.cache.entity.InstanceStats) ArrayList(java.util.ArrayList) AppDetailVO(com.sohu.cache.web.vo.AppDetailVO) ArrayList(java.util.ArrayList) List(java.util.List) AppDesc(com.sohu.cache.entity.AppDesc) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 9 with AppDetailVO

use of com.sohu.cache.web.vo.AppDetailVO in project cachecloud by sohutv.

the class TotalManageController method doTotalList.

@RequestMapping(value = "/list")
public ModelAndView doTotalList(HttpServletRequest request, HttpServletResponse response, Model model) {
    AppUser currentUser = getUserInfo(request);
    List<AppDesc> apps = appService.getAppDescList(currentUser, new AppSearch());
    List<AppDetailVO> appDetailList = new ArrayList<AppDetailVO>();
    long totalApplyMem = 0;
    long totalUsedMem = 0;
    long totalApps = 0;
    long totalRunningApps = 0;
    if (apps != null && apps.size() > 0) {
        for (AppDesc appDesc : apps) {
            AppDetailVO appDetail = appStatsCenter.getAppDetail(appDesc.getAppId());
            appDetailList.add(appDetail);
            totalApplyMem += appDetail.getMem();
            totalUsedMem += appDetail.getMemUsePercent() * appDetail.getMem() / 100.0;
            if (appDesc.getStatus() == AppStatusEnum.STATUS_PUBLISHED.getStatus()) {
                totalRunningApps++;
            }
            totalApps++;
        }
    }
    long totalMachineMem = 0;
    long totalFreeMachineMem = 0;
    List<MachineStats> allMachineStats = machineCenter.getAllMachineStats();
    for (MachineStats machineStats : allMachineStats) {
        totalMachineMem += NumberUtils.toLong(machineStats.getMemoryTotal(), 0l);
        totalFreeMachineMem += NumberUtils.toLong(machineStats.getMemoryFree(), 0l);
    }
    long totalInstanceMem = 0;
    long totalUseInstanceMem = 0;
    List<InstanceStats> instanceStats = instanceStatsCenter.getInstanceStats();
    for (InstanceStats instanceStat : instanceStats) {
        totalInstanceMem += instanceStat.getMaxMemory();
        totalUseInstanceMem += instanceStat.getUsedMemory();
    }
    model.addAttribute("totalApps", totalApps);
    model.addAttribute("totalApplyMem", totalApplyMem);
    model.addAttribute("totalUsedMem", totalUsedMem);
    model.addAttribute("totalRunningApps", totalRunningApps);
    model.addAttribute("totalMachineMem", totalMachineMem);
    model.addAttribute("totalFreeMachineMem", totalFreeMachineMem);
    model.addAttribute("totalInstanceMem", totalInstanceMem);
    model.addAttribute("totalUseInstanceMem", totalUseInstanceMem);
    model.addAttribute("apps", apps);
    model.addAttribute("appDetailList", appDetailList);
    model.addAttribute("list", apps);
    model.addAttribute("totalActive", SuccessEnum.SUCCESS.value());
    return new ModelAndView("manage/total/list");
}
Also used : ArrayList(java.util.ArrayList) AppDetailVO(com.sohu.cache.web.vo.AppDetailVO) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with AppDetailVO

use of com.sohu.cache.web.vo.AppDetailVO in project cachecloud by sohutv.

the class AppDailyDataCenterImpl method sendAppDailyEmail.

@Override
public boolean sendAppDailyEmail(long appId, Date startDate, Date endDate) {
    try {
        AppDailyData appDailyData = generateAppDaily(appId, startDate, endDate);
        if (appDailyData == null) {
            return false;
        }
        AppDetailVO appDetailVO = appDailyData.getAppDetailVO();
        noticeAppDaily(startDate, appDetailVO, appDailyData);
        return true;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return false;
    }
}
Also used : AppDetailVO(com.sohu.cache.web.vo.AppDetailVO) AppDailyData(com.sohu.cache.entity.AppDailyData)

Aggregations

AppDetailVO (com.sohu.cache.web.vo.AppDetailVO)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ModelAndView (org.springframework.web.servlet.ModelAndView)5 ArrayList (java.util.ArrayList)4 AppDailyData (com.sohu.cache.entity.AppDailyData)2 AppDesc (com.sohu.cache.entity.AppDesc)2 InstanceInfo (com.sohu.cache.entity.InstanceInfo)2 InstanceStats (com.sohu.cache.entity.InstanceStats)2 Date (java.util.Date)2 List (java.util.List)2 HighchartPoint (com.sohu.cache.web.chart.model.HighchartPoint)1 Page (com.sohu.cache.web.util.Page)1 BaseTest (com.sohu.test.BaseTest)1 DecimalFormat (java.text.DecimalFormat)1 Test (org.junit.Test)1