首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何根据失败率对日志字段进行告警?

如何根据失败率对日志字段进行告警?
EN

Stack Overflow用户
提问于 2019-06-04 15:26:33
回答 1查看 302关注 0票数 2

我在sumologic上做了日志记录。日志JSON包含请求的响应时间。假设它是一个名称为"response_time“的JSON key。每个请求由唯一的ID标识,由JSON键"request_id“表示。以及由JSON键" URL“表示的url。基于以下情况,我需要在空闲通道上发出警报。

1)在10分钟的窗口中,如果有100个请求,并且超过5%的请求的响应时间超过100ms,则警告所有这些请求的url、request_id和response_time。2)如果小于或等于5%的请求响应时间超过100ms,则完全不报警。我写了一个这样的查询。

代码语言:javascript
复制
_sourceName=<my_source_name> 
| json field=_raw "response_time" as response_time 
| json field=_raw "request_id" as request_id 
| if (num(response_time) > 100, 1, 0) as higher 
| if (num(response_time) <= 100, 1, 0) as lower 
| count as total_requests, sum(higher) as 
response_time_greater_than_100, sum(lower) as 
response_time_less_than_100 
| (response_time_greater_than_100/total_requests) as failure_ratio 
| where (failure_ratio > 0.05)

当超过5%的请求的response_time超过100ms时,上面的查询会给出所有的请求。但它给了我所有的请求,而不考虑响应时间。否则不会返回任何结果。

除了这个结果,我还想用"response_time“>100ms的请求进一步过滤上面的查询。只要有结果,它就会给出两个选项卡。一个用于“消息”,另一个用于“聚集”。我想要将“Messages”选项卡中的字段发送到一个空闲通道。如何做到这一点?

EN

回答 1

Stack Overflow用户

发布于 2019-06-04 19:05:19

选项卡-聚合与消息

首先,让我们澄清这两个选项卡。第一个(消息)包含产生结果的所有这些原始日志行。第二个(Aggregates)是使用分组进行实际查询的结果。注意,您使用的是| count,它是一个分组操作符(类似于SQL中的GROUP BY )。

任何传出的交互总是基于查询的实际结果(聚合)。原始线条仅在用于检查的用户界面中可见(在API中也可见)。

实际查询

如果您只想获取响应时间>100所有请求,那么使用这样的查询就足够了:

代码语言:javascript
复制
_sourceName=<my_source_name> 
| json field=_raw "response_time" as response_time 
| json field=_raw "request_id" as request_id 
| where response_time > 100

声明式地说,我知道你想要一些不同的东西:获取所有超过100的响应,但只有当超过100的请求占总请求的5%以上时,否则就是一个空的结果集。

代码语言:javascript
复制
_sourceName=<my_source_name> 
| 1 as expected_failure_ratio_violation
| where [subquery:
  _sourceName=<my_source_name> 
  | json field=_raw "response_time" as response_time 
  | json field=_raw "request_id" as request_id
  | if (num(response_time) > 100, 1, 0) as higher 
  | if (num(response_time) <= 100, 1, 0) as lower 
  | count as total_requests, sum(higher) as response_time_greater_than_100, 
    sum(lower) as response_time_less_than_100 
  | (response_time_greater_than_100/total_requests) as failure_ratio 
  | where (failure_ratio > 0.05)
  | count as expected_failure_ratio_violation 
  | compose expected_failure_ratio_violation        
]
| json field=_raw "response_time" as response_time 
| json field=_raw "request_id" as request_id
| where response_time > 100

它使用了一个技巧,将(一个常量) 1与子查询中的违规计数(expected_failure_ratio_violation)进行匹配。

另外,作为提示-您在这里没有使用| timeslice,根据我的经验,这是人们在这样的场景中通常使用的。你可能会想看看它。

免责声明:我目前受雇于相扑逻辑公司

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56439235

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档