Skip to content

Commit 538db17

Browse files
committed
updated
1 parent 47ced96 commit 538db17

File tree

1 file changed

+41
-28
lines changed

1 file changed

+41
-28
lines changed

articles/service-bus-messaging/automate-update-messaging-units.md

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
title: Azure Service Bus - Automatically update messaging units
33
description: This article shows you how you can use an Azure Automation runbook to automatically update messaging units of a Service Bus namespace.
44
services: service-bus-messaging
5-
ms.service: service-bus-message
5+
6+
ms.service: service-bus-messaging
67
documentationcenter: ''
78
author: spelluru
89

@@ -13,10 +14,16 @@ ms.author: spelluru
1314
---
1415

1516
# 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%.
1723

1824
> [!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+
2027

2128
## Create a Service Bus namespace
2229
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
2532
Create an Azure Automation account by following instructions from the [Create an Azure Automation account](../automation/automation-quickstart-create-account.md) article.
2633

2734
## 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).
2938

3039
## Create and publish a PowerShell runbook
3140

3241
1. Create a PowerShell runbook by follow instructions in the [Create a PowerShell runbook](../automation/automation-quickstart-create-runbook.md) article.
3342

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.
3544

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.
3748

3849
```powershell
3950
[OutputType("PSAzureOperationResponse")]
@@ -55,14 +66,21 @@ Import `Az.Accounts` and `Az.ServiceBus` modules from the gallery into the autom
5566
# Get the data object from WebhookData
5667
$WebhookBody = (ConvertFrom-Json -InputObject $WebhookData.RequestBody)
5768
58-
# Get the info needed to identify the VM (depends on the payload schema)
69+
# Get the alert schema ID
5970
$schemaId = $WebhookBody.schemaId
71+
72+
# If it's a metric alert
6073
if ($schemaId -eq "AzureMonitorMetricAlert") {
74+
75+
# Get the resource group name from the alert context
6176
$resourceGroupName = $AlertContext.resourceGroupName
77+
78+
# Get the namespace name from the alert context
6279
$namespaceName = $AlertContext.resourceName
6380
}
6481
}
6582
83+
# Connect to Azure account
6684
$connection = Get-AutomationConnection -Name AzureRunAsConnection
6785
6886
while(!($connectionResult) -And ($logonAttempt -le 10))
@@ -85,6 +103,7 @@ Import `Az.Accounts` and `Az.ServiceBus` modules from the gallery into the autom
85103
86104
$currentCapacity = $sbusns.Sku.Capacity
87105
106+
# Increase the capacity
88107
# Capacity can be one of these values: 1, 2, 4, 8
89108
if ($currentCapacity -eq 1) {
90109
$newMU = 2
@@ -108,13 +127,13 @@ Import `Az.Accounts` and `Az.ServiceBus` modules from the gallery into the autom
108127
-ResourceGroupName $resourceGroupName
109128
110129
```
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.
113132
114133
## 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).
116135
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%**.
118137
119138
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.
120139
@@ -125,7 +144,7 @@ Now, create an alert on the namespace for a metric and tie it to the automation
125144
3. On the **Configure signal logic** page, select **CPU** for the signal.
126145
127146
![Configure signal logic - select CPU](./media/automate-update-messaging-units/configure-signal-logic.png)
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**.
129148
130149
![Configure CPU signal](./media/automate-update-messaging-units/cpu-signal-configuration.png)
131150
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
143162
1. Enter a **name for the action**. For example: **Increase messaging units**.
144163
2. For **Action type**, select **Automation Runbook**.
145164
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.
152-
153-
![Configure runbook](./media/automate-update-messaging-units/configure-runbook.png)
154-
165+
1. For **Runbook source**, select **User**.
166+
2. For **Subscription**, select your Azure **subscription** that contains the automation account.
167+
3. For **Automation account**, select your **automation account**.
168+
4. For **Runbook**, select your runbook.
169+
5. Select **OK** on the **Configure Runbook** page.
170+
6. Select **OK** on the **Add action group** page.
171+
![Configure runbook](./media/automate-update-messaging-units/configure-runbook.png)
155172
5. Now, on the **Create alert rule** page, enter a **name for the rule**, and then select **Create alert rule**.
156-
157173
![Create alert rule](./media/automate-update-messaging-units/create-alert-rule.png)
158174
159-
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.
160177
161178
## 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

Comments
 (0)