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

时间:2016-12-13 18:43:17

标签: azure azure-functions

我想为基于消费的Azure功能检索粒度GB /秒使用情况数据。我怎么能这样做?

1 个答案:

答案 0 :(得分:9)

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

相关指标为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')

你会得到这样的东西:

{
  "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"
    }
  ]
}