Azure功能-以编程方式检查其完成

时间:2019-08-09 06:00:18

标签: azure azure-functions azure-monitoring

我有一个Azure函数,我想检查它是否已完成运行。

此刻,我正在做的是进入Portal中的应用程序,然后单击Monitor并观察日期/时间,直到它基本上停止显示新行。基本上,如果10分钟后没有录入,我就知道完成了。

enter image description here

这不是很理想,所以我可以用JavaScript代替吗?

或者在门户网站中更简单的方法?我已经看到有可能在Application Insights的Logs(Analytics)中运行查询吗?那里有什么办法可以解决问题?

任何想法/帮助将不胜感激。

谢谢。

1 个答案:

答案 0 :(得分:1)

这是一个示例请求,该请求将返回与JSON相同的内容-

curl 'https://management.azure.com//subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/microsoft.insights/components/<FUNC_APP_NAME>/api/query?api-version=2015-05-01' \
    -H 'Authorization: Bearer eyJ0....' \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    --data-binary $'{\n  "query": "requests | where timestamp >= ago(30d) | where cloud_RoleName =~ \'<FUNC_APP_NAME>\' and operation_Name == \'<FUNC_NAME>\' | summarize count=count() by success"\n}'

有关更详细的视图,请使用-

"query": "requests |
    project timestamp, id, operation_Name, success, resultCode, duration, operation_Id, cloud_RoleName, invocationId=customDimensions['InvocationId'] |
    where timestamp > ago(30d) |
    where cloud_RoleName =~ '<FUNC_APP_NAME>' and operation_Name == '<FUNC_NAME>' |
    order by timestamp desc |
    take 20"

来源:在Azure门户中,按F12开发人员工具>“网络”选项卡,刷新屏幕快照中的刀片服务器。

为了更加简洁,我建议您向Application Insights API查询此数据,而不要查询ARM API。

遥测可能会延迟最多5分钟,通常会少很多,但可以解决这个问题。另请注意,400 Bad Request被视为成功,全绿色,因为从技术上讲这是正确的,您的函数运行正常,输入错误-

400 bad request

相关问题