首页 > 解决方案 > 如果今天的日志量比过去三天每项服务的平均值高 10%,则 Splunk 发出警报

问题描述

我想创建一个警报,当今天的日志数量比过去三天每个服务的平均值多 10% 时触发。

对于一项特定的服务,我接下来可以使用

index="some-index" AND "ctx.endpointname"="service-name" earliest=-3d@d |
timechart span=1d count |
timewrap d series=short |
eval threshold=(((s1+s2+s3)/3)+(((s1+s2+s3)/3)*0.1))'

但是当我添加by ctx.endpointname

index="some-index" AND "ctx.endpointname"=* earliest=-3d@d |
timechart span=1d count by ctx.endpointname|
timewrap d series=short |
eval threshold=(((s1+s2+s3)/3)+(((s1+s2+s3)/3)*0.1))'

结果字段名称:

service-name_s0
service-name_s1
service-name_s2
service-name_s3

而且我无法计算阈值,因为我不知道如何为每个服务引用此字段

标签: splunksplunk-query

解决方案


index="some-index" AND "ctx.endpointname"="service-name" 最早=-3d@d 最新=@d | 添加信息 | eval orig_time = strftime(_time, "%H:%M:%S")| 评估 min_time = info_min_time | 桶跨度=1440m info_min_time | 评估偏移量 = min_time - info_min_time | eval _time=_time-offset| 铲斗跨度=1440m _time | eval _time=_time+offset | eval min_time = strftime(min_time, "%H:%M:%S") | eval info_min_time = strftime(info_min_time, "%H:%M:%S")| 桶_时间跨度=1440m | 统计数据按 _time| 计为 current_count| 自动回归 current_count 作为 previous_count | eval total_count=(current_count+previous_count)|streamstats 计为行| 评估更改=(当前计数-先前计数)| eval ChangePercent=(change/total_count)*100 |fields _time, current_count, previous_count, change, ChangePercent, 行 | 其中 current_count>x AND ChangePercent>10 AND row=2

请使用上述查询并更改当前计数,您将获得所需的结果。


推荐阅读