从未触发执行计数 < 1 的 Azure Function 监视器警报

Azure Function monitor alert where execution count < 1 never triggered

我有一个带有 Azure Functions 的 Azure Function 应用程序,我想单独使用以下规则对其进行监控:如果 Azure Functions 在 N 分钟内未执行,则发送 email/notification。

我想知道这是否可以通过 Application Insights Alerts 实现, 为单个 Azure 上的 count 提供信号逻辑功能基础。但是这个计数永远不会为 0,在图中似乎任何计数 < 0 都不会被视为数字。它显示为 --,如下图所示,我的测试函数:

testfunction chart(没有足够的声誉来 post 图片)

图表上的峰值显示为 3,但如果我使用条件“每当测试函数计数小于 1”,则永远不会触发警报。

更改聚合粒度并没有太大作用,因为信号逻辑似乎从未记录过 0 计数或任何小于 1 的计数。

有很多(稍微)更不方便的方法来进行这种类型的监视,但是使用漂亮的内置 Azure Application Insights Alerts 似乎很有可能,如果可能的话,我想使用它。

我是在试图滥用 Application Insights 警报,还是有一些明显的东西我没有得到?我认为应该可以有基于缺乏执行的监控规则。

您可能需要使用 log/query 警报来执行此操作。如果您正在执行基于指标的警报,其中一些不会将 0 作为数据发送。因此,如果在某个时间范围内没有发生任何事情,则没有 0 可以提醒,因为没有提交 0, 0, 0, 0.

相反,您将根据查询创建警报:https://docs.microsoft.com/en-us/azure/azure-monitor/platform/alerts-unified-log

文档列出了这个确切的场景:

In some cases, you may want to create an alert in the absence of an event.

For example, a process may log regular events to indicate that it's working properly. If it doesn't log one of these events within a particular time period, then an alert should be created. In this case, you would set the threshold to less than 1. [emphasis added, this is your scenario, correct]?

Example of Number of Records type log alert

Consider a scenario where you want to know when your web-based App gives a response to users with code 500 (that is) Internal Server Error. You would create an alert rule with the following details:

Query: requests | where resultCode == "500"

Time period: 30 minutes

Alert frequency: five minutes

Threshold value: Greater than 0

在该示例中,由于设置了时间段,查询最终会变成类似 requests | where timespan < ago(30m) | where resultCode == "500" 的内容。 (然后查询本身可以过滤那个时间 range/result 根据需要设置)

所以对于你来说,你可能只是做 requests 根本没有 where 条件,无论你有什么时间段和频率,并且 "less than one" 作为阈值。 您还可以进行更复杂的查询,以过滤掉测试数据等。

需要注意的一件事是,我相信每次频率过去时日志警报都会触发警报。因此,如果您每 5 分钟设置了一个请求 < 1 警报,并且您的函数在 2 小时内没有调用,则警报将每 5 分钟触发一次,向您发送 40 封电子邮件或其他任何内容。也许你想要那个:)