use of com.sohu.tv.jedis.stat.model.CostTimeDetailStatKey in project cachecloud by sohutv.
the class ClientDataCollectReportExecutor method collectReportCostTimeData.
/**
* 收集耗时
*
* @param lastMinute
*/
private List<Map<String, Object>> collectReportCostTimeData(String lastMinute) {
try {
//1. 收集数据
Map<CostTimeDetailStatKey, AtomicLongMap<Integer>> map = UsefulDataCollector.getCostTimeLastMinute(lastMinute);
if (map == null || map.isEmpty()) {
return Collections.emptyList();
}
// 2. 组装数据
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
for (Entry<CostTimeDetailStatKey, AtomicLongMap<Integer>> entry : map.entrySet()) {
CostTimeDetailStatKey costTimeDetailStatKey = entry.getKey();
AtomicLongMap<Integer> statMap = entry.getValue();
CostTimeDetailStatModel model = UsefulDataCollector.generateCostTimeDetailStatKey(statMap);
Map<String, Object> tempMap = new HashMap<String, Object>();
tempMap.put(ClientReportConstant.COST_COUNT, model.getTotalCount());
tempMap.put(ClientReportConstant.COST_COMMAND, costTimeDetailStatKey.getCommand());
tempMap.put(ClientReportConstant.COST_HOST_PORT, costTimeDetailStatKey.getHostPort());
tempMap.put(ClientReportConstant.COST_TIME_90_MAX, model.getNinetyPercentMax());
tempMap.put(ClientReportConstant.COST_TIME_99_MAX, model.getNinetyNinePercentMax());
tempMap.put(ClientReportConstant.COST_TIME_100_MAX, model.getHundredMax());
tempMap.put(ClientReportConstant.COST_TIME_MEAN, model.getMean());
tempMap.put(ClientReportConstant.COST_TIME_MEDIAN, model.getMedian());
tempMap.put(ClientReportConstant.CLIENT_DATA_TYPE, ClientCollectDataTypeEnum.COST_TIME_DISTRI_TYPE.getValue());
list.add(tempMap);
}
return list;
} catch (Exception e) {
UsefulDataCollector.collectException(e, "", System.currentTimeMillis(), ClientExceptionType.CLIENT_EXCEPTION_TYPE);
logger.error("collectReportCostTimeData:" + e.getMessage(), e);
return Collections.emptyList();
}
}
use of com.sohu.tv.jedis.stat.model.CostTimeDetailStatKey in project cachecloud by sohutv.
the class CachecloudDataWatcher method getCostTimeMap.
@Override
public Map<String, Map<Integer, Long>> getCostTimeMap() {
Map<CostTimeDetailStatKey, AtomicLongMap<Integer>> map = UsefulDataCollector.getDataCostTimeMapAll();
if (map == null || map.isEmpty()) {
return Collections.emptyMap();
}
Map<String, Map<Integer, Long>> result = new HashMap<String, Map<Integer, Long>>();
for (Entry<CostTimeDetailStatKey, AtomicLongMap<Integer>> entry : map.entrySet()) {
CostTimeDetailStatKey costTimeDetailStatKey = entry.getKey();
String key = costTimeDetailStatKey.getUiqueKey();
result.put(key, entry.getValue().asMap());
}
return result;
}
use of com.sohu.tv.jedis.stat.model.CostTimeDetailStatKey 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());
}
}
Aggregations