Search in sources :

Example 6 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 7 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 8 with InstanceStats

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

the class MachineCenterImpl method getAllMachineStats.

@Override
public List<MachineStats> getAllMachineStats() {
    List<MachineStats> list = machineStatsDao.getAllMachineStats();
    for (MachineStats ms : list) {
        String ip = ms.getIp();
        MachineInfo machineInfo = machineDao.getMachineInfoByIp(ip);
        if (machineInfo == null || machineInfo.isOffline()) {
            continue;
        }
        int memoryHost = instanceDao.getMemoryByHost(ip);
        getMachineMemoryDetail(ms.getIp());
        //获取机器申请和使用内存
        long applyMem = 0;
        long usedMem = 0;
        List<InstanceStats> instanceStats = instanceStatsDao.getInstanceStatsByIp(ip);
        for (InstanceStats instance : instanceStats) {
            applyMem += instance.getMaxMemory();
            usedMem += instance.getUsedMemory();
        }
        MachineMemInfo machineMemInfo = new MachineMemInfo();
        machineMemInfo.setIp(ip);
        machineMemInfo.setApplyMem(applyMem);
        machineMemInfo.setUsedMem(usedMem);
        ms.setMachineMemInfo(machineMemInfo);
        ms.setMemoryAllocated(memoryHost);
        ms.setInfo(machineInfo);
    }
    return list;
}
Also used : MachineInfo(com.sohu.cache.entity.MachineInfo) InstanceStats(com.sohu.cache.entity.InstanceStats) MachineStats(com.sohu.cache.entity.MachineStats) MachineMemInfo(com.sohu.cache.entity.MachineMemInfo)

Example 9 with InstanceStats

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

the class AppClientConnInspector method inspect.

@Override
public boolean inspect(Map<InspectParamEnum, Object> paramMap) {
    Long appId = MapUtils.getLong(paramMap, InspectParamEnum.SPLIT_KEY);
    AppDetailVO appDetailVO = appStatsCenter.getAppDetail(appId);
    if (appDetailVO == null) {
        logger.warn("appId {} appDetailVO is empty", appId);
        return true;
    }
    List<InstanceInfo> appInstanceInfoList = (List<InstanceInfo>) paramMap.get(InspectParamEnum.INSTANCE_LIST);
    if (CollectionUtils.isEmpty(appInstanceInfoList)) {
        logger.warn("appId {} instanceList is empty", appId);
        return true;
    }
    // 报警阀值
    int appClientConnThreshold = getClientConnThreshold(appDetailVO.getAppDesc());
    int appClientConnNum = appDetailVO.getConn();
    // 阀值乘以分片个数
    int instanceCount = appInstanceInfoList.size();
    if (appClientConnNum > appClientConnThreshold * instanceCount) {
        alertAppClientConn(appDetailVO, appClientConnThreshold, instanceCount);
    } else {
        for (InstanceInfo instanceInfo : appInstanceInfoList) {
            if (instanceInfo == null) {
                continue;
            }
            if (instanceInfo.isOffline()) {
                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 instanceClientConnNum = instanceStats.getCurrConnections();
            // 大于标准值
            if (instanceClientConnNum > appClientConnThreshold) {
                alertInstanceClientConn(instanceStats, appDetailVO, appClientConnThreshold);
            }
        }
    }
    return true;
}
Also used : InstanceStats(com.sohu.cache.entity.InstanceStats) AppDetailVO(com.sohu.cache.web.vo.AppDetailVO) List(java.util.List) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 10 with InstanceStats

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

the class InstanceStatsCenterTest method getInstanceStats.

@Test
public void getInstanceStats() {
    InstanceStats instanceStats = instanceStatsCenter.getInstanceStats(51L);
    logger.info("{}", instanceStats);
    logger.info("{}", instanceStats.getInfoMap());
    logger.info("{}", instanceStats.isRun());
    instanceStats = instanceStatsCenter.getInstanceStats(139L);
    logger.info("{}", instanceStats);
    logger.info("{}", instanceStats.getInfoMap());
    logger.info("{}", instanceStats.isRun());
}
Also used : InstanceStats(com.sohu.cache.entity.InstanceStats) BaseTest(com.sohu.test.BaseTest) Test(org.junit.Test)

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