我正在尝试创建有关应用程序见解的警报,如果超过 5% 的请求超过特定阈值,该警报就会向我发出警报。我在 Application Insights 的警报部分编写了一个查询,并将其指定为指标测量,以在超过所需阈值时发出警报
requests
| where timestamp >= ago(15m)
| where (tostring(customDimensions['ProviderName']) == 'ProviderX')
| where (tostring(customDimensions['operationMethod']) == 'operationX')
| extend responseTime = tolong(customDimensions['totalMilliseconds'])
| summarize AggregatedValue = (percentile(responseTime, 95)) by bin(timestamp, 15m)
虽然此警报有效并正确通知我,但存在一个问题,即由于在某些 15 分钟窗口内请求数量极少(少于 3 个),因此存在大量误报。因此,我只想在超过阈值并且该时间段内相关请求的数量超过某个阈值(例如 10)时发出警报。
我尝试使用应用程序见解的警报部分中的“结果数量警报”来执行此操作。
requests
| where timestamp >= ago(15m)
| where (tostring(customDimensions['ProviderName']) == 'ProviderX')
| where (tostring(customDimensions['operationMethod']) == 'OpeartionX')
| extend responseTime = tolong(customDimensions['totalMilliseconds'])
| summarize hasFailed = ((percentile(responseTime, 95) > 1000) and count() > 135)
| project iff(hasFailed, 1, 0)
我试图实现的是,如果测试失败,则警报返回 1,然后对该值发出警报。然而,“结果数”似乎仅对返回的结果数发出警报,因此这种方法也不起作用。
如果有人能够阐明适当的查询或有关如何在 Azure 上实现此操作的替代策略,我将不胜感激。
谢谢。
最佳答案
如果您想使用阈值警报,我可以将您的第一个查询替换为以下查询:
requests
| where timestamp >= ago(15m)
| where (tostring(customDimensions['ProviderName']) == 'ProviderX')
| where (tostring(customDimensions['operationMethod']) == 'operationX')
| extend responseTime = tolong(customDimensions['totalMilliseconds'])
| summarize AggregatedValue = iff(count() > 135, percentile(responseTime, 95), 0) by bin(timestamp, 15m)
如果您更喜欢“结果数量警报”方法,我认为您可以将第二个查询的最后一行替换为 |其中 hasFailed == true
这样,当满足条件时,您最终会得到一行,而当条件不满足时,您最终会得到零行。
关于Azure Application Insights 基于百分位数的警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51188442/