Azure function monitoring with Azure Monitor and Application Insights

September 26, 2022 

Microsoft Azure provides a metrics and monitoring framework called Azure Monitor. With it you can monitor your Cloud infrastructure and services running there. You can view graphs of the metrics, alert on threshold and all that usual stuff, just like in AWS Cloudwatch.

Some Cloud resources like Azure Functions expose "a limited number of useful metrics" in Azure Monitor. This is a polite way of saying that the metrics are "completely useless" for most intents and purposes. For example, an Azure Function that gets triggered a few times a week on an irregular schedule by real people you don't really have any useful metrics in Azure Monitor which you could alert on if something is off.

Fortunately you can use Application Insights to get more useful metrics. Application Insights extends Azure Monitor, but is not particularly tightly coupled with it. This is clear from the fact that both in Azure Portal and with Azure command-line they're completely separate things. Fortunately for us both Azure Monitor and Application Insights are supported by azure-metrics-exporter, which allows getting both metrics into Prometheus.

We are command-line guys, so here how you can get a list of metrics available in Azure Monitor and Application Insights. First log in to Azure - you can skip the tenant part if you only have access one:

$ az login --tenant example.onmicrosoft.com

First we get Azure Monitor metrics. Note that the resource-uri is the URI of the Azure Function itself:

$ az monitor metrics list-definitions --resource <resource-uri>

Then Application Insights metrics. Note that the --app parameter expect an URI of the Application Insights "component" of a Function, not a Function's resource URI:

az monitor app-insights metrics get-metadata --app <app-insights-component-uri>

Prometheus integration will follow up in future blog post, stay tuned!

Samuli Seppänen
Samuli Seppänen
Author archive
menucross-circle