Search in sources :

Example 1 with InstanceStats

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

the class MachineCenterImpl method getMachineMemoryDetail.

@Override
public MachineStats getMachineMemoryDetail(String ip) {
    long applyMem = 0;
    long usedMem = 0;
    List<InstanceStats> instanceStats = instanceStatsDao.getInstanceStatsByIp(ip);
    for (InstanceStats instance : instanceStats) {
        applyMem += instance.getMaxMemory();
        usedMem += instance.getUsedMemory();
    }
    MachineStats machineStats = machineStatsDao.getMachineStatsByIp(ip);
    machineStats.setInfo(machineDao.getMachineInfoByIp(ip));
    MachineMemInfo machineMemInfo = new MachineMemInfo();
    machineMemInfo.setIp(ip);
    machineMemInfo.setApplyMem(applyMem);
    machineMemInfo.setUsedMem(usedMem);
    machineStats.setMachineMemInfo(machineMemInfo);
    int memoryHost = instanceDao.getMemoryByHost(ip);
    machineStats.setMemoryAllocated(memoryHost);
    return machineStats;
}
Also used : InstanceStats(com.sohu.cache.entity.InstanceStats) MachineStats(com.sohu.cache.entity.MachineStats) MachineMemInfo(com.sohu.cache.entity.MachineMemInfo)

Example 2 with InstanceStats

use of com.sohu.cache.entity.InstanceStats 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 3 with InstanceStats

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

the class ImportAppCenterImpl method check.

@Override
public ImportAppResult check(AppDesc appDesc, String appInstanceInfo) {
    // 1.检查是否应用信息为空
    if (appDesc == null) {
        return ImportAppResult.fail("应用信息为空");
    }
    // 2.检查应用名是否重复
    String appName = appDesc.getName();
    AppDesc existAppDesc = appService.getAppByName(appName);
    if (existAppDesc != null) {
        return ImportAppResult.fail(appName + ", 应用名重复");
    }
    // 3.实例信息是否为空
    if (StringUtils.isBlank(appInstanceInfo)) {
        return ImportAppResult.fail("实例详情为空");
    }
    String[] appInstanceDetails = appInstanceInfo.split("\n");
    // 4.检查实例信息格式是否正确
    for (String appInstance : appInstanceDetails) {
        if (StringUtils.isBlank(appInstance)) {
            return ImportAppResult.fail("应用实例信息有空行");
        }
        String[] instanceItems = appInstance.split(":");
        if (instanceItems.length != 3) {
            return ImportAppResult.fail("应用实例信息" + appInstance + "格式错误,必须有2个冒号");
        }
        String ip = instanceItems[0];
        // 4.1.检查ip对应的机器是否存在
        try {
            MachineInfo machineInfo = machineCenter.getMachineInfoByIp(ip);
            if (machineInfo == null) {
                return ImportAppResult.fail(appInstance + "中的ip不存在");
            } else if (machineInfo.isOffline()) {
                return ImportAppResult.fail(appInstance + "中的ip已经被删除");
            }
        } catch (Exception e) {
            return ImportAppResult.fail(appInstance + "中的ip不存在");
        }
        // 4.2.检查端口是否为整数
        String portStr = instanceItems[1];
        boolean portIsDigit = NumberUtils.isDigits(portStr);
        if (!portIsDigit) {
            return ImportAppResult.fail(appInstance + "中的port不是整数");
        }
        int port = NumberUtils.toInt(portStr);
        // 4.3.检查ip:port是否已经在instance_info表和instance_statistics中
        int count = instanceDao.getCountByIpAndPort(ip, port);
        if (count > 0) {
            return ImportAppResult.fail(appInstance + "中ip:port已经在instance_info存在");
        }
        InstanceStats instanceStats = instanceStatsDao.getInstanceStatsByHost(ip, port);
        if (instanceStats != null) {
            return ImportAppResult.fail(appInstance + "中ip:port已经在instance_statistics存在");
        }
        // 4.4.检查Redis实例是否存活
        boolean isRun = redisCenter.isRun(ip, port);
        if (!isRun) {
            return ImportAppResult.fail(appInstance + "中的节点不是存活的");
        }
        // 4.5.检查内存是否为整数
        String memoryOrMasterName = instanceItems[2];
        boolean isSentinelNode = redisCenter.isSentinelNode(ip, port);
        if (isSentinelNode) {
            // 4.5.1 sentinel节点masterName判断
            if (StringUtils.isEmpty(memoryOrMasterName)) {
                return ImportAppResult.fail(appInstance + "中的sentinel节点master为空");
            }
            // 判断masterName
            String masterName = getSentinelMasterName(ip, port);
            if (StringUtils.isEmpty(masterName) || !memoryOrMasterName.equals(masterName)) {
                return ImportAppResult.fail(ip + ":" + port + ", masterName:" + masterName + "与所填" + memoryOrMasterName + "不一致");
            }
        } else {
            // 4.5.2 内存必须是整数
            boolean maxMemoryIsDigit = NumberUtils.isDigits(memoryOrMasterName);
            if (!maxMemoryIsDigit) {
                return ImportAppResult.fail(appInstance + "中的maxmemory不是整数");
            }
        }
    }
    return ImportAppResult.success();
}
Also used : MachineInfo(com.sohu.cache.entity.MachineInfo) InstanceStats(com.sohu.cache.entity.InstanceStats) AppDesc(com.sohu.cache.entity.AppDesc)

Example 4 with InstanceStats

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

the class BaseController method fillAppInstanceStats.

/**
     * 实例统计信息
     * 
     * @param appId
     * @param model
     */
protected void fillAppInstanceStats(Long appId, Model model) {
    List<InstanceInfo> instanceList = appService.getAppInstanceInfo(appId);
    List<InstanceStats> appInstanceStats = appService.getAppInstanceStats(appId);
    Map<String, InstanceStats> instanceStatsMap = new HashMap<String, InstanceStats>();
    for (InstanceStats instanceStats : appInstanceStats) {
        instanceStatsMap.put(instanceStats.getIp() + ":" + instanceStats.getPort(), instanceStats);
    }
    model.addAttribute("instanceList", instanceList);
    model.addAttribute("instanceStatsMap", instanceStatsMap);
    //slot分布
    Map<String, InstanceSlotModel> clusterSlotsMap = redisCenter.getClusterSlotsMap(appId);
    model.addAttribute("clusterSlotsMap", clusterSlotsMap);
}
Also used : InstanceStats(com.sohu.cache.entity.InstanceStats) HashMap(java.util.HashMap) InstanceInfo(com.sohu.cache.entity.InstanceInfo) InstanceSlotModel(com.sohu.cache.entity.InstanceSlotModel)

Example 5 with InstanceStats

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

the class MachineManageController method fillInstanceModel.

/**
     * 实例统计信息
     * @param appAudit
     * @param model
     */
protected void fillInstanceModel(List<InstanceInfo> instanceList, List<InstanceStats> appInstanceStats, Model model) {
    Map<String, MachineStats> machineStatsMap = new HashMap<String, MachineStats>();
    Map<String, Long> machineCanUseMem = new HashMap<String, Long>();
    Map<String, InstanceStats> instanceStatsMap = new HashMap<String, InstanceStats>();
    Map<Long, AppDesc> appInfoMap = new HashMap<Long, AppDesc>();
    for (InstanceStats instanceStats : appInstanceStats) {
        instanceStatsMap.put(instanceStats.getIp() + ":" + instanceStats.getPort(), instanceStats);
        appInfoMap.put(instanceStats.getAppId(), appService.getByAppId(instanceStats.getAppId()));
    }
    for (InstanceInfo instanceInfo : instanceList) {
        if (TypeUtil.isRedisSentinel(instanceInfo.getType())) {
            continue;
        }
        String ip = instanceInfo.getIp();
        if (machineStatsMap.containsKey(ip)) {
            continue;
        }
        List<MachineStats> machineStatsList = machineCenter.getMachineStats(ip);
        MachineStats machineStats = null;
        for (MachineStats stats : machineStatsList) {
            if (stats.getIp().equals(ip)) {
                machineStats = stats;
                machineStatsMap.put(ip, machineStats);
                break;
            }
        }
        MachineStats ms = machineCenter.getMachineMemoryDetail(ip);
        machineCanUseMem.put(ip, ms.getMachineMemInfo().getLockedMem());
    }
    model.addAttribute("appInfoMap", appInfoMap);
    model.addAttribute("machineCanUseMem", machineCanUseMem);
    model.addAttribute("machineStatsMap", machineStatsMap);
    model.addAttribute("instanceList", instanceList);
    model.addAttribute("instanceStatsMap", instanceStatsMap);
}
Also used : HashMap(java.util.HashMap) InstanceStats(com.sohu.cache.entity.InstanceStats) MachineStats(com.sohu.cache.entity.MachineStats) AppDesc(com.sohu.cache.entity.AppDesc) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Aggregations

InstanceStats (com.sohu.cache.entity.InstanceStats)10 InstanceInfo (com.sohu.cache.entity.InstanceInfo)6 AppDesc (com.sohu.cache.entity.AppDesc)3 MachineInfo (com.sohu.cache.entity.MachineInfo)3 MachineStats (com.sohu.cache.entity.MachineStats)3 MachineMemInfo (com.sohu.cache.entity.MachineMemInfo)2 AppDetailVO (com.sohu.cache.web.vo.AppDetailVO)2 HashMap (java.util.HashMap)2 List (java.util.List)2 InstanceSlotModel (com.sohu.cache.entity.InstanceSlotModel)1 BaseTest (com.sohu.test.BaseTest)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1