You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/service-bus-messaging/automate-update-messaging-units.md
+41-28Lines changed: 41 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,8 @@
2
2
title: Azure Service Bus - Automatically update messaging units
3
3
description: This article shows you how you can use an Azure Automation runbook to automatically update messaging units of a Service Bus namespace.
4
4
services: service-bus-messaging
5
-
ms.service: service-bus-message
5
+
6
+
ms.service: service-bus-messaging
6
7
documentationcenter: ''
7
8
author: spelluru
8
9
@@ -13,10 +14,16 @@ ms.author: spelluru
13
14
---
14
15
15
16
# Automatically update messaging units of an Azure Service Bus namespace
16
-
This article shows you how you can use an Azure Automation runbook to automatically update messaging units of a Service Bus namespace.
17
+
This article shows you how you can automatically update [messaging units](service-bus-premium-messaging.md) of a Service Bus namespace based on resource (CPU or memory) usage.
18
+
19
+
The example in this article shows how to increase messaging units for a Service Bus namespace when the CPU usage of the namespace goes above 75%. The high-level steps are:
20
+
21
+
1. Create an Azure Automation runbook with PowerShell script that scales up (increases) messaging units for a Service Bus namespace.
22
+
2. Create a CPU usage alert on the Service Bus namespace, which invokes the PowerShell script when the namespace CPU usage goes above 75%.
17
23
18
24
> [!IMPORTANT]
19
-
> This article applies to only the premium tier of Azure Service Bus.
25
+
> This article applies to only the **premium** tier of Azure Service Bus.
26
+
20
27
21
28
## Create a Service Bus namespace
22
29
Create a premier tier Service Bus namespace. Follow steps from the [Create a namespace in the Azure portal](service-bus-quickstart-portal.md#create-a-namespace-in-the-azure-portal) article to create the namespace.
@@ -25,15 +32,19 @@ Create a premier tier Service Bus namespace. Follow steps from the [Create a nam
25
32
Create an Azure Automation account by following instructions from the [Create an Azure Automation account](../automation/automation-quickstart-create-account.md) article.
26
33
27
34
## Import Az.Service module from gallery
28
-
Import `Az.Accounts` and `Az.ServiceBus` modules from the gallery into the automation account. For step-by-step instructions, see [Import a module from the module gallery](../automation/automation-runbook-gallery.md#import-a-module-from-the-module-gallery-with-the-azure-portal).
35
+
Import `Az.Accounts` and `Az.ServiceBus` modules from the gallery into the automation account. The `Az.ServiceBus` module depends on `Az.Accounts` module, so it must be installed first.
36
+
37
+
For step-by-step instructions, see [Import a module from the module gallery](../automation/automation-runbook-gallery.md#import-a-module-from-the-module-gallery-with-the-azure-portal).
29
38
30
39
## Create and publish a PowerShell runbook
31
40
32
41
1. Create a PowerShell runbook by follow instructions in the [Create a PowerShell runbook](../automation/automation-quickstart-create-runbook.md) article.
33
42
34
-
Here's a sample PowerShell script you can use to increase messaging units for a Service Bus namespace. This PowerShell script in an automation runbook increases MUs from 1 to 2, 2 to 4, or 4 to 8. The allowed values for this property are: 1, 2, 4, and 8. You can create another runbook to decrease the messaging units.1
43
+
Here's a sample PowerShell script you can use to increase messaging units for a Service Bus namespace. This PowerShell script in an automation runbook increases MUs from 1 to 2, 2 to 4, or 4 to 8. The allowed values for this property are: 1, 2, 4, and 8. You can create another runbook to decrease the messaging units.
35
44
36
-
The **namespaceName** and **resourceGroupName** parameters are for testing the script in the runbook. The **WebHookData** parameter is for the alert to pass this information at runtime.
45
+
The **namespaceName** and **resourceGroupName** parameters are used for testing the script separately from alerting scenario.
46
+
47
+
The **WebHookData** parameter is for the alert to pass information such as resource group name, resource name, etc. at runtime.
37
48
38
49
```powershell
39
50
[OutputType("PSAzureOperationResponse")]
@@ -55,14 +66,21 @@ Import `Az.Accounts` and `Az.ServiceBus` modules from the gallery into the autom
@@ -85,6 +103,7 @@ Import `Az.Accounts` and `Az.ServiceBus` modules from the gallery into the autom
85
103
86
104
$currentCapacity = $sbusns.Sku.Capacity
87
105
106
+
# Increase the capacity
88
107
# Capacity can be one of these values: 1, 2, 4, 8
89
108
if ($currentCapacity -eq 1) {
90
109
$newMU = 2
@@ -108,13 +127,13 @@ Import `Az.Accounts` and `Az.ServiceBus` modules from the gallery into the autom
108
127
-ResourceGroupName $resourceGroupName
109
128
110
129
```
111
-
2. [Test the workbook](../automation/manage-runbooks.md#test-a-runbook) and confirm that the messaging units on the namespace are updated.
112
-
3. [Publish the workbook](..//automation/manage-runbooks.md#publish-a-runbook) so that it's available to add as an action for an alert on the namespace later.
130
+
2. [Test the workbook](../automation/manage-runbooks.md#test-a-runbook) by specifying values for the **namespaceName** and **resourceGroupName** parameters. Confirm that the messaging units on the namespace are updated.
131
+
3. After you test successfully, [publish the workbook](..//automation/manage-runbooks.md#publish-a-runbook) so that it's available to add as an action for an alert on the namespace later.
113
132
114
133
## Create an alert on the namespace to trigger the runbook
115
-
See [Use an alert to trigger an Azure Automation runbook](../automation/automation-create-alert-triggered-runbook.md) article to configure an alert on your Service Bus namespace to trigger the automation runbook you created. As an example, you could create an alert with namespace CPU usage goes above 75% as the condition and running automation runbook as an action on the alert.
134
+
See [Use an alert to trigger an Azure Automation runbook](../automation/automation-create-alert-triggered-runbook.md) article to configure an alert on your Service Bus namespace to trigger the automation runbook you created. For example, you can create an alert on **CPU usage per namespace** or **Memory size usage per namespace** metric, and add an action to trigger the automation runbook you created. For details about these metrics, see [Resource usage metrics](service-bus-metrics-azure-monitor.md#resource-usage-metrics).
116
135
117
-
Now, create an alert on the namespace for a metric and tie it to the automation runbook. For example, you can create an alert on **CPU usage per namespace** or **Memory size usage per namespace** metric, and add an action to trigger the automation runbook you created. For details about these metrics, see [Resource usage metrics](service-bus-metrics-azure-monitor.md#resource-usage-metrics).
136
+
The following procedure shows how to create an alert that triggers the automation runbook when the namespace **CPU usage** goes above **75%**.
118
137
119
138
1. On the **Service Bus Namespace** page for your namespace, select **Alerts** on the left menu, and then select **+ New alert rule** on the toolbar.
120
139
@@ -125,7 +144,7 @@ Now, create an alert on the namespace for a metric and tie it to the automation
125
144
3. On the **Configure signal logic** page, select **CPU** for the signal.
126
145
127
146

128
-
4. Enter a **threshold value** (in this example, it's 75%), and select **Done**.
147
+
4. Enter a **threshold value** (in this example, it's **75%**), and select **Done**.
129
148
130
149

131
150
5. Now, on the **Create alert page**, click **Select action group**.
@@ -143,24 +162,18 @@ Now, create an alert on the namespace for a metric and tie it to the automation
143
162
1. Enter a **name for the action**. For example: **Increase messaging units**.
144
163
2. For **Action type**, select **Automation Runbook**.
145
164
3. On the **Configure Runbook** page, do the following steps:
146
-
1. For **Runbook source**, select **User**.
147
-
2. For **Subscription**, select your Azure **subscription** that contains the automation account.
148
-
3. For **Automation account**, select your **automation account**.
149
-
4. For **Runbook**, select your runbook.
150
-
5. Select **OK** on the **Configure Runbook** page.
151
-
6. Select **OK** on the **Add action group** page.
Now, when the namespace CPU usage is above 75, the alert triggers the automation runbook, which increases the messaging units of the Service Bus namespace. Similarly, you can create an alert for another automation runbook, which decreases the messaging units if the CPU usage is below 25.
175
+
> [!NOTE]
176
+
> Now, when the namespace CPU usage goes above 75, the alert triggers the automation runbook, which increases messaging units of the Service Bus namespace. Similarly, you can create an alert for another automation runbook, which decreases the messaging units if the namespace CPU usage goes below 25.
160
177
161
178
## Next steps
162
-
To learn more about Service Bus messaging, see the following topics.
163
-
164
-
- [Service Bus queues, topics, and subscriptions](service-bus-queues-topics-subscriptions.md)
165
-
- [Get started with Service Bus queues](service-bus-dotnet-get-started-with-queues.md)
166
-
- [How to use Service Bus topics and subscriptions](service-bus-dotnet-how-to-use-topics-subscriptions.md)
179
+
To learn about messaging units, see the [Premium messaging](service-bus-premium-messaging.md)
0 commit comments