【问题标题】:Splunk :find percentage of top 1000 in splunkSplunk : 在 splunk 中查找前 1000 名的百分比
【发布时间】:2021-01-29 17:13:42
【问题描述】:

我们如何获得前 1000 个值的百分比以及更多字段.. 我在下面尝试过,但它不起作用..

|评估百分比=round(count/total*100,1000) | eventstats count(src) 总计 | iplocation src|按 src 、 dest 、 msg 、 Server_Group、Country、percent 统计的统计数据 |排序计数 |头 1000

【问题讨论】:

  • “它不工作”是什么意思?请提供预期结果和实际结果。还有,“前1000”是什么? Splunk 使用整数数学,因此您可以使用eval count*100/total 获得更准确的结果。 round 函数的第二个参数是小数位数,所以2 可能比1000 更有意义。 eval 命令适用于单个事件,这意味着示例查询正在计算 1000 个百分比。并不是说这有什么问题,但这可能不是本意。
  • 我们有以下查询 index=abc| iplocation src_IP|统计数据按 src ,国家 |排序计数 | head 1000 输出低于攻击源 国家计数 50.17.98.189 爱尔兰 9602 159.89.48.18 加拿大 2200 221.151.26.232 大韩民国 1437 84.39.116.10 英国 1372 我想要记录总数为 1000 的平均计数(我已经给出了示例仅以上 4 个)

标签: splunk splunk-query splunk-calculation


【解决方案1】:

这个随处运行的查询应该可以帮助您入门。

| makeresults 
| eval _raw="Source of attack Country           count
50.17.98.189   Ireland             9602 
159.89.48.18   Canada              2200 
221.151.26.232 Republic of Korea 1437 
84.39.116.10   United Kingdom      1372
" 
| multikv 
```Above just sets up test data```
| sort - count 
```Add average and total fields to the results```
| appendpipe 
    [ stats avg(count) as Avg, sum(count) as Total ] 
```Put the Total field on top so the filldown command works```
|  reverse
```Put the Total field in every event```
| filldown Total 
```Calculate the percentage for each source
| eval pct=round(count*100/Total,2)
```Restore the original order```
| reverse
```Remove unneeded field```
| fields - Total

这是您的查询与我的结合

index=abc
| iplocation src_IP
| stats count by src ,Country 
| sort - count 
| head 1000
| appendpipe 
    [ stats avg(count) as Avg, sum(count) as Total ] 
| reverse
| filldown Total 
| eval pct=round(count*100/Total,2)
| reverse
| fields - Total

【讨论】:

  • sry 它有点令人困惑.. 你能帮忙准确查询吗
  • 我更新了我的答案以包含一个扩展您的查询。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多