Search in sources :

Example 1 with AppDetailVO

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

the class AppEmailUtil method noticeOfflineApp.

/**
     * 下线应用通知
     * @param appUser
     * @param appId
     * @param isSuccess
     */
public void noticeOfflineApp(AppUser appUser, Long appId, boolean isSuccess) {
    AppDetailVO appDetailVO = appStatsCenter.getAppDetail(appId);
    StringBuilder mailContent = new StringBuilder();
    mailContent.append(appUser.getChName()).append(",对应用appid=").append(appId);
    mailContent.append("进行下线,操作结果是").append(isSuccess ? "成功" : "失败");
    mailContent.append(",请知晓!");
    emailComponent.sendMail("【CacheCloud】状态通知", mailContent.toString(), appDetailVO.getEmailList(), Arrays.asList(emailComponent.getAdminEmail().split(ConstUtils.COMMA)));
}
Also used : AppDetailVO(com.sohu.cache.web.vo.AppDetailVO)

Example 2 with AppDetailVO

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

the class AppStatsCenterImpl method getAppDetail.

/**
     * 获取应用详细信息
     */
@Override
public AppDetailVO getAppDetail(long appId) {
    AppDesc appDesc = appDao.getAppDescById(appId);
    if (appDesc == null) {
        return null;
    }
    AppDetailVO resultVO = new AppDetailVO();
    resultVO.setAppDesc(appDesc);
    Set<String> machines = new HashSet<String>();
    List<InstanceInfo> instanceList = instanceDao.getInstListByAppId(appId);
    if (instanceList == null || instanceList.isEmpty()) {
        return resultVO;
    }
    long hits = 0L;
    long miss = 0L;
    long allUsedMemory = 0L;
    long allMaxMemory = 0L;
    List<InstanceStats> instanceStatsList = instanceStatsDao.getInstanceStatsByAppId(appId);
    if (instanceStatsList != null && instanceStatsList.size() > 0) {
        Map<Long, InstanceStats> instanceStatMap = new HashMap<Long, InstanceStats>();
        for (InstanceStats stats : instanceStatsList) {
            instanceStatMap.put(stats.getInstId(), stats);
        }
        for (InstanceInfo instanceInfo : instanceList) {
            if (instanceInfo.isOffline()) {
                continue;
            }
            machines.add(instanceInfo.getIp());
            InstanceStats instanceStats = instanceStatMap.get(Long.valueOf(instanceInfo.getId()));
            if (instanceStats == null) {
                continue;
            }
            boolean isMaster = isMaster(instanceStats);
            long usedMemory = instanceStats.getUsedMemory();
            long usedMemoryMB = usedMemory / 1024 / 1024;
            allUsedMemory += usedMemory;
            allMaxMemory += instanceStats.getMaxMemory();
            hits += instanceStats.getHits();
            miss += instanceStats.getMisses();
            if (isMaster) {
                resultVO.setMem(resultVO.getMem() + instanceInfo.getMem());
                resultVO.setCurrentMem(resultVO.getCurrentMem() + usedMemoryMB);
                resultVO.setCurrentObjNum(resultVO.getCurrentObjNum() + instanceStats.getCurrItems());
                resultVO.setMasterNum(resultVO.getMasterNum() + 1);
                //按instanceStats计算conn
                resultVO.setConn(resultVO.getConn() + instanceStats.getCurrConnections());
            } else {
                resultVO.setSlaveNum(resultVO.getSlaveNum() + 1);
            }
        }
    }
    List<AppUser> userList = userService.getByAppId(appId);
    if (userList != null && userList.size() > 0) {
        resultVO.setAppUsers(userList);
    }
    resultVO.setMachineNum(machines.size());
    if (allMaxMemory == 0L) {
        resultVO.setMemUsePercent(0.0D);
    } else {
        double percent = 100 * (double) allUsedMemory / (allMaxMemory);
        DecimalFormat df = new DecimalFormat("##.##");
        resultVO.setMemUsePercent(Double.parseDouble(df.format(percent)));
    }
    if (miss == 0L) {
        if (hits > 0) {
            resultVO.setHitPercent(100.0D);
        } else {
            resultVO.setHitPercent(0.0D);
        }
    } else {
        double percent = 100 * (double) hits / (hits + miss);
        DecimalFormat df = new DecimalFormat("##.##");
        resultVO.setHitPercent(Double.parseDouble(df.format(percent)));
    }
    return resultVO;
}
Also used : DecimalFormat(java.text.DecimalFormat) AppDetailVO(com.sohu.cache.web.vo.AppDetailVO)

Example 3 with AppDetailVO

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

the class AppController method appCommandAnalysis.

/**
     * 命令曲线
     *
     * @param appId
     * @param firstCommand 第一条命令
     * @throws ParseException
     */
@RequestMapping("/commandAnalysis")
public ModelAndView appCommandAnalysis(HttpServletRequest request, HttpServletResponse response, Model model, Long appId, String firstCommand) 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 endDate;
    Date startDate;
    if (StringUtils.isBlank(startDateParam) || StringUtils.isBlank(endDateParam)) {
        startDate = new Date();
        endDate = DateUtils.addDays(startDate, 1);
        startDateParam = DateUtil.formatDate(startDate, "yyyy-MM-dd");
        endDateParam = DateUtil.formatDate(endDate, "yyyy-MM-dd");
    } else {
        endDate = DateUtil.parseYYYY_MM_dd(endDateParam);
        startDate = DateUtil.parseYYYY_MM_dd(startDateParam);
    }
    Date yesterDay = DateUtils.addDays(startDate, -1);
    model.addAttribute("yesterDay", DateUtil.formatDate(yesterDay, "yyyy-MM-dd"));
    model.addAttribute("startDate", startDateParam);
    model.addAttribute("endDate", endDateParam);
    long beginTime = NumberUtils.toLong(DateUtil.formatYYYYMMddHHMM(startDate));
    long endTime = NumberUtils.toLong(DateUtil.formatYYYYMMddHHMM(endDate));
    // 3.是否超过1天
    if (endDate.getTime() - startDate.getTime() > TimeUnit.DAYS.toMillis(1)) {
        model.addAttribute("betweenOneDay", 0);
    } else {
        model.addAttribute("betweenOneDay", 1);
    }
    /** 3.获取top5命令 */
    List<AppCommandStats> allCommands = appStatsCenter.getTopLimitAppCommandStatsList(appId, beginTime, endTime, commandsCount);
    model.addAttribute("allCommands", allCommands);
    if (StringUtils.isBlank(firstCommand) && CollectionUtils.isNotEmpty(allCommands)) {
        model.addAttribute("firstCommand", allCommands.get(0).getCommandName());
    } else {
        model.addAttribute("firstCommand", firstCommand);
    }
    model.addAttribute("appId", appId);
    // 返回标签名
    return new ModelAndView("app/appCommandAnalysis");
}
Also used : AppDetailVO(com.sohu.cache.web.vo.AppDetailVO) ModelAndView(org.springframework.web.servlet.ModelAndView) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with AppDetailVO

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

the class AppController method doAppList.

/**
     * 应用列表
     *
     * @param userId
     * @return
     */
@RequestMapping(value = "/list")
public ModelAndView doAppList(HttpServletRequest request, HttpServletResponse response, Model model, AppSearch appSearch) {
    // 1.获取该用户能够读取的应用列表,没有返回申请页面
    AppUser currentUser = getUserInfo(request);
    model.addAttribute("currentUser", currentUser);
    int userAppCount = appService.getUserAppCount(currentUser.getId());
    if (userAppCount == 0 && !AppUserTypeEnum.ADMIN_USER.value().equals(currentUser.getType())) {
        return new ModelAndView("redirect:/admin/app/init");
    }
    // 2.1 分页相关
    int totalCount = appService.getAppDescCount(currentUser, appSearch);
    int pageNo = NumberUtils.toInt(request.getParameter("pageNo"), 1);
    int pageSize = NumberUtils.toInt(request.getParameter("pageSize"), 10);
    Page page = new Page(pageNo, pageSize, totalCount);
    model.addAttribute("page", page);
    // 2.2 查询指定时间客户端异常
    appSearch.setPage(page);
    List<AppDesc> apps = appService.getAppDescList(currentUser, appSearch);
    // 2.3 应用列表
    List<AppDetailVO> appDetailList = new ArrayList<AppDetailVO>();
    model.addAttribute("appDetailList", appDetailList);
    // 3. 全局统计
    long totalApplyMem = 0;
    long totalUsedMem = 0;
    long totalApps = 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;
            totalApps++;
        }
    }
    model.addAttribute("totalApps", totalApps);
    model.addAttribute("totalApplyMem", totalApplyMem);
    model.addAttribute("totalUsedMem", totalUsedMem);
    return new ModelAndView("app/appList");
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) AppDetailVO(com.sohu.cache.web.vo.AppDetailVO) Page(com.sohu.cache.web.util.Page) HighchartPoint(com.sohu.cache.web.chart.model.HighchartPoint) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with AppDetailVO

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

the class AppController method appDetail.

/**
     * 应用基本信息
     *
     * @param appId 应用id
     */
@RequestMapping("/detail")
public ModelAndView appDetail(HttpServletRequest request, HttpServletResponse response, Model model, Long appId) {
    // 获取应用vo
    AppDetailVO appDetail = appStatsCenter.getAppDetail(appId);
    model.addAttribute("appDetail", appDetail);
    return new ModelAndView("app/appDetail");
}
Also used : AppDetailVO(com.sohu.cache.web.vo.AppDetailVO) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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