avg
、geometric_mean
等,直接以样本统计结果代表真实值。count(*)
、sum
、count_if
等,以样本统计结果除以采样率代表真实值。例如,按照1:10,000的采样率统计接口 pv(count(*)
),样本统计结果为232,则真实值约为232 / (1:10000) = 2320000。* | select count(*)/(1.0/10000) as pv,avg(response_time) as response_time_avg
count(*)
为统计日志条数,属于和值计算,需以样本统计结果除以采样率代表真实值。其中,(1.0/10000)
即为采样率,计算获得的 pv 为真实 pv 的估算值。avg(response_time)
为计算响应时间response_time
的平均值,属于平均值计算,可直接作为真实 response_time_avg 的估算值。* | select avg(response_time) as x,count(response_time) as n,stddev_samp(response_time) as s
avg(response_time)
的真实值位于[541.75,547.18]内,而实际上该案例通过精确统计得到的avg(response_time)
为545.16,估算值非常接近真实值。* | select avg(response_time) as response_time,count(*) as sampleCount,url group by url order by count(*) desc
url | response_time | sampleCount |
/user | 45.23 | 7845 |
/user/list | 78.45 | 6574 |
/user/login | 45.85 | 5235 |
/user/logout | 45.48 | 1245 |
/book/new | 125.78 | 987 |
/book/list | 17.23 | 658 |
/book/col | 10.21 | 23 |
/order | 12.13 | 2 |
/book/col
和/order
两个 url 的样本数过低,统计结果准确度较低,不具备参考性。如需对这两个 url 获取更加准确的统计结果,可提高整体的采样率,或单独对其进行统计分析。例如:url:"/book/col" OR url:"/order" | select avg(response_time) as response_time,count(*) as sampleCount,url group by url order by count(*) desc
本页内容是否解决了您的问题?