chart
命令对数据进行聚合统计,比如平均数、计数与总和。与stats命令不同的是,chart命令支持多个分组字段。第一个分组字段<row-split-field>
对数据进行行分组,将分组字段的每一个值显示在单独的行上。第二个及之后的分组字段<column-split-field>
对数据进行列分组,分组字段的每个值成为列标签,效果如下。
语法:
chart [<chart-options>] <stats-func>... [ BY <row-split>, <column-split> ] | [ OVER <row-split> ] [BY <column-split>]
参数说明:
chart-options
:limit=<N>
: 可选, 限制返回列的数量,超出限制的列显示为other列标签。limit默认值为10,limit值为0的时候表示无限制。当有<where-clause>
时,limit 参数无效。
stats-func
: 必填,统计函数,详见链接。row-split
:<field> [<bin-options>]
<field>
: 行分组字段。<bin-options>
: 可选,分桶选项。bins=<N>
:可选,分桶数量,默认100。span=<N>
:可选,分桶的时间间隔,可为时间单位字符串或者正整数。例如 1s,1m,1h,支持毫秒(ms),秒(s),分钟(m),小时(h),天(d),周(w),月(M),季度(q),年(y),当span为正整数时,其单位为毫秒。align=<true|false>
: 可选,与bins搭配使用,表示是否将桶值对齐到数值5的倍数,默认值为false。
column-split
:<field> [<bin-options>] [<field>...] [useother=<BOOL>] [<where-clause>]
<field> [bin-option]
<field>
: 单个列分组字段。<bin-options>
: 可选,分桶选项,只对第一个列分组字段可用。
<field>...
: 多个列分组字段。useother=<BOOL>
: 可选,是否需要 OTHER 列,默认为 true。<where-clause>
: 用于筛选哪些列需要用于展示, 语法:where <stats-func> <where-comp>
<stats-func>
: 统计函数.<where-comp>
:<wherein-comp> | <wherethresh-comp>
<wherein-comp>
:(in | notin) (top | bottom)<int>
<wherethresh-comp>
:( < | > ) <num>
用法示例:
显示每个“主机”和“用户”之间的最大“延迟”。
... | chart max(delay) by host, user
这个写法等价于
... | chart max(delay) over host by user
如果要限制 user 的显示数量,可以使用 limit 参数, 它会选出 top 5 的指标, 其他将归类到 OTHER 列中。
... | chart limit=5 max(delay) over host by user
按时间分组统计:
... | chart count() over _time span=1d by user
... | chart count() over _time span=1d by date_hour span=12
多个列字段:
... | chart count() over f1 by sourcetype, origin
where-clase 示例:
选出和最大的 5 个列:
... | chart count() over _time span=1d by f1 where sum in top5
... | chart count() over _time span=1d by f1 useother=false where sum in top5
选出最小值大于 0 的所有列:
... | chart count() over _time span=1d by f1 where min > 0
文档反馈
(如有产品使用问题,请 提交工单)