如何在 Splunk 中应用多重加法

问题描述

嗨,有来自以下查询的以下数据.. (index=abc OR index=def) |rex field=index "(?[^cita]\w.*?)_" |按阻塞的图表计数,Local_Market

被阻止的配音老鼠米尔 0 10 20 21 1 02 03 09 2 9 2 1

现在我想要的数据如下

总阻塞(sumof 0 and sumof 2)dub rat mil total found(Sumof 1) (10+20+21+9+2+1)=63 10 20 21 (02+03+09)=14

解决方法

问题可以更好地格式化,但我认为您想要的是 addcoltotals 命令。

,

这个随处运行的例子很难看,但我相信它会产生预期的结果。

| makeresults 
| eval _raw="blocked dub rat mil
0       10  20  21
1       02  03  09
2       9   2   1"
| multikv forceheader=1
| fields - _time _raw linecount
```Skip the above - it just creates test data```
```Compute the total_bolocked field for blocked=0 and blocked=2```
| eval total_bolocked=if(blocked!=1,dub+mil+rat,0)
```Compute the total_found field for blocked=1```
| eval total_found=if(blocked=1,0)
```Add up the total_bolocked fields.  This will include blocked=1,but we'll fix that below```
| eventstats sum(total_bolocked) as total_bolocked
```Set total_bolocked=0 if blocked is 1```
| eval total_bolocked=if(blocked=1,total_bolocked)