10
votes

Is it possible to view memory usage / how many consumption units you are presently/historically using for Azure Functions?

I'm currently using the consumption plan for a function which handles messages from a service bus queue. Each message takes around 5 seconds to process and there are usually several hundred messages / second to be handled.

My fear is simply that at some point I will starting seeing outofmemoryexceptions with no forewarning, though it would also be helpful for me to get an idea of costing before being billed.

I've looked through the portal and all I've found is the success count and pulse (which never seems to report any data for my function. Though the graphs are drawn - they are always empty.)

There is also this blog post:

https://blogs.msdn.microsoft.com/appserviceteam/2016/11/15/making-azure-functions-more-serverless/

..which essentially says that you do not need to specify your memory cap anymore and providing your usage is within 1.5GB & your processing is under the 5 minute timeout then life is good. Knowing how much room I have would be reassuring though!

2

2 Answers

9
votes

You can use the Monitor -> Metrics view in the Azure Portal:

enter image description here

For more information on this topic see this functions cost/billing FAQ.

4
votes

The simple answer to your question is "yes".

Use the Azure Monitor Metrics REST API to get FunctionExecutionUnits and FunctionExecutionCount metrics.

This sample call:
az monitor metrics list --resource /subscriptions/<subid>/resourceGroups/pbconsumptionexample/providers/Microsoft.Web/sites/pbconsumptionexample --metric FunctionExecutionUnits,FunctionExecutionCount --aggregation Total --interval PT1M

yields the following sample output shows 153600 MB-milliseconds, or .15 GB-ms:

"name": {
    "additionalProperties": {},
    "localizedValue": "Function Execution Units",
    "value": "FunctionExecutionUnits"
  },
  "resourceGroup": "pbconsumptionexample",
  "timeseries": [
    {
      "additionalProperties": {},
      "data": [
        {
          "additionalProperties": {},
          "average": null,
          "count": null,
          "maximum": null,
          "minimum": null,
          "timeStamp": "2018-04-13T23:40:00+00:00",
          "total": 153600.0
        }
      ],
      "metadatavalues": []
    }
  ],

Here's an explanation of how:

https://github.com/Azure/Azure-Functions/wiki/Consumption-Plan-Cost-Billing-FAQ#how-can-i-access-execution-count-and-gb-seconds-programmatically

For greater context:

https://github.com/Azure/Azure-Functions/wiki/Consumption-Plan-Cost-Billing-FAQ