是否可以在 splunk 中应用动态条件阈值
例如 我有一个服务helloworld它包含多个端点,为了这个例子
helloworld/greeting
和helloworld/process
门槛是这样的
endpoint,90thPercentile(millisec),95thPercentile(millisec)
helloworld/greeting,20,50
helloworld/process,50,100
Output
endpoint,datetime,execution(millisec),p90(breached/notbreached),p95(breached/notbreached)
helloworld/greeting,04/23/23,8:00:000,25,breached,notbreached
helloworld/greeting,04/23/23,8:05:000,12,notbreached,notbreached
helloworld/process,04/23/23,8:00:000,125,breached,breached
helloworld/process,04/23/23,8:00:000,25,notbreached,notbreached
Query
...
...
|eval "90"=case(execution>90thPercentile(OF A SPECIFIC ENDPOINT FOR A TOKEN),"breach",1=1,"notbreached"),"95"=case(execution>95thPercentile(OF A SPECIFIC ENDPOINT FOR A TOKEN),"breach",1=1,"notbreached"),
我可以轻松创建硬编码的通用 90thPercentile、95thPercentile 令牌,但这些令牌对于所有端点都是相同的,相反,我希望通过查看阈值配置或令牌变量来为每个端点应用阈值
希望我说得有道理,我已经精疲力尽了我的研究,看起来我需要为每个端点硬编码一个面板,并在 eval 案例陈述中硬编码第 90/95%Percentile
动态处理此类查询的最佳方法是使用 Splunk 查找功能
查找可以帮助您将阈值保存在 Splunk 服务器中的 CSV 文件中,并在您的 SPL 查询中引用它。 它通常用于用静态数据丰富您的 Splunk 事件,并将它们用于应用计算
1/ 在 Lookup 中保存您的阈值文件
--> 参见 查找文档
2/ 使用
lookup
命令来丰富您的索引事件
--> 参见 lookup 命令文档
3/ 使用新创建的字段来处理所有类型的端点
您的 SPL 查询将如下所示:
<your base search>
| lookup thresholds.csv endpoint
|eval p90=if(perc90(execution)>90thPercentile(millisec),"breach","notbreached"),
p95=if(perc95(execution)>95thPercentile(millisec),"breach","notbreached")
希望对您有所帮助!