# Azure Service Bus Queue Monitoring with Azure Monitor Metrics
## Overview
This document provides step-by-step instructions to create metrics in **Azure Monitor** for tracking:
- **Incoming Messages**: The total number of messages sent to the queue.
- **Completed Messages**: Messages successfully processed and removed from the queue.
- **Dead Lettered Messages**: Messages moved to the Dead Letter Queue (DLQ) after exceeding delivery attempts or TTL.
---
## Prerequisites
1. **Azure Subscription** with access to:
- Service Bus Namespace and Queue.
- Azure Monitor.
2. A Service Bus namespace with the following configuration:
- **Namespace Name**: `ordernamespace`
- **Max Delivery Count**: 3
- **Dead Letter Queue (DLQ)**: Enabled.
3. Proper permissions to create metrics and alerts in Azure Monitor.
---
## Steps to Create Metrics in Azure Monitor
### 1. Navigate to Azure Monitor
1. Log in to the [Azure Portal](https://portal.azure.com).
2. Search for **Azure Monitor** in the search bar and select it.
---
### 2. Define the Scope
1. In the **Azure Monitor** overview page, select **Metrics** from the left menu.
2. In the **Scope** section:
- Select the **Service Bus Namespace** (`ordernamespace`).
---
### 3. Configure Metrics
#### Incoming Messages Metric
1. In the **Metrics** tab, click **+ Add Metric**.
2. Select:
- **Metric Namespace**: `Service Bus Queue`.
- **Metric**: `Incoming Messages`.
3. Adjust visualization:
- Use **Line Chart** for trend analysis.
- Set the **Aggregation** to `Sum`.
4. Save the metric configuration.
---
#### Completed Messages Metric
1. Click **+ Add Metric** again.
2. Select:
- **Metric Namespace**: `Service Bus Queue`.
- **Metric**: `Completed Messages`.
3. Adjust visualization:
- Use **Bar Chart** to represent completed message counts.
- Set the **Aggregation** to `Sum`.
4. Save the metric configuration.
---
#### Dead Lettered Messages Metric
1. Click **+ Add Metric** again.
2. Select:
- **Metric Namespace**: `Service Bus Queue`.
- **Metric**: `Dead Lettered Messages`.
3. Adjust visualization:
- Use **Table Chart** to analyze DLQ trends.
- Set the **Aggregation** to `Sum`.
4. Save the metric configuration.
---
## References
1. [Azure Monitor Documentation](https://learn.microsoft.com/en-us/azure/azure-monitor/)
2. [Azure Service Bus Documentation](https://learn.microsoft.com/en-us/azure/service-bus-messaging/)
---