在基于日志的 kusto 查询上设置多个阈值

问题描述

我在 Microsoft Azure 中设置了基于日志的警报。通过 ARM 模板完成警报的部署。 您可以在其中输入查询并设置阈值,如下所示。

 "triggerThresholdOperator": {
        "value": "GreaterThan"
      },"triggerThreshold": {
        "value": 0
      },"frequencyInMinutes": {
        "value":15
      },"timeWindowInMinutes": {
        "value": 15
      },"severityLevel": {
        "value": "0"
      },"appInsightsQuery": {
        "value": "exceptions\r\n| where A_ != '2000' \r\n| where A_ != '4000' \r\n| where A_ != '3000' "
      }

据我所知,我们只能在整个查询中设置一次阈值。

问题:我的查询中有多个语句,我将它们排除在外,因为它只是一个噪音。但是现在我想将值 3000 的阈值设置为 5,并且还想在同一查询中将时间窗口设置为 30。意思是只排除过去 30 分钟内出现 5 次的 3000(当查询运行时)。

exceptions
| where A_ != '2000' 
| where A_ != '4000' 
| where A_ != '3000' 

我很确定我无法在查询中设置这样的阈值,唯一的解决方法是为值 3000 创建一个新警报并在 ARM 模板中设置一个阈值。我在 Aure 中没有发现任何重阈值/时间过滤器。有什么方法可以在单个查询中设置多个阈值和时间过滤器?这将再次通过 ARM 模板中的不同阈值和时间文件进行检查。

谢谢。

解决方法

我不完全理解你的问题。

但是对于您的时间窗口问题,您可以执行类似的操作

exceptions
| summarize count() by A_,bin(TimeGenerated,30m)

这样你就会得到一个以 30 分钟为单位的 A_ 计数。

另一种方法是:

let Materialized = materialize(
exceptions
| summarize Count=count(A_) by bin(TimeGenerated,30m)
); 
Materialized | where Count == 10

不过话说回来,这一切都取决于你想要达到的目标

,

您可以在查询中轻松设置并根据汇总结果触发。

exceptions
| where timestamp > ago(30m)
| summarize count2000 = countif(A_ == '2000'),count3000 = countif(A_ == '3000'),count4000 = countif(A_ == '4000')
| where count2000 > 5 or count3000 > 3 or count4000 > 4

如果结果数量大于 1,则聚合条件适用。