Search in sources :

Example 1 with ValueLengthModel

use of com.sohu.tv.jedis.stat.model.ValueLengthModel in project cachecloud by sohutv.

the class ClientDataCollectReportExecutor method collectReportValueDistriData.

/**
     * 收集值分布
     * 
     * @param lastMinute
     */
private List<Map<String, Object>> collectReportValueDistriData(String lastMinute) {
    try {
        // 1. 只取当前时间前一分钟的的数据
        Map<ValueLengthModel, Long> jedisValueLengthMap = UsefulDataCollector.getValueLengthLastMinute(lastMinute);
        if (jedisValueLengthMap == null || jedisValueLengthMap.isEmpty()) {
            return Collections.emptyList();
        }
        // 2.解析拼接数据
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        for (Entry<ValueLengthModel, Long> entry : jedisValueLengthMap.entrySet()) {
            ValueLengthModel model = entry.getKey();
            Long count = entry.getValue();
            Map<String, Object> tempMap = new HashMap<String, Object>();
            tempMap.put(ClientReportConstant.VALUE_DISTRI, model.getRedisValueSizeEnum().getValue());
            tempMap.put(ClientReportConstant.VALUE_COUNT, count);
            tempMap.put(ClientReportConstant.VALUE_COMMAND, model.getCommand());
            tempMap.put(ClientReportConstant.VALUE_HOST_PORT, model.getHostPort());
            tempMap.put(ClientReportConstant.CLIENT_DATA_TYPE, ClientCollectDataTypeEnum.VALUE_LENGTH_DISTRI_TYPE.getValue());
            list.add(tempMap);
        }
        return list;
    } catch (Exception e) {
        UsefulDataCollector.collectException(e, "", System.currentTimeMillis(), ClientExceptionType.CLIENT_EXCEPTION_TYPE);
        logger.error("collectReportValueDistriData:" + e.getMessage(), e);
        return Collections.emptyList();
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ValueLengthModel(com.sohu.tv.jedis.stat.model.ValueLengthModel) HashMap(java.util.HashMap) Map(java.util.Map) AtomicLongMap(com.sohu.tv.jedis.stat.utils.AtomicLongMap) ParseException(java.text.ParseException)

Example 2 with ValueLengthModel

use of com.sohu.tv.jedis.stat.model.ValueLengthModel 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

ValueLengthModel (com.sohu.tv.jedis.stat.model.ValueLengthModel)2 ValueSizeDistriEnum (com.sohu.tv.jedis.stat.enums.ValueSizeDistriEnum)1 CostTimeDetailStatKey (com.sohu.tv.jedis.stat.model.CostTimeDetailStatKey)1 AtomicLongMap (com.sohu.tv.jedis.stat.utils.AtomicLongMap)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1