Splunk命令检查当前搜索是否大于先前搜索的x%

问题描述

我想知道如何在Splunk中编写搜索查询,以检查当前搜索是否大于先前搜索的20%。我每10分钟就会收到特定次数的事件。我想检查当前计数(最近10分钟)是否大于先前计数(最近20分钟)的20%。我需要使用子搜索进行比较。但没有得到结果。有人可以帮忙吗?

解决方法

我建议将搜索结果保存到摘要索引中。然后,您可以单独搜索摘要索引,以查找结果为先前结果的120%的实例。

要将搜索结果保存到摘要索引中,请将| collect <summary>添加到现有搜索中。 <summary>是将接收搜索结果的现有索引的名称。

将要处理摘要的搜索可以使用streamstats命令来处理事件。

index=summary 
`comment("Change 'head' to 'tail' if the events are in reverse order")`
| head 2
`comment("Get the difference between the current value and the previous one")`
| streamstats range(foo) as diff
`comment("We don't know the previous value of foo so we need to work 'backward' to see if the current value is too big")`
| where (foo - diff) > (foo * 0.833)