使用Azure Insights和/或分析,提醒错误率超过阈值



我将customEvents发送到看起来像这样的Azure应用程序洞察力:

timestamp                 |  name          |  customDimensions
----------------------------------------------------------------------------
2017-06-22T14:10:07.391Z  |  StatusChange  |  {"Status":"3000","Id":"49315"}
2017-06-22T14:10:14.699Z  |  StatusChange  |  {"Status":"3000","Id":"49315"}
2017-06-22T14:10:15.716Z  |  StatusChange  |  {"Status":"2000","Id":"49315"}
2017-06-22T14:10:21.164Z  |  StatusChange  |  {"Status":"1000","Id":"41986"}
2017-06-22T14:10:24.994Z  |  StatusChange  |  {"Status":"3000","Id":"41986"}
2017-06-22T14:10:25.604Z  |  StatusChange  |  {"Status":"2000","Id":"41986"}
2017-06-22T14:10:29.964Z  |  StatusChange  |  {"Status":"3000","Id":"54234"}
2017-06-22T14:10:35.192Z  |  StatusChange  |  {"Status":"2000","Id":"54234"}
2017-06-22T14:10:35.809Z  |  StatusChange  |  {"Status":"3000","Id":"54234"}
2017-06-22T14:10:39.22Z   |  StatusChange  |  {"Status":"1000","Id":"74458"}

假设状态3000是错误状态,当Ids的某些百分比最终在过去一个小时内处于错误状态时,我想获得警报。

据我所知,默认情况下的见解不能执行此操作,因此我想尝试此处描述的方法来编写可能触发警报的分析查询。这是我能想到的最好的:
customEvents
| where timestamp > ago(1h)
| extend isError = iff(toint(customDimensions.Status) == 3000, 1, 0)
| summarize failures = sum(isError), successes = sum(1 - isError) by timestamp bin = 1h
| extend ratio = todouble(failures) / todouble(failures+successes)
| extend failure_Percent = ratio * 100
| project iff(failure_Percent < 50, "PASSED", "FAILED")

但是,要使我的警报正常工作,查询应该:

  1. 返回"通过"即使在一个小时内没有事件(另一个警报都会照顾没有事件(
  2. (
  3. 仅考虑一个小时内每个ID的最终状态。

由于没有事件编写请求,查询尚未返回"传递"也不是"失败"。

它还考虑了使用Status == 3000的任何记录,这意味着上面的示例将返回"失败"(10个记录中有5个记录具有状态3000(,而实际上只有4个。ID最终处于错误状态。

有人可以帮助我找出正确的查询吗?

(还有可选的次要问题:有人使用Insights设置了类似的警报吗?这是正确的方法吗?(

如前所述,由于您只在单个时刻查询您不需要bin bin timestamp,或者根本不需要将其用作聚合的一部分。
回答您的问题:

  1. 克服根本没有数据的方法是将合成行注入表中,如果找不到其他结果
  2. ,将转化为成功结果
  3. 如果您希望通过/失败标准基于每个ID的最终状态,则需要在summarize中使用argmax - 它将返回与最大时间戳相对应的状态。

因此,将其全部包裹起来:

customEvents
| where timestamp > ago(1h)
| extend isError = iff(toint(customDimensions.Status) == 3000, 1, 0)
| summarize argmax(timestamp, isError) by tostring(customDimensions.Id) 
| summarize failures = sum(max_timestamp_isError), successes = sum(1 - max_timestamp_isError)
| extend ratio = todouble(failures) / todouble(failures+successes)
| extend failure_Percent = ratio * 100
| project Result = iff(failure_Percent < 50, "PASSED", "FAILED"), IsSynthetic = 0
| union (datatable(Result:string, IsSynthetic:long) ["PASSED", 1])
| top 1 by IsSynthetic asc 
| project Result 

关于奖励问题 - 您可以根据流程来基于分析查询来设置警报。有关一个相关的问题/答案

,请参见此处。

我认为查询在小时内没有数据,因为timestamp bin = 1h(aka bin(timestamp,1h)(不返回任何垃圾箱?

但是,如果您只是在查询最后一个小时,我认为您根本不需要时间戳上的垃圾桶?

没有数据,很难准确地重复出现,但是...您可以尝试(当心语法错误(:

customEvents
| where timestamp > ago(1h)
| extend isError = iff(toint(customDimensions.Status) == 3000, 1, 0)
| summarize totalCount = count(), failures = countif(isError == 1), successes = countif(isError ==0) 
| extend ratio = iff(totalCount == 0, 0, todouble(failures) / todouble(failures+successes))
| extend failure_Percent = ratio * 100
| project iff(failure_Percent < 50, "PASSED", "FAILED")

假设,摆脱时小时应该给您一排

的一行

totalcount = 0,失败= 0,成功= 0,因此失败百分比的数学应该给您回馈0失败比,这应该使您"通过"。

不尝试它,我不确定如果没有数据,那是否有效或仍然返回您没有行?

对于第二个问题,您可以使用

之类的东西
let maxTimestamp = toscalar(customEvents where timestamp > ago(1h)
| summarize max(timestamp));
customEvents | where timestamp == maxTimestamp ...
// ... more query here

仅获取具有时间戳记的行的行?

最新更新