1

我真的可以使用持续警报来捕捉某个错误代码(例如 404 或 502 等)的突然上升(峰值) . 我真的可以在脚本上使用你的帮助:-)

据我了解,搜索查询应该“知道”或“感知”正常流量(不确定多长时间,可能是 1 小时、2 小时),并在错误代码与 1-2 小时前相比出现峰值时发出警报。我认为错误代码峰值阈值应该超过总流量的 5%,同时发生时间超过 90 秒。

这是我今天使用的 Splunk 查询,感谢您帮助将其调整为我上面描述的内容:

tag=NginxLogs host=www1 OR host=www2 |stats count by status|eventstats sum(count) as total|eval perc=round((count/total)*100,2)|where status="404" AND perc>5
4

1 回答 1

0

top 命令自动提供计数和百分比。 http://docs.splunk.com/Documentation/Splunk/7.1.2/SearchReference/Top

tag=NginxLogs host=www1 OR host=www2  
| top status
| search percent > 5 AND status > 399

如果您的 splunk 日志中有 url、http 请求方法和用户,您可以将其添加为此警报的一部分。例子:

tag=NginxLogs host=www1 OR host=www2  
| eventstats distinct_count(userid) as NoOfUsersAffected by requestUri,status,httpmethod
| top status,httpmethod,NoOfUsersAffected by requestUri
| search NoOfUsersAffected > 2 AND ((status>499 AND percentage > 5) OR (StatusCode=400 AND percentage > 95))

您可以使用以下警报消息:

$result.percent$ % ($result.count$ calls) has StatusCode $result.status$  for 
$result.requestUri$ - $result.httpmethod$.
$result.NoOfUsersAffected$ users were affected

您将收到如下警报:

21.19 % (850 calls) has StatusCode 500  for https://app.test.com/hello - GET.
90 users are affected
于 2018-08-08T20:57:18.747 回答