Search in sources :

Example 41 with InstanceInfo

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

the class AppServiceAlertImplTest method getAppInstanceInfo.

@Test
public void getAppInstanceInfo() {
    watch.start("getAppInstanceInfo1");
    List<InstanceInfo> list = appService.getAppInstanceInfo(10129L);
    watch.stop();
    watch.start("getAppInstanceInfo2");
    list = appService.getAppInstanceInfo(10129L);
    watch.stop();
    logger.info(watch.prettyPrint());
    for (InstanceInfo info : list) {
        logger.warn("{}:{} -> {}:{} id={}", info.getIp(), info.getPort(), info.getMasterHost(), info.getMasterPort(), info.getMasterInstanceId());
    }
}
Also used : InstanceInfo(com.sohu.cache.entity.InstanceInfo) BaseTest(com.sohu.test.BaseTest) Test(org.junit.Test)

Example 42 with InstanceInfo

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

the class RedisClientController method getRedisSentinelInfo.

private void getRedisSentinelInfo(HttpServletRequest request, long appId, Model model) {
    String clientVersion = request.getParameter("clientVersion");
    if (!checkClientVersion(clientVersion, model)) {
        return;
    }
    List<InstanceInfo> instanceList = instanceDao.getInstListByAppId(appId);
    if (instanceList == null || instanceList.isEmpty()) {
        model.addAttribute("status", ClientStatusEnum.ERROR.getStatus());
        model.addAttribute("message", "appId: " + appId + " 实例集合为空 ");
        return;
    }
    String masterName = null;
    List<String> sentinelList = new ArrayList<String>();
    for (InstanceInfo instance : instanceList) {
        if (instance.isOffline()) {
            continue;
        }
        if (instance.getType() == ConstUtils.CACHE_REDIS_SENTINEL && masterName == null && StringUtils.isNotBlank(instance.getCmd())) {
            masterName = instance.getCmd();
        }
        if (instance.getType() == ConstUtils.CACHE_REDIS_SENTINEL) {
            sentinelList.add(instance.getIp() + ":" + instance.getPort());
        }
    }
    String sentinels = StringUtils.join(sentinelList, " ");
    model.addAttribute("sentinels", sentinels);
    model.addAttribute("masterName", masterName);
    model.addAttribute("appId", appId);
    model.addAttribute("status", ClientStatusEnum.GOOD.getStatus());
    //保存版本信息
    try {
        clientVersionService.saveOrUpdateClientVersion(appId, IpUtil.getIpAddr(request), clientVersion);
    } catch (Exception e) {
        logger.error("redisSentinel heart error:" + e.getMessage(), e);
    }
}
Also used : ArrayList(java.util.ArrayList) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 43 with InstanceInfo

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

the class ClientReportCostDistriServiceImpl method generate.

private AppClientCostTimeStat generate(String clientIp, long collectTime, long reportTime, Map<String, Object> map) {
    try {
        Integer count = MapUtils.getInteger(map, ClientReportConstant.COST_COUNT, 0);
        String command = MapUtils.getString(map, ClientReportConstant.COST_COMMAND, "");
        if (StringUtils.isBlank(command)) {
            logger.warn("command is empty!");
            return null;
        }
        String hostPort = MapUtils.getString(map, ClientReportConstant.COST_HOST_PORT, "");
        if (StringUtils.isBlank(hostPort)) {
            logger.warn("hostPort is empty", hostPort);
            return null;
        }
        int index = hostPort.indexOf(":");
        if (index <= 0) {
            logger.warn("hostPort {} format is wrong", hostPort);
            return null;
        }
        String host = hostPort.substring(0, index);
        int port = NumberUtils.toInt(hostPort.substring(index + 1));
        // 实例信息
        InstanceInfo instanceInfo = clientReportInstanceService.getInstanceInfoByHostPort(host, port);
        if (instanceInfo == null) {
            //                logger.warn("instanceInfo is empty, host is {}, port is {}", host, port);
            return null;
        }
        long appId = instanceInfo.getAppId();
        // 耗时分布详情
        double mean = MapUtils.getDouble(map, ClientReportConstant.COST_TIME_MEAN, 0.0);
        Integer median = MapUtils.getInteger(map, ClientReportConstant.COST_TIME_MEDIAN, 0);
        Integer ninetyPercentMax = MapUtils.getInteger(map, ClientReportConstant.COST_TIME_90_MAX, 0);
        Integer ninetyNinePercentMax = MapUtils.getInteger(map, ClientReportConstant.COST_TIME_99_MAX, 0);
        Integer hunredMax = MapUtils.getInteger(map, ClientReportConstant.COST_TIME_100_MAX, 0);
        AppClientCostTimeStat stat = new AppClientCostTimeStat();
        stat.setAppId(appId);
        stat.setClientIp(clientIp);
        stat.setReportTime(new Date(reportTime));
        stat.setCollectTime(collectTime);
        stat.setCreateTime(new Date());
        stat.setCommand(command);
        stat.setCount(count);
        stat.setInstanceHost(host);
        stat.setInstancePort(port);
        stat.setMean(NumberUtils.toDouble(new DecimalFormat("#.00").format(mean)));
        stat.setMedian(median);
        stat.setNinetyPercentMax(ninetyPercentMax);
        stat.setNinetyNinePercentMax(ninetyNinePercentMax);
        stat.setHundredMax(hunredMax);
        stat.setInstanceId(instanceInfo.getId());
        return stat;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) InstanceInfo(com.sohu.cache.entity.InstanceInfo) AppClientCostTimeStat(com.sohu.cache.entity.AppClientCostTimeStat) Date(java.util.Date)

Example 44 with InstanceInfo

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

the class ClientReportExceptionServiceImpl method generate.

private AppClientExceptionStat generate(String clientIp, long collectTime, long reportTime, Map<String, Object> map) {
    // 异常信息
    String exceptionClass = MapUtils.getString(map, ClientReportConstant.EXCEPTION_CLASS, "");
    Long exceptionCount = MapUtils.getLong(map, ClientReportConstant.EXCEPTION_COUNT, 0L);
    int exceptionType = MapUtils.getInteger(map, ClientReportConstant.EXCEPTION_TYPE, ClientExceptionType.REDIS_TYPE.getType());
    String host = null;
    Integer port = null;
    Integer instanceId = null;
    long appId;
    if (ClientExceptionType.REDIS_TYPE.getType() == exceptionType) {
        // 实例host:port
        String hostPort = MapUtils.getString(map, ClientReportConstant.EXCEPTION_HOST_PORT, "");
        if (StringUtils.isEmpty(hostPort)) {
            logger.warn("hostPort is empty", hostPort);
            return null;
        }
        int index = hostPort.indexOf(":");
        if (index <= 0) {
            logger.warn("hostPort {} format is wrong", hostPort);
            return null;
        }
        host = hostPort.substring(0, index);
        port = NumberUtils.toInt(hostPort.substring(index + 1));
        // 实例信息
        InstanceInfo instanceInfo = clientReportInstanceService.getInstanceInfoByHostPort(host, port);
        if (instanceInfo == null) {
            //                logger.warn("instanceInfo is empty, host is {}, port is {}", host, port);
            return null;
        }
        // 实例id
        instanceId = instanceInfo.getId();
        // 应用id
        appId = instanceInfo.getAppId();
    } else {
        List<AppClientVersion> appClientVersion = appClientVersionDao.getByClientIp(clientIp);
        if (CollectionUtils.isNotEmpty(appClientVersion)) {
            appId = appClientVersion.get(0).getAppId();
        } else {
            appId = 0;
        }
    }
    // 组装AppClientExceptionStat
    AppClientExceptionStat stat = new AppClientExceptionStat();
    stat.setAppId(appId);
    stat.setClientIp(clientIp);
    stat.setReportTime(new Date(reportTime));
    stat.setCollectTime(collectTime);
    stat.setCreateTime(new Date());
    stat.setExceptionClass(exceptionClass);
    stat.setExceptionCount(exceptionCount);
    stat.setInstanceHost(host);
    stat.setInstancePort(port);
    stat.setInstanceId(instanceId);
    stat.setType(exceptionType);
    return stat;
}
Also used : AppClientExceptionStat(com.sohu.cache.entity.AppClientExceptionStat) InstanceInfo(com.sohu.cache.entity.InstanceInfo) AppClientVersion(com.sohu.cache.entity.AppClientVersion) Date(java.util.Date)

Example 45 with InstanceInfo

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

the class ClientReportValueDistriServiceImplV2 method generate.

private AppClientValueDistriStatTotal generate(long collectTime, long reportTime, Map<String, Object> map) {
    String valueDistri = MapUtils.getString(map, ClientReportConstant.VALUE_DISTRI, "");
    ValueSizeDistriEnum valueSizeDistriEnum = ValueSizeDistriEnum.getByValue(valueDistri);
    if (valueSizeDistriEnum == null) {
        logger.warn("valueDistri {} is wrong, not in enums {}", valueDistri, ValueSizeDistriEnum.values());
    }
    // 次数
    Integer count = MapUtils.getInteger(map, ClientReportConstant.VALUE_COUNT, 0);
    // 命令
    String command = MapUtils.getString(map, ClientReportConstant.VALUE_COMMAND, "");
    if (StringUtils.isBlank(command)) {
        logger.warn("command is empty!");
        return null;
    }
    if (excludeCommands.contains(command)) {
        return null;
    }
    // 实例host:port
    String hostPort = MapUtils.getString(map, ClientReportConstant.VALUE_HOST_PORT, "");
    if (StringUtils.isEmpty(hostPort)) {
        logger.warn("hostPort is empty", hostPort);
        return null;
    }
    int index = hostPort.indexOf(":");
    if (index <= 0) {
        logger.warn("hostPort {} format is wrong", hostPort);
        return null;
    }
    String host = hostPort.substring(0, index);
    int port = NumberUtils.toInt(hostPort.substring(index + 1));
    // 实例信息
    InstanceInfo instanceInfo = clientReportInstanceService.getInstanceInfoByHostPort(host, port);
    if (instanceInfo == null) {
        // host, port);
        return null;
    }
    AppClientValueDistriStatTotal stat = new AppClientValueDistriStatTotal();
    stat.setAppId(instanceInfo.getAppId());
    stat.setCollectTime(collectTime);
    stat.setUpdateTime(new Date());
    stat.setCommand(command);
    stat.setDistributeType(valueSizeDistriEnum.getType());
    stat.setCount(count);
    return stat;
}
Also used : ValueSizeDistriEnum(com.sohu.tv.jedis.stat.enums.ValueSizeDistriEnum) InstanceInfo(com.sohu.cache.entity.InstanceInfo) AppClientValueDistriStatTotal(com.sohu.cache.entity.AppClientValueDistriStatTotal) Date(java.util.Date)

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