【问题标题】:Azure Web App Service trigger alert if X% of the requests fail如果 X% 的请求失败,Azure Web App Service 会触发警报
【发布时间】:2019-06-02 12:21:39
【问题描述】:
我一直在尝试设置托管在 Azure 中的 .NET Core 应用服务的警报,以在过去 24 小时内 X% 的请求失败时触发事件。我还尝试使用以下指标从服务的 AppInsights 资源设置警报:异常率、服务器异常或失败请求。
但是,这些都没有能力捕获% (failure rate),它们都使用count 作为指标。
有人知道解决方法吗?
【问题讨论】:
标签:
azure
azure-application-insights
azure-web-app-service
【解决方案1】:
请尝试基于查询的警报:
1.转到应用洞察分析,在查询编辑器中,输入以下脚本:
exceptions
| where timestamp >ago(24h)
| summarize exceptionsCount = sum(itemCount) | extend t = ""| join
(requests
| where timestamp >ago(24h)
| summarize requestsCount = sum(itemCount) | extend t = "") on t
| project isFail = 1.0 * exceptionsCount / requestsCount > 0.5 // if fail rate is greater than 50%, fail
| project rr = iff(isFail, "Fail", "Pass")
| where rr == "Fail"
2.然后点击右上角的“新建警报规则”:
3.在创建规则页面,设置如下:
【解决方案2】:
我一直在寻找一种方法来避免使用已经内置在应用程序洞察中的东西来编写查询,但最后我也想出了类似你的解决方案,而是使用请求:
requests
| summarize count()
| extend a = "a"
| join
(
requests
| summarize count() by resultCode
| extend a = "a"
)
on a
| extend percentage = (todouble(count_1)*100/todouble(count_))
| where resultCode == 200
| where percentage < 90 //percentage of success is less than 90%
| project percentage_of_failures = round(100- percentage,2), total_successful_req = count_, total_failing_req = count_ - count_1 , total_req = count_1