如何以编程方式访问 Azure Functions 使用指标? [英] How can I programmatically access Azure Functions usage metrics?
问题描述
我想为基于消耗的 Azure Functions 检索精细的 GB/秒使用数据.我该怎么做?
I would like to retrieve granular GB/sec usage data for my consumption based Azure Functions. How can I do this?
推荐答案
使用情况数据可通过 Azure Monitor REST API 获得.有关如何使用此 API 的一般概述,请参阅 这里.
The usage data is available through the Azure Monitor REST API. For a general overview of how to use this API, see here.
相关指标是FunctionExecutionUnits
.该单位以 MB 毫秒为单位,因此要将其转换为 GB 秒,您需要将这些值除以 1,024,000.以下是检索函数应用每分钟使用数据的示例查询:
The relevant metric is FunctionExecutionUnits
. This unit is in MB-milliseconds so to convert it into GB-seconds you need to divide the values by 1,024,000. Here is an example query retrieving per-minute usage data for a function app:
GET /subscriptions/<subid>/resourcegroups/<rg>/providers/Microsoft.Web/sites/<appname>/providers/microsoft.insights/metrics?api-version=2016-06-01&$filter=(name.value eq 'FunctionExecutionUnits') and timeGrain eq duration'PT1M' and startTime eq 2016-12-10T00:00:00Z and endTime eq 2016-12-10T00:05:00Z and (aggregationType eq 'Total')
你会得到这样的东西:
{
"value": [
{
"data": [
{
"timeStamp": "2016-12-10T00:00:00Z",
"total": 0
},
{
"timeStamp": "2016-12-10T00:01:00Z",
"total": 140544
},
{
"timeStamp": "2016-12-10T00:02:00Z",
"total": 0
},
{
"timeStamp": "2016-12-10T00:03:00Z",
"total": 0
},
{
"timeStamp": "2016-12-10T00:04:00Z",
"total": 0
}
],
"name": {
"value": "FunctionExecutionUnits",
"localizedValue": "Function Execution Units"
},
"type": "Microsoft.Insights/metrics",
"unit": "0"
}
]
}
这篇关于如何以编程方式访问 Azure Functions 使用指标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!