Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Azure Service Bus Monitoring with Application Insights

This Azure Function App is a sample how to monitor an Azure Service Bus leveraging Application Insights. It will iterate through each queue and topic/subscription, creating custom metrics of Active Message count and DeadLetter Message count for each.

The function is timer triggered and will poll the queue length every 10 sec. To change this adjust the timerTrigger binding in function.json according to your needs. Please note that this sample just illustrates the concept and is not a fully configurable solution. It is by no means intended for being used in a production scenario as-is!

Deployment Steps

1. Create Application Insights Instance

If you don't already have an Application Insights instance you want to send the data to:

  • Navigate to the Azure portal
  • Next, login and navigate to the Application Insights blade and select "+Add"
  • Complete the guided setup of your Application Insights instance

From your Application insights blade, click into the instance that you will be using, select the Overview blade and copy the Instrumentation Key, you will need that later

2. Create an Azure Function App

  • Navigate to and click on Get Started button (at the time of this writing, it's at the bottom of the page)
  • Login, name your app and select a region
  • Click Create
  • You will then be redirected to the new function page in the Azure portal

3. Configure the App Service

  • At the bottom left of the Functions blade, there is a link for Function App Settings, click that, then click Configure App Settings
  • On the Applications Settings blade, add the following App Settings:
    • Key: TelemetryKey ; Value: the instrumentation key copied from Application insights
    • Key: QueueNames ; Value: Comma delimited list of service bus queues names
    • Key: TopicNames ; Value: Comma delimited list of service bus topic names
    • Key: SubsciptionNames ; Value: Commad delimited list of topic subscription names
  • Add the following to Connection Settings:
    • Key: ServiceBusConnectionString ; Value: Connection string to your service bus
  • Click the Save button to save these settings

4. Deploy your function

  • In the Function app blade, click "+ New function
  • Select "Empty - C#" as the template
  • Enter the name of your new function and click Create
  • In the Develop view / Code section, click the link for View Files
  • Click the upload icon and locate your files in the file picker window
  • Select the function.json, project.json, and run.csx files and click Open
  • Click the Save button to save your function. Compilation will start automatically
  • To ensure the function is runing properly, scroll down to the Logs window and you should see a "Compilation succeeded" message. If not, troubleshoot according to the log message

5. Monitor in Application Insights

The function will create 2 custom metrics for each queue and topic/subscription with the format of {name}-Active-Length and {name}-Deadletter-Length

  • In the Azure portal, navigate to your Application insights instance
  • Select Metrics Explorer and either add a new metric chart or edit an existing one.
  • Scroll down to CUSTOM metrics and select metric(s) you want to add to the chart.
  • The current metric length should now be displayed in the chart.

Optionally, you can also create an alert for specific threshold values of your new metric.

Thanks to Simon Schwingel for kickstarting this code!


An Azure Function App sample for how to monitor an Azure Service Bus leveraging Application Insights.




No releases published


You can’t perform that action at this time.