contact@yottabyte.cn
400-085-0159
调查问卷
J

SPL

stats

stats提供统计功能,可以根据设定字段进行group操作。

命令行格式:

stats stats_function(field) [as field] [by field_list]

field可以是event中已经提取的字段,也可以是eval命令生成的新字段。

比如:eval c=a+b stats avg(c)

目前支持的函数为:

函数名 使用方法&含义 返回值
sum sum(apache.status)
参数只有一个,可以是已经解析的field,也可以是eval生成的新字段,field必须是数值型

统计field对应值的累加和
"sum(apache.status)":{
"as\_field":"",
"value":2.0057305165E10
}
如果设置了as\_field,返回值里就不在为空,比如命令行为“sum(apache.status) as sum_of\_status",返回值中会将as\_field设置为sum\_of\_status
min 使用方法同上

统计field对应值的最小值
同上
max 使用方法同上

统计field对应值的最大值
同上
avg 使用方法同上

统计field对应值的平均值
同上
count 使用方法同上

统计field的出现次数
同上
distinct\_count or dc 使用方法同上

统计field对应值去重之后的个数
同上
extend\_stat or es 使用方法同上

一次性计算出基于field的avg/count/max/min/sum/std\_deviation/variance/sum\_of\_squares值
"extended\_stat(apache.status)":{
"as\_field":"",
"avg":226.76832896353707,
"count":88448441,
"max":502,
"min":200,
"std\_deviation":68.74379972321682,
"sum":2.0057305165E10,
"sum\_of\_squares":4.966343257931E12,
"variance":4725.710000385745
}
top top(field, count)
field: 待统计的字段
count:返回个数

统计field内最多出现的若干个值
"top(apache.status)":{
    "as\_field":"top\_status",
    "buckets":[{
        "doc\_count":79473063,
        "key":"200"
     }, {
       "doc\_count":10397265,
       "key":"405"
     }],
   "total":91796729
}}]
histogram or hg hg(field, interval)
field: 待统计字段,必须为数值型
interval: 直方图间隔

直方图统计
"histogram(apache.status)":{
"as\_field":"",
"buckets":[
{
"doc\_count":80274444,
"key":200
},
{
"doc\_count":11522285,
"key":400
}
],
"interval":200
},
date\_histogram or dhg dhg(field, interval)
field: 待统计字段,数值当做以毫秒为单位的时间戳
interval: 时间间隔,描述方式如1m, 1d... 后缀有以下几种:y|M|w|d|h|m|s

时间直方图统计,可以认为是直方图统计的一种特殊形式
同上
range\_bucket or rb rb(field, (start, end), (start,end), ....)
field: 待统计字段,数值型
(start,end): 待统计区间,可以设置多个统计区间

区间统计
"range(apache.status)":{
    "as\_field":"",
    "buckets":[{
        "doc\_count":400,
        "from":205,
        "key":"205.0-302.0",
        "to":302
    },{
        "doc\_count":2450465,
        "from":402,
        "key":"402.0-500.0",
        "to":500
    }]}
pct pct(field, value1, value2...)
field: 待统计字段,必须是数值型

统计百分位为value1,value2时所对应的field值
"percentiles(apache.status)":{
"as\_field":"",
"values":{
"10.0":200,
"20.0":200,
"30.0":200
}
}
百分位为10%时,对应的值为200
管道命令样例:
* | stats pct(apache.status,1,5,25,50,75,95,99)
pct\_ranks pct\_ranks(field, value1, value2,....)

百分位统计,统计value值在整个field数值区间中的百分位
"percentile\_ranks(apache.status)":{
"as\_field":"",
"values":{
"249.0":86.57802705984146,
"308.0":87.20943559126225,
"401.0":88.03192145410496
}
}
管道命令样例:
* | stats pct\_ranks(apache.status,199,200,302,500)

例如使用以下语句搜索

   * | stats es(apache.status)

会得到以下统计数据:

通过表格可以看到apache.status的计数、最大值、最小值、求和、平均值、方差、平方和标准偏差。