Set up a custom Azure dashboard and alerts to monitor the health of your queues

by Patrick Lee on 29 Sep 2019 in categories tech with tags ASP.NET Core Azure AzureFunctions AzureQueues dashboard

Set up a custom dashboard showing the length of your queues 

One of the common use cases for an Azure function is to run on a timer to check the status of one or more Azure queues.

You can do this very easily via an Azure v2 function because these integrate very easily with their associated Applications Insights resource. (If you create the function via the Azure portal, you can choose - and I recommend - to create an associated Applications Insights resource at the same time.  Otherwise you can add such a resource after creating the function.)

It turns out (although this is not immediately clear from the documentation) that you don't have to do anything to connect your function to its Application Insights resource: if you want to add a custom metric (e.g. the length of a particular queue), all you have to do is call LogMetric on the logger than is passed to the function.

For example, for a queue called queueName whose approximate length is queueLength, simply call:

log.LogMetric($"Queue length - {queueName}", (double)queueLength);

So with very little code you can track and monitor the approximate length of your Azure queues over time via creating charts of these custom metrics and even add them to a custom Azure dashboard that you can check periodically to try and find out:

  • a) what your normal patterns of queue usage are
  • b) spot unusual patterns which could be an early warning sign of problems or extra resources being needed.

Set up automated alerts if your queues grow bigger than expected

And you can even set up alerts to send yourself and key colleagues an email if a queue (including a poison queue) has an unexpectedly high number of messages.

To do this: in the Portal, via Monitor, Alerts, New alert rule, then choose the ApplicationInsights cadsqueuemonitorfuncapp1 resource.

In Configure signal logic, choose Metrics as the signal type and AzureApplicationInsights as the service to be monitored, and then you can choose any of the custom metrics (i.e. the length of a particular queue), and add an alert to e.g. send an email to a group of addresses if the queue length exceeds a specified number.

Conclusion

This is a great feature of Azure Functions version 2, and combined with custom metrics in Application Insights, custom dashboards and Alerts can make monitoring your Azure queues much easier!