一、内存报表数据结构
TransactionReport报表的数据结构如下:
CrossReport内存报表数据结构
数据示例:
<?xml version="1.0" encoding="utf-8"?>
<cross-report domain="monitor-cat" startTime="2017-12-28 18:00:00" endTime="2017-12-28 18:59:59">
<domain>monitor-cat</domain>
<domain>monitor-dubbo</domain>
<ip>10.15.83.181</ip>
<local id="10.15.83.181">
<remote id="10.15.83.181(monitor-cat):Pigeon.Client" role="Pigeon.Client" app="monitor-cat" ip="10.15.83.181(monitor-cat)">
<type id="PigeonService" totalCount="19" failCount="0" failPercent="0.00" avg="0.00" sum="28.89" tps="0.00">
<name id="DubboProviderService.getProviderServiceName" totalCount="19" failCount="0" failPercent="0.00" avg="0.00" sum="28.89" tps="0.00"/>
</type>
</remote>
<remote id="10.15.83.181(monitor-dubbo):Pigeon.Server" role="Pigeon.Server" app="monitor-dubbo" ip="10.15.83.181(monitor-dubbo)">
<type id="PigeonCall" totalCount="19" failCount="0" failPercent="0.00" avg="0.00" sum="461.26" tps="0.00">
<name id="DubboProviderService.getProviderServiceName" totalCount="19" failCount="0" failPercent="0.00" avg="0.00" sum="461.26" tps="0.00"/>
</type>
</remote>
</local>
</cross-report>
二、计算公式
2.1 95线、99线
详见:
com.dianping.cat.consumer.transaction.TransactionStatisticsComputer.computeLineValue(Map<Integer, AllDuration>, double)
/**
* 统计95线,99.9线。
* 思路:
* 求请求的总数,假设是100,求线余下的数目,如果是95线,那余下是5,
* 将之前统计的durations放进treeMap里面,倒序
* 从前向后遍历,找到第5个元素,拿到对应的值
*
* 基本上是按照95线的定义来取数的
* @param durations
* @param percent
* @return
*/
private double computeLineValue(Map<Integer, AllDuration> durations, double percent) {
int totalCount = 0;
Map<Integer, AllDuration> sorted = new TreeMap<Integer, AllDuration>(TransactionComparator.DESC);
sorted.putAll(durations);
for (AllDuration duration : durations.values()) {
totalCount += duration.getCount();
}
int remaining = (int) (totalCount * (100 - percent) / 100);
for (Entry<Integer, AllDuration> entry : sorted.entrySet()) {
remaining -= entry.getValue().getCount();
if (remaining <= 0) {
return entry.getKey();
}
}
return 0.0;
}
2.2 方差
位置:
com.dianping.cat.consumer.transaction.TransactionStatisticsComputer.std(long, double, double, double)
/**
* sum2 = sum2 + sum;
* 求方差 value = sum2/count - 均值*均值
* value = 开方(value)
*
*
* @param count
* @param avg
* @param sum2
* @param max
* @return
*/
double std(long count, double avg, double sum2, double max) {
double value = sum2 / count - avg * avg;
if (value <= 0 || count <= 1) {
return 0;
} else if (count == 2) {
return max - avg;
} else {
return Math.sqrt(value);
}
}