Azure应用洞察基于百分比的警报

时间:2018-07-05 10:01:09

标签: azure azure-application-insights azure-log-analytics

我正在尝试创建有关应用程序见解的警报,如果我的请求中有超过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上实施此查询的替代策略,我将不胜感激。

谢谢。

1 个答案:

答案 0 :(得分:1)

如果您想使用阈值警报,我可以将您的第一个查询替换为以下查询:

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)

如果您希望使用“结果警报数量”方法,我认为您可以将第二个查询的最后一行替换为| where hasFailed == true,以便在满足条件时以第一行结束,并且为零排成行。