如何为 splunk timechart 命令添加总计和百分比列

How to add total and percentage column for splunk timechart command

用一个简单的例子:统计每个主机名的事件数

... |按主机计算的时间表

> ... | timechart count BY host
> 
> This search produces this results table:
> 
> _time         host1   host2   host3   
> 
> 2018-07-05    1038    27      7      
> 2018-07-06    4981    111     35      
> 2018-07-07    5123    99      45       
> 2018-07-08    5016    112     22    

我想要的是添加一个列来显示当天的总事件以及每个http状态代码的百分比。

我试过了

 ... | timechart count BY host
| eval total= host1 + host2 + host3
| eval host1_percent = host1 / total
| eval host2_percent = host2 / total
| eval host3_percent = host3 / total
| table _time, host1_percent, host2_percent, host3_percent

这在大多数情况下都有效,但我发现如果某天主机离线(没有特定主机的记录),则搜索不起作用(return 空白结果) ,我必须从“total = host1 + host2 + host3”中删除那个特定的主机才能让它工作。

所以我的问题是:有没有办法获取每天(行)的记录总数,而不必将它们加在一起,例如用计数或总和替换“total = host1 + host2 + host3”,我尝试了一些,none 其中有效。

了解您到目前为止尝试过的内容会有所帮助,因此我们不会推荐相同的内容。

你试过了吗addtotals

| timechart count by host
| addtotals row=true fieldname=total host*