使用 Azure Log Analytics,有没有办法根据搜索查询结果设置警报规则?

With Azure Log Analytics, is there has a way to set an alert rule based on the Search Query Results?

借助 Azure Log Analytics,我使用日志来监视某些内容,并根据查询结果设置新警报。

How do I need to set the coding/query?

我尝试编写一些代码来查看 CPU 的性能,Azure 日志上的内存并得到了我想要的图表。

Perf | where parse_json(CounterName) == "% Committed Bytes In Use" | where parse_json(ObjectName) == "Memory" | limit 10

I expect the I can set the alert based on the search result,

但是当我点击“+ 新警报规则”时,图表是由自定义日志搜索配置的,而不是性能计数器值(*如使用中的内存百分比提交字节数)。

也许我遗漏了一些东西,但根据给定的信息和 AFAIK,根据设计,当您在单击“+ 新警报规则”后尝试配置信号逻辑时,您可以看到的第一个信号是 "Custom log search"(属于 "Log" 信号类型,属于 "Log Analytics" 监控服务)。如果您想根据自己的自定义查询生成警报,可以使用此 "Custom log search"。但如果您想要 re-use pre-existing 信号(信号类型 "Metric"、"Activity Log" 等),那么您可以搜索所需信号并利用它们。我用关键字 "committed bytes in use" 进行了快速搜索,但找不到任何相关信号,所以我会使用 "Custom log search" 信号。

如果您的问题更多关于如何根据名为“% Committed Bytes In Use”的计数器的计数器值生成警报,请确保 "alert logic" 设置为 "Metric measurement" 并更新您的查询,例如如下所示。

Perf 
| where parse_json(CounterName) == "% Committed Bytes In Use" 
| where parse_json(ObjectName) == "Memory" 
| limit 10
| summarize AggregatedValue= avg(CounterValue) by Computer, bin(TimeGenerated, 30s)

有关警报逻辑("metric measurement" 或 "number of results")的更多信息,请参阅 this 文档。

其他相关参考:

https://docs.microsoft.com/en-us/azure/azure-monitor/platform/alerts-log#create-a-log-alert-rule-with-the-azure-portal

希望对您有所帮助!!干杯!!