如何以编程方式访问Azure功能使用指标?

Pau*_*tum 5 azure azure-functions

我想为基于消费的Azure功能检索粒度GB /秒使用数据.我怎样才能做到这一点?

Pau*_*tum 9

使用数据可通过Azure Monitor REST API获得.有关如何使用此API的一般概述,请参见此处.

相关指标是FunctionExecutionUnits.此单位为MB毫秒,因此要将其转换为GB秒,您需要将值除以1,024,000.以下是检索功能应用的每分钟使用数据的示例查询:

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')
Run Code Online (Sandbox Code Playgroud)

你会得到这样的东西:

{
  "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"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)