How can I programmatically access Azure Functions usage metrics?

前端 未结 1 1869
南笙
南笙 2021-02-10 04:40

I would like to retrieve granular GB/sec usage data for my consumption based Azure Functions. How can I do this?

1条回答
  •  时光说笑
    2021-02-10 05:24

    The usage data is available through the Azure Monitor REST API. For a general overview of how to use this API, see here.

    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//resourcegroups//providers/Microsoft.Web/sites//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')
    

    You'll get back something like this:

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

    0 讨论(0)
提交回复
热议问题