---
title: Monitor Azure Service Bus with Elasticsearch & Azure Function with .NET Core 3.0
description: Most people who have ever sat with Azure Service Bus as a transport layer in some kind of event-driven architecture have probably used Paolo Salvatori's WinForms project, Service Bus Explorer.
image: https://lp.queenslab.co/hubfs/Elasticsearch-cover.jpg
---

[Skip to content](https://lp.queenslab.co/blog/monitor-azure-service-bus-with-elasticsearch#main-content)

Close

- [About us](https://lp.queenslab.co/about-us)
- [Services](https://lp.queenslab.co/services)
- [Cases](https://lp.queenslab.co/cases)
- [News](https://lp.queenslab.co/blog)
- [Career](https://join.queenslab.se/)
- [Contact](https://lp.queenslab.co/contact)

[![Frame (16)](https://lp.queenslab.co/hs-fs/hubfs/Frame%20(16).png?width=114&height=26&name=Frame%20(16).png)](https://www.eqlovesmusic.com/wp-content/uploads/2020/06/QueensLab-logo-stacked-black-rgb.png) [![Frame (16)](https://lp.queenslab.co/hs-fs/hubfs/Frame%20(16).png?width=114&height=26&name=Frame%20(16).png)](https://www.eqlovesmusic.com/wp-content/uploads/2020/06/QueensLab-logo-stacked-black-rgb.png)

- [About us](https://lp.queenslab.co/about-us)
- [Services](https://lp.queenslab.co/services)
- [Cases](https://lp.queenslab.co/cases)
- [News](https://lp.queenslab.co/blog)
- [Career](https://join.queenslab.se/)
- [Contact](https://lp.queenslab.co/contact)

25 November 2019 3 min read

# Monitor Azure Service Bus with Elasticsearch & Azure Function with .NET Core 3.0

[Previous](https://lp.queenslab.co/blog/wtf-is-pwa)

<https://lp.queenslab.co/blog>

[Next](https://lp.queenslab.co/blog/ada-the-ultimate-queen)

### The problem

Most people who have ever sat with Azure Service Bus as a transport layer in some kind of event-driven architecture have probably used Paolo Salvatori's WinForms project, [Service Bus Explorer.](https://github.com/paolosalvatori/ServiceBusExplorer)

 

![Elasticsearch-1](https://lp.queenslab.co/hs-fs/hubfs/Elasticsearch-1.jpg?width=800&name=Elasticsearch-1.jpg)

 

Personally, I have benefited a lot from Service Bus Explorer but I am genuinely surprised that it is the only tool available in its class to monitor and view queues in Service Bus, and the application lacks relevant features that I as a developer and system administrator need to do a good job.

The need to monitor and be able to alert when messages start to accumulate on a queue or DLQ has been recurring over the past six months. The specific case I have worked on has required the solution to be able to do the following:

1. Monitor number of messages on deadletter queue (Azure Service Bus)
2. Identify problems based on rules that can be configured, alert and then send e-mails
3. Continuously update an Elasticsearch index with details about queues
4. Visualize this Elasticsearch index on a Dashboard in Elasticsearch

 

To do this, we have developed a simple Azure Function that runs every five minutes, alerts if the configuration dictates and updates Elasticsearch with the right data. A few simple steps to achieve this solution.

 

### Set up the Elasticsearch Index

The following curl creates an index in Elasticsearch named example-queue.

curl -X PUT https://{username}:{password}.{elasticsearch-instance}:9243/example-queue

### Set up Azure Function

In the Azure portal, we set up an Azure Function container. We call it example-queue-monitor. When there is an Azure Function in place, we can take the opportunity to set it up with the right settings.

 

![Elasticsearch-2](https://lp.queenslab.co/hs-fs/hubfs/Elasticsearch-2.jpg?width=800&name=Elasticsearch-2.jpg)

 

> \[
> 
> {
> 
>  "name": "AlertRules:FiveMinutePercentageThreshold",
> 
>  "value": "50",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "AlertRules:HighThreshold",
> 
>  "value": "100",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "AlertRules:LowThreshold",
> 
>  "value": "2",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "AlertRules:MediumThreshold",
> 
>  "value": "10",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "APPINSIGHTS\_INSTRUMENTATIONKEY",
> 
>  "value": "",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "AzureWebJobsStorage",
> 
>  "value": "",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "ElasticConnection",
> 
>  "value": "https://{username}:{password}.{elasticsearch-instance}:9243",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "ElasticIndex",
> 
>  "value": "example-queue",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "EmailConfig:Recipient",
> 
>  "value": "where.to.send.the.alarm@example.com",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "EmailConfig:Sender",
> 
>  "value": "valid.postmark.sender@example.com",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "Environment",
> 
>  "value": "user for logging",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "FUNCTIONS\_EXTENSION\_VERSION",
> 
>  "value": "~2",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "FUNCTIONS\_WORKER\_RUNTIME",
> 
>  "value": "dotnet",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "LogQueue",
> 
>  "value": "elastic-log-index",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "PostMarkWarningTemplateId",
> 
>  "value": "15046353",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "ServiceBusConnection",
> 
>  "value": "Endpoint=sb://my- servicebus.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey={key}",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "WEBSITE\_CONTENTAZUREFILECONNECTIONSTRING",
> 
>  "value": "",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "WEBSITE\_CONTENTSHARE",
> 
>  "value": "",
> 
>  "slotSetting": false
> 
> },
> 
> {
> 
>  "name": "WEBSITE\_RUN\_FROM\_PACKAGE",
> 
>  "value": "",
> 
>  "slotSetting": false
> 
> }
> 
> \]

 

 

### ServiceBusMonitorFunction

ServiceBusMonitorFunction is available on GitHub. We publish the function to our Azure Function and run it through once.

 

![Elasticsearch-3](https://lp.queenslab.co/hs-fs/hubfs/Elasticsearch-3.jpg?width=800&name=Elasticsearch-3.jpg)

 

 

### Elasticsearch

In addition to our new index, example-queue, we need an index pattern to be able to visualize the data in a meaningful way. We create it in the Elasticsearch dashboard. In our case, we can have an exact pattern which is also called example-queue.

 

![Elasticsearch-4](https://lp.queenslab.co/hs-fs/hubfs/Elasticsearch-4.jpg?width=800&name=Elasticsearch-4.jpg)

I

n step 2, we can choose whether to use Created or Updated as the Time attribute in Elasticsearch, which is used for filtering. In our case we use Updated.

 

### Elasticsearch Dashboard

There are many different ways to visualize data in Elasticsearch, but for this purpose we will settle for a simple pie chart.

 

![Elasticsearch-5](https://lp.queenslab.co/hs-fs/hubfs/Elasticsearch-5.jpg?width=800&name=Elasticsearch-5.jpg)

 

So in the end we have a very simple monitoring with email sending when messages are built up on DLQ. Some things we know about is that the current solution sends an email every five minutes unless the deadletter queues are processed and emptied, that can be both good and bad depending on who receives the email ;)

Written by Marcus Nordquist

 

## Related posts

### [28 March 2023 2 min read Taking QueensLab to Japan Start Reading](https://lp.queenslab.co/blog/https/www.queenslab.co/blog/taking-queenslab-to-japan-1)

### [10 October 2022 8 min read Your View Of Information Technology Is Wrong Start Reading](https://lp.queenslab.co/blog/your-view-of-information-technology-is-wrong)

### [05 September 2022 3 min read QueensLab New Brand - Why? Start Reading](https://lp.queenslab.co/blog/queenslab-new-brand-why)

[![QueensLab](https://lp.queenslab.co/hs-fs/hubfs/Frame%20(16).png?width=114&height=26&name=Frame%20(16).png)](https://www.eqlovesmusic.com/wp-content/uploads/2020/06/QueensLab-logo-stacked-black-rgb.png)

Together we explore the unknown.

[info@queenslab.se](mailto:info@queenslab.se)   
+4631 745 80 40

[**Linkedin**](https://www.linkedin.com/company/queenslab/?originalSubdomain=se)  
[**Instagram Sweden**](https://www.instagram.com/queenslab.sweden/)  
[**Instagram Portugal**](https://www.instagram.com/queenslab.portugal/)  
[**Tiktok**](https://www.tiktok.com/@queenslab)

- [Gothenburg](https://goo.gl/maps/CmndegLWk7raX3gs9) 
    - [Västra Hamngatan 11 411 17 Gothenburg](https://goo.gl/maps/CmndegLWk7raX3gs9)
- [Stockholm](https://goo.gl/maps/8VnickyTQoyeBuZWA) 
    - [Stora Nygatan 33 111 27 Stockholm](https://goo.gl/maps/8VnickyTQoyeBuZWA)
- [Lisbon](https://goo.gl/maps/tUMrijzs9RWXAdaj8) 
    - [Av. Fontes Pereira de Melo 16 1050-121 Lisbon](https://goo.gl/maps/tUMrijzs9RWXAdaj8)

Keep in touch with us

We follow all GDPR rules of course  ❤️  
You can read our privacy policy [here](https://www.queenslab.co/privacy-policy).

```json
{
  "@context" : "https://schema.org",
  "@type" : "Organization",
  "address" : {
    "@type" : "PostalAddress",
    "addressCountry" : "Sverige",
    "addressLocality" : "Göteborg",
    "addressRegion" : "Göteborg",
    "postalCode" : "411 19",
    "streetAddress" : "Västra Hamngatan 11"
  },
  "knowsLanguage" : "en",
  "logo" : {
    "@type" : "ImageObject",
    "url" : "https://8840478.fs1.hubspotusercontent-na1.net/hubfs/8840478/QL_Logo_Blue.png"
  },
  "name" : "QueensLab",
  "url" : "https://lp.queenslab.co/blog/monitor-azure-service-bus-with-elasticsearch"
}
```

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "abstract" : "Most people who have ever sat with Azure Service Bus as a transport layer in some kind of event-driven architecture have probably used Paolo Salvatori's WinForms project, Service Bus Explorer.",
  "author" : {
    "@type" : "Person",
    "name" : "QueensLab"
  },
  "dateModified" : "December 13, 2022 6 PM",
  "datePublished" : "November 25, 2019 7 PM",
  "headline" : "Monitor Azure Service Bus with Elasticsearch &amp; Azure Function with .NET Core 3.0",
  "image" : "https://8840478.fs1.hubspotusercontent-na1.net/hubfs/8840478/Elasticsearch-cover.jpg",
  "inLanguage" : "en",
  "keywords" : "[]",
  "mainEntityOfPage" : {
    "@type" : "WebPage"
  },
  "name" : "Monitor Azure Service Bus with Elasticsearch &amp; Azure Function with .NET Core 3.0",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://8840478.fs1.hubspotusercontent-na1.net/hubfs/8840478/QL_Logo_Blue.png"
    },
    "name" : "QueensLab"
  },
  "text" : "The problem Most people who have ever sat with Azure Service Bus as a transport layer in some kind of event-driven architecture have probably used Paolo Salvatori's WinForms project, Service Bus Explorer. Personally, I have benefited a lot from Service Bus Explorer but I am genuinely surprised that it is the only tool available in its class to monitor and view queues in Service Bus, and the application lacks relevant features that I as a developer and system administrator need to do a good job. The need to monitor and be able to alert when messages start to accumulate on a queue or DLQ has been recurring over the past six months. The specific case I have worked on has required the solution to be able to do the following: Monitor number of messages on deadletter queue (Azure Service Bus) Identify problems based on rules that can be configured, alert and then send e-mails Continuously update an Elasticsearch index with details about queues Visualize this Elasticsearch index on a Dashboard in Elasticsearch To do this, we have developed a simple Azure Function that runs every five minutes, alerts if the configuration dictates and updates Elasticsearch with the right data. A few simple steps to achieve this solution. Set up the Elasticsearch Index The following curl creates an index in Elasticsearch named example-queue. curl -X PUT https://{username}:{password}.{elasticsearch-instance}:9243/example-queue Set up Azure Function In the Azure portal, we set up an Azure Function container. We call it example-queue-monitor. When there is an Azure Function in place, we can take the opportunity to set it up with the right settings. [ { \"name\": \"AlertRules:FiveMinutePercentageThreshold\", \"value\": \"50\", \"slotSetting\": false }, { \"name\": \"AlertRules:HighThreshold\", \"value\": \"100\", \"slotSetting\": false }, { \"name\": \"AlertRules:LowThreshold\", \"value\": \"2\", \"slotSetting\": false }, { \"name\": \"AlertRules:MediumThreshold\", \"value\": \"10\", \"slotSetting\": false }, { \"name\": \"APPINSIGHTS_INSTRUMENTATIONKEY\", \"value\": \"\", \"slotSetting\": false }, { \"name\": \"AzureWebJobsStorage\", \"value\": \"\", \"slotSetting\": false }, { \"name\": \"ElasticConnection\", \"value\": \"https://{username}:{password}.{elasticsearch-instance}:9243\", \"slotSetting\": false }, { \"name\": \"ElasticIndex\", \"value\": \"example-queue\", \"slotSetting\": false }, { \"name\": \"EmailConfig:Recipient\", \"value\": \"where.to.send.the.alarm@example.com\", \"slotSetting\": false }, { \"name\": \"EmailConfig:Sender\", \"value\": \"valid.postmark.sender@example.com\", \"slotSetting\": false }, { \"name\": \"Environment\", \"value\": \"user for logging\", \"slotSetting\": false }, { \"name\": \"FUNCTIONS_EXTENSION_VERSION\", \"value\": \"~2\", \"slotSetting\": false }, { \"name\": \"FUNCTIONS_WORKER_RUNTIME\", \"value\": \"dotnet\", \"slotSetting\": false }, { \"name\": \"LogQueue\", \"value\": \"elastic-log-index\", \"slotSetting\": false }, { \"name\": \"PostMarkWarningTemplateId\", \"value\": \"15046353\", \"slotSetting\": false }, { \"name\": \"ServiceBusConnection\", \"value\": \"Endpoint=sb://my- servicebus.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey={key}\", \"slotSetting\": false }, { \"name\": \"WEBSITE_CONTENTAZUREFILECONNECTIONSTRING\", \"value\": \"\", \"slotSetting\": false }, { \"name\": \"WEBSITE_CONTENTSHARE\", \"value\": \"\", \"slotSetting\": false }, { \"name\": \"WEBSITE_RUN_FROM_PACKAGE\", \"value\": \"\", \"slotSetting\": false } ] ServiceBusMonitorFunction ServiceBusMonitorFunction is available on GitHub. We publish the function to our Azure Function and run it through once. Elasticsearch In addition to our new index, example-queue, we need an index pattern to be able to visualize the data in a meaningful way. We create it in the Elasticsearch dashboard. In our case, we can have an exact pattern which is also called example-queue. I n step 2, we can choose whether to use Created or Updated as the Time attribute in Elasticsearch, which is used for filtering. In our case we use Updated. Elasticsearch Dashboard There are many different ways to visualize data in Elasticsearch, but for this purpose we will settle for a simple pie chart. So in the end we have a very simple monitoring with email sending when messages are built up on DLQ. Some things we know about is that the current solution sends an email every five minutes unless the deadletter queues are processed and emptied, that can be both good and bad depending on who receives the email ;) Written by Marcus Nordquist",
  "url" : "https://lp.queenslab.co/blog/monitor-azure-service-bus-with-elasticsearch",
  "wordCount" : "2113"
}
```

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "QueensLab",
    "url" : "https://lp.queenslab.co/blog/author/queenslab"
  },
  "dateModified" : "2022-12-13T18:48:43.156Z",
  "datePublished" : "2019-11-25T19:56:00.000Z",
  "headline" : "Monitor Azure Service Bus with Elasticsearch & Azure Function with .NET Core 3.0",
  "image" : [ "https://lp.queenslab.co/hubfs/Elasticsearch-cover.jpg" ],
  "mainEntityOfPage" : {
    "@id" : "https://lp.queenslab.co/blog/monitor-azure-service-bus-with-elasticsearch",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://lp.queenslab.co/hubfs/QL_Logo_Blue.png"
    },
    "name" : "QueensLab"
  }
}
```