Search in sources :

Example 1 with InstanceInfo

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

the class RedisImportantDataDeal method clearAllAppData.

@Test
public void clearAllAppData() {
    // /////////////一定要谨慎处理/////////////////
    // /////////////一定要谨慎处理/////////////////
    // /////////////一定要谨慎处理/////////////////
    long appId = 000L;
    // /////////////一定要谨慎处理///////////////
    // /////////////一定要谨慎处理/////////////////
    // /////////////一定要谨慎处理/////////////////
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    logger.warn("确认要清除appId:" + appId + "的所有内存数据(输入y代表确认):");
    String confirm = null;
    try {
        confirm = br.readLine();
    } catch (IOException e1) {
        e1.printStackTrace();
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    if (!"y".equals(confirm)) {
        return;
    }
    List<InstanceInfo> instanceList = instanceDao.getInstListByAppId(appId);
    if (CollectionUtils.isEmpty(instanceList)) {
        logger.error("appId: {}, 可能输入错误,不存在实例列表");
    }
    for (InstanceInfo instance : instanceList) {
        if (instance.getStatus() != InstanceStatusEnum.GOOD_STATUS.getStatus()) {
            continue;
        }
        String host = instance.getIp();
        int port = instance.getPort();
        // master + 非sentinel节点
        Boolean isMater = redisCenter.isMaster(host, port);
        if (isMater != null && isMater.equals(true) && !TypeUtil.isRedisSentinel(instance.getType())) {
            Jedis jedis = new Jedis(host, port, 30000);
            try {
                logger.info("{}:{} 开始清理内存", host, port);
                long start = System.currentTimeMillis();
                jedis.flushAll();
                logger.info("{}:{} 清理完成, 耗时:{} ms", host, port, (System.currentTimeMillis() - start));
            } catch (Exception e) {
                logger.error(e.getMessage());
            } finally {
                jedis.close();
            }
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) InstanceInfo(com.sohu.cache.entity.InstanceInfo) IOException(java.io.IOException) BaseTest(com.sohu.test.BaseTest) Test(org.junit.Test)

Example 2 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 3 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 4 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 5 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)

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