Search in sources :

Example 1 with ValueSizeDistriEnum

use of com.sohu.tv.jedis.stat.enums.ValueSizeDistriEnum 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)

Example 2 with ValueSizeDistriEnum

use of com.sohu.tv.jedis.stat.enums.ValueSizeDistriEnum in project cachecloud by sohutv.

the class UsefulDataCollector method collectCostAndValueDistribute.

/**
     * 收集耗时和值分布
     * 
     * @param costModel
     */
public static void collectCostAndValueDistribute(UsefulDataModel costModel) {
    Long start = System.currentTimeMillis();
    try {
        // 基础数据
        String currentMinute = ClientReportConstant.getCollectTimeSDf().format(new Date());
        int cost = (int) costModel.getCost();
        String command = costModel.getCommand();
        String hostPort = costModel.getHostPort();
        int valueBytesLength = costModel.getValueBytesLength();
        // 耗时详细统计
        CostTimeDetailStatKey costTimeDetailStatKey = new CostTimeDetailStatKey(currentMinute, command, hostPort);
        if (DATA_COST_TIME_MAP_ALL.containsKey(costTimeDetailStatKey)) {
            AtomicLongMap<Integer> stat = DATA_COST_TIME_MAP_ALL.get(costTimeDetailStatKey);
            stat.getAndIncrement(cost);
        } else {
            AtomicLongMap<Integer> stat = AtomicLongMap.create();
            stat.getAndIncrement(cost);
            AtomicLongMap<Integer> currentStat = DATA_COST_TIME_MAP_ALL.putIfAbsent(costTimeDetailStatKey, stat);
            if (currentStat != null) {
                currentStat.getAndIncrement(cost);
            }
        }
        // 值分布
        ValueSizeDistriEnum redisValueSizeEnum = ValueSizeDistriEnum.getRightSizeBetween(valueBytesLength);
        if (redisValueSizeEnum != null) {
            ValueLengthModel valueLengthModel = new ValueLengthModel(redisValueSizeEnum, costModel.getCommand(), costModel.getHostPort());
            if (DATA_VALUE_LENGTH_DISTRIBUTE_MAP_ALL.containsKey(currentMinute)) {
                DATA_VALUE_LENGTH_DISTRIBUTE_MAP_ALL.get(currentMinute).getAndIncrement(valueLengthModel);
            } else {
                AtomicLongMap<ValueLengthModel> dataValueLengthMap = AtomicLongMap.create();
                dataValueLengthMap.getAndIncrement(valueLengthModel);
                AtomicLongMap<ValueLengthModel> currentDataValueLengthMap = DATA_VALUE_LENGTH_DISTRIBUTE_MAP_ALL.putIfAbsent(currentMinute, dataValueLengthMap);
                if (currentDataValueLengthMap != null) {
                    currentDataValueLengthMap.getAndIncrement(valueLengthModel);
                }
            }
        }
        // 统计收集这件事本身的耗时
        Long collectCostTime = System.currentTimeMillis() - start;
        if (COLLECTION_COST_TIME_MAP_ALL.containsKey(currentMinute)) {
            AtomicLongMap<Long> stat = COLLECTION_COST_TIME_MAP_ALL.get(currentMinute);
            stat.getAndIncrement(collectCostTime);
        } else {
            AtomicLongMap<Long> stat = AtomicLongMap.create();
            stat.getAndIncrement(collectCostTime);
            AtomicLongMap<Long> currentStat = COLLECTION_COST_TIME_MAP_ALL.putIfAbsent(currentMinute, stat);
            if (currentStat != null) {
                currentStat.getAndIncrement(collectCostTime);
            }
        }
    } catch (Exception e) {
        logger.error("collect data error: " + e.getMessage());
    }
}
Also used : ValueSizeDistriEnum(com.sohu.tv.jedis.stat.enums.ValueSizeDistriEnum) CostTimeDetailStatKey(com.sohu.tv.jedis.stat.model.CostTimeDetailStatKey) ValueLengthModel(com.sohu.tv.jedis.stat.model.ValueLengthModel) Date(java.util.Date)

Aggregations

ValueSizeDistriEnum (com.sohu.tv.jedis.stat.enums.ValueSizeDistriEnum)2 Date (java.util.Date)2 AppClientValueDistriStatTotal (com.sohu.cache.entity.AppClientValueDistriStatTotal)1 InstanceInfo (com.sohu.cache.entity.InstanceInfo)1 CostTimeDetailStatKey (com.sohu.tv.jedis.stat.model.CostTimeDetailStatKey)1 ValueLengthModel (com.sohu.tv.jedis.stat.model.ValueLengthModel)1