【发布时间】:2020-11-11 16:05:47
【问题描述】:
我遇到了一个问题,即在执行 azure 函数时会触发 azure 警报。我查看了不同的文档,查看了警报规则,查看了代码,但似乎我无法指出问题所在。你们可以检查一下我错过了什么吗?
警报的条件如下:
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
"allOf": [
{
"name": "1st criterion",
"metricName": "<functionName> Failures",
"metricNamespace": "Azure.ApplicationInsights",
"dimensions": [
],
"operator": "GreaterThan",
"threshold": "0",
"monitorTemplateType": "8",
"criterionType": "StaticThresholdCriterion",
"timeAggregation": "PT1M",
"skipMetricValidation": true
}
]
},
"autoMitigate": true,
相关部分代码:
module.exports = async function (context, req) {
try{
let res = await apicall();
response = {
status: 200, /* Defaults to 200 */
body: res
}
}catch(error){
response = {
status: 500, /* Defaults to 500 */
body: errorHandler(error)
};
errorObj = error
}finally{
if (response.status == 200) {
context.done(null, response)
} else {
context.done(errorObj, response)
}
}
}
并成功执行:
【问题讨论】:
-
您是否通过 azure monitor 设置了警报?如果您通过 UI 配置警报,可以分享一些屏幕截图吗?
-
我是通过 azure 资源管理器设置的,
-
哦,我不熟悉资源管理器。但是如果你可以通过 UI 使用 azure monitor 来设置它,我可以提供一些想法。
-
我添加了图片
-
是的,切换到它可能是一个更好的主意。首先,我将完成一些我仍然需要对我的函数应用程序进行的修改,然后检查自定义搜索日志以及警报如何使用它。感谢您的意见:)
标签: node.js azure azure-functions azure-alerts