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");
}
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;
}
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;
}
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");
}
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;
}
}
Aggregations