Search in sources :

Example 16 with InstanceInfo

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

the class RedisClientController method getRedisStandaloneInfo.

private void getRedisStandaloneInfo(HttpServletRequest request, long appId, Model model) {
    String clientVersion = request.getParameter("clientVersion");
    if (!checkClientVersion(clientVersion, model)) {
        return;
    }
    List<InstanceInfo> instanceList = instanceDao.getInstListByAppId(appId);
    String standalone = null;
    for (InstanceInfo instanceInfo : instanceList) {
        if (instanceInfo.isOffline()) {
            continue;
        }
        standalone = instanceInfo.getIp() + ":" + instanceInfo.getPort();
    }
    model.addAttribute("standalone", standalone);
    model.addAttribute("status", ClientStatusEnum.GOOD.getStatus());
    //保存版本信息
    try {
        clientVersionService.saveOrUpdateClientVersion(appId, IpUtil.getIpAddr(request), clientVersion);
    } catch (Exception e) {
        logger.error("redisStandalone heart error:" + e.getMessage(), e);
    }
}
Also used : InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 17 with InstanceInfo

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

the class MachineCenterImpl method getMachineInstanceInfo.

@Override
public List<InstanceInfo> getMachineInstanceInfo(String ip) {
    List<InstanceInfo> resultList = instanceDao.getInstListByIp(ip);
    if (resultList == null || resultList.isEmpty()) {
        return resultList;
    }
    if (resultList != null && resultList.size() > 0) {
        for (InstanceInfo instanceInfo : resultList) {
            int type = instanceInfo.getType();
            if (instanceInfo.getStatus() != InstanceStatusEnum.GOOD_STATUS.getStatus()) {
                continue;
            }
            if (TypeUtil.isRedisType(type)) {
                if (TypeUtil.isRedisSentinel(type)) {
                    continue;
                }
                String host = instanceInfo.getIp();
                int port = instanceInfo.getPort();
                Boolean isMaster = redisCenter.isMaster(host, port);
                instanceInfo.setRoleDesc(isMaster);
                if (isMaster != null && !isMaster) {
                    HostAndPort hap = redisCenter.getMaster(host, port);
                    if (hap != null) {
                        instanceInfo.setMasterHost(hap.getHost());
                        instanceInfo.setMasterPort(hap.getPort());
                        for (InstanceInfo innerInfo : resultList) {
                            if (innerInfo.getIp().equals(hap.getHost()) && innerInfo.getPort() == hap.getPort()) {
                                instanceInfo.setMasterInstanceId(innerInfo.getId());
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    return resultList;
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 18 with InstanceInfo

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

the class AppInspectHandler method getSplitMap.

@Override
protected Map<String, List<InstanceInfo>> getSplitMap() {
    List<InstanceInfo> list = getAllInstanceList();
    Map<String, List<InstanceInfo>> hostMap = new TreeMap<String, List<InstanceInfo>>();
    for (InstanceInfo instanceInfo : list) {
        String appId = String.valueOf(instanceInfo.getAppId());
        if (hostMap.containsKey(appId)) {
            hostMap.get(appId).add(instanceInfo);
        } else {
            List<InstanceInfo> hostInstances = new ArrayList<InstanceInfo>();
            hostInstances.add(instanceInfo);
            hostMap.put(appId, hostInstances);
        }
    }
    return hostMap;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 19 with InstanceInfo

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

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

the class InstanceRunInspector method inspect.

@Override
public boolean inspect(Map<InspectParamEnum, Object> paramMap) {
    String host = MapUtils.getString(paramMap, InspectParamEnum.SPLIT_KEY);
    List<InstanceInfo> list = (List<InstanceInfo>) paramMap.get(InspectParamEnum.INSTANCE_LIST);
    for (InstanceInfo info : list) {
        final int port = info.getPort();
        final int type = info.getType();
        long appId = info.getAppId();
        if (TypeUtil.isRedisType(type)) {
            boolean isRun = redisCenter.isRun(host, port);
            Boolean isUpdate = updateInstanceByRun(isRun, info);
            if (isUpdate == null) {
                continue;
            } else if (isUpdate) {
                redisCenter.deployRedisCollection(appId, host, port);
                redisCenter.deployRedisSlowLogCollection(appId, host, port);
            } else {
                redisCenter.unDeployRedisCollection(appId, host, port);
                redisCenter.unDeployRedisSlowLogCollection(appId, host, port);
            }
            // 错误
            if (isUpdate != null) {
                alertInstanceInfo(info);
            }
        }
    }
    return true;
}
Also used : List(java.util.List) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Aggregations

InstanceInfo (com.sohu.cache.entity.InstanceInfo)45 AppDesc (com.sohu.cache.entity.AppDesc)11 List (java.util.List)7 Jedis (redis.clients.jedis.Jedis)7 InstanceStats (com.sohu.cache.entity.InstanceStats)6 MachineInfo (com.sohu.cache.entity.MachineInfo)5 ArrayList (java.util.ArrayList)5 IdempotentConfirmer (com.sohu.cache.util.IdempotentConfirmer)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 InstanceCommandStats (com.sohu.cache.entity.InstanceCommandStats)2 InstanceSlotModel (com.sohu.cache.entity.InstanceSlotModel)2 AppDetailVO (com.sohu.cache.web.vo.AppDetailVO)2 BaseTest (com.sohu.test.BaseTest)2 HashSet (java.util.HashSet)2 TreeMap (java.util.TreeMap)2 Test (org.junit.Test)2 HostAndPort (redis.clients.jedis.HostAndPort)2