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
description: Configure autoscale for a Virtal Machine Scale Set using PowerShell
3
+
description: Configure autoscale for a Virtual Machine Scale Set using PowerShell
4
4
author: EdB-MSFT
5
5
ms.author: edbaynash
6
6
ms.topic: how-to
@@ -14,27 +14,28 @@ ms.reviewer: akkumari
14
14
15
15
# Configure autoscale with PowerShell
16
16
17
-
Autoscale settings help ensure that you have the right amount of resources running to handle the fluctuating load of your application. You can configure autoscale using the Azure portal, Azure CLI, PowerShell or ARM or Bicep templates.
17
+
Autoscale settings help ensure that you have the right amount of resources running to handle the fluctuating load of your application. You can configure autoscale using the Azure portal, Azure CLI, PowerShell or ARM or Bicep templates.
18
18
19
-
This article shows you how to configure autoscale for a Virtual Machine Scale Set using Powershell using the following steps:
19
+
This article shows you how to configure autoscale for a Virtual Machine Scale Set with PowerShell, using the following steps:
20
20
+ Create a scale set that you can autoscale
21
21
+ Create rules to scale in and scale out
22
22
+ Create a profile that uses your rules
23
23
+ Apply the autoscale settings
24
24
+ Update your autoscale settings with notifications
25
25
26
-
## Prerequisites
26
+
## Prerequisites
27
27
28
28
To configure autoscale using PowerShell, you need an Azure account with an active subscription. You can [create an account for free](https://azure.microsoft.com/free).
29
29
30
30
31
31
## Create a Virtual Machine Scale Set
32
32
33
-
Create a scale set using the following cmdlets
33
+
Create a scale set using the following cmdlets. Set the `$resourceGroupName` and `$vmssName` variables to suite your environment.
34
34
35
35
```azurepowershell
36
36
#Set the VMSS name and resource group name
37
37
38
+
$subscriptionId = (Get-AzContext).Subscription.Id
38
39
$resourceGroupName="rg-powershell-autoscale"
39
40
$vmssName="vmss-001"
40
41
@@ -55,12 +56,12 @@ New-AzVmss `
55
56
-SubnetName "mySubnet" `
56
57
-PublicIpAddressName "myPublicIPAddress" `
57
58
-LoadBalancerName "myLoadBalancer" `
58
-
-UpgradePolicyMode "Automatic" `
59
+
-UpgradePolicyMode "Automatic"
59
60
```
60
61
61
62
## Create autoscale settings
62
63
63
-
To create autoscale setting using Powershell, follow the sequence below:
64
+
To create autoscale setting using PowerShell, follow the sequence below:
64
65
65
66
1. Create rules using `New-AzAutoscaleScaleRuleObject`
66
67
1. Create a profile using `New-AzAutoscaleProfileObject`
@@ -71,7 +72,7 @@ To create autoscale setting using Powershell, follow the sequence below:
71
72
Create scale in and scale out rules then associated them with a profile.
72
73
Rules are created using the [`New-AzAutoscaleScaleRuleObject`](https://learn.microsoft.com/powershell/module/az.monitor/new-azautoscalescaleruleobject).
73
74
74
-
The following Powershell script created two rules.
75
+
The following PowerShell script created two rules.
|`MetricTriggerMetricName` |Sets the autoscale trigger metric
119
-
|`MetricTriggerMetricResourceUri`| Specifies the resource that the `MetricTriggerMetricName` metric belongs to. `MetricTriggerMetricResourceUri` can be any resource and not just the resource that is being scaled. For example, you can scale your VMSS based on metrics created by a load balancer, database, or the VMSS itself. The `MetricTriggerMetricName` must exist for the specified `MetricTriggerMetricResourceUri`.
120
+
|`MetricTriggerMetricResourceUri`| Specifies the resource that the `MetricTriggerMetricName` metric belongs to. `MetricTriggerMetricResourceUri` can be any resource and not just the resource that's being scaled. For example, you can scale your VMSS based on metrics created by a load balancer, database, or the VMSS itself. The `MetricTriggerMetricName` must exist for the specified `MetricTriggerMetricResourceUri`.
120
121
|`MetricTriggerTimeGrain`|The sampling frequency of the metric that the rule monitors. `MetricTriggerTimeGrain` must be one of the predefined values for the specified metric and must be between 12 hours and 1 minute. For example, `MetricTriggerTimeGrain` = *PT1M*"* means that the metrics are sampled every 1 minute and aggregated using the aggregation method specified in `MetricTriggerStatistic`.
121
-
|`MetricTriggerTimeAggregation` | The aggregation method within the timeGrain period. For example, statistic = "Average" and timeGrain = "PT1M" means that the metrics will be aggregated every 1 minute by taking the average.
122
-
|`MetricTriggerStatistic` |The aggregation method used to aggregate the sampled metrics. For example, TimeAggregation = "Average" will aggregate the sampled metrics by taking the average.
123
-
|`MetricTriggerTimeWindow` | The amount of time that the autoscale engine looks back to aggregate the metric. This value must be greater than the delay in metric collection, which varies by resource. It must be between 5 minutes and 12 hours. For example, 10 minutes means that every time autoscale runs, it queries metrics for the past 10 minutes. This allows your metrics to stabilize and avoids reacting to transient spikes.
122
+
|`MetricTriggerTimeAggregation` | The aggregation method within the timeGrain period. For example, statistic = "Average" and timeGrain = "PT1M" means that the metrics are aggregated every 1 minute by taking the average.
123
+
|`MetricTriggerStatistic` |The aggregation method used to aggregate the sampled metrics. For example, TimeAggregation = "Average" aggregates the sampled metrics by taking the average.
124
+
|`MetricTriggerTimeWindow` | The amount of time that the autoscale engine looks back to aggregate the metric. This value must be greater than the delay in metric collection, which varies by resource. It must be between 5 minutes and 12 hours. For example, 10 minutes means that every time autoscale runs, it queries metrics for the past 10 minutes. This feature allows your metrics to stabilize and avoids reacting to transient spikes.
124
125
|`MetricTriggerThreshold`|Defines the value of the metric that triggers a scale event.
125
126
|`MetricTriggerOperator` |Specifies the logical comparative operating to use when evaluating the metric value.
126
-
|`MetricTriggerDividePerInstance`| When set to `true` divides the trigger metric by the total number of instances. Gor example, If message count is 300 and there are 5 instances running, the calculated metric value is 60 messages per instance. This property isn't applicable for all metrics.
127
+
|`MetricTriggerDividePerInstance`| When set to `true` divides the trigger metric by the total number of instances. For example, If message count is 300 and there are 5 instances running, the calculated metric value is 60 messages per instance. This property isn't applicable for all metrics.
127
128
| `ScaleActionDirection`| Specify scaling in or out. Valid values are `Increase` and `Decrease`.
128
-
|`ScaleActionType` |Scale by a number of instances, to a specific instance count, or by percentage of the current instance count. Valid value include `ChangeCount`, `ExactCount`, and `PercentChangeCount`.
129
+
|`ScaleActionType` |Scale by a number of instances, to a specific instance count, or by percentage of the current instance count. Valid values include `ChangeCount`, `ExactCount`, and `PercentChangeCount`.
129
130
|`ScaleActionCooldown`| The minimum amount of time to wait between scale operations. This is to allow the metrics to stabilize and avoids [flapping](./autoscale-flapping.md). For example, if `ScaleActionCooldown` is 10 minutes and a scale operation just occurred, Autoscale won't attempt to scale again for 10 minutes.
130
131
131
132
132
-
### Create an autoscale profile and associate the rules
133
+
### Create a default autoscale profile and associate the rules
133
134
134
-
After defining the scale rules, create a profile. The profile specifies the default, upper, and lower instance count limits, and the times that the associated rules can be applied. Use the [`New-AzAutoscaleProfileObject`](https://learn.microsoft.com/powershell/module/az.monitor/new-azautoscaleprofileobject) cmdlet to create a new autoscale profile.
135
+
After defining the scale rules, create a profile. The profile specifies the default, upper, and lower instance count limits, and the times that the associated rules can be applied. Use the [`New-AzAutoscaleProfileObject`](https://learn.microsoft.com/powershell/module/az.monitor/new-azautoscaleprofileobject) cmdlet to create a new autoscale profile. As this is a default profile, it doesn't have any schedule parameters. The default profile is active at times that no other profiles are active
135
136
136
137
```azurepowershell
137
-
$profile1=New-AzAutoscaleProfileObject `
138
-
-Name "profile1" `
138
+
$defaultProfile=New-AzAutoscaleProfileObject `
139
+
-Name "default" `
139
140
-CapacityDefault 1 `
140
141
-CapacityMaximum 10 `
141
142
-CapacityMinimum 1 `
142
-
-RecurrenceFrequency week `
143
-
-ScheduleDay "Wednesday","Friday" `
144
-
-ScheduleHour 7 `
145
-
-ScheduleMinute 00 `
146
-
-ScheduleTimeZone "Pacific Standard Time" `
147
143
-Rule $rule1, $rule2
148
144
```
149
145
150
146
Parameters
151
147
152
148
|Parameter|Description|
153
149
|---|---|
154
-
|`CapacityDefault`| The number of instances that will be set if metrics are not available for evaluation. The default is only used if the current instance count is lower than the default.
150
+
|`CapacityDefault`| The number of instances that are if metrics aren't available for evaluation. The default is only used if the current instance count is lower than the default.
155
151
| `CapacityMaximum` |The maximum number of instances for the resource. The maximum number of instances is further limited by the number of cores that are available in the subscription.
156
152
| `CapacityMinimum` |The minimum number of instances for the resource.
157
153
|`FixedDateEnd`| The end time for the profile in ISO 8601 format for.
158
154
|`FixedDateStart` |The start time for the profile in ISO 8601 format.
159
155
| `Rule` |A collection of rules that provide the triggers and parameters for the scaling action when this profile is active. A maximum of 10, comma separated rules can be specified.
160
156
|`RecurrenceFrequency` | How often the scheduled profile takes effect. This value must be `week`.
161
-
|`ScheduleDay`| A collection of days that the profile takes effect on when specifying a recurring schedule. Possible values are Sunday through Saturday. For more information on recurring schedules see [Add a recurring profile using CLI](./autoscale-multiprofile.md?tabs=powershell#add-a-recurring-profile-using-powershell)
157
+
|`ScheduleDay`| A collection of days that the profile takes effect on when specifying a recurring schedule. Possible values are Sunday through Saturday. For more information on recurring schedules, see [Add a recurring profile using CLI](./autoscale-multiprofile.md?tabs=powershell#add-a-recurring-profile-using-powershell)
162
158
|`ScheduleHour`| A collection of hours that the profile takes effect on. Values supported are 0 to 23.
163
-
|`ScheduleMinute`| A collection of minutes at which the profile takes effect at.
159
+
|`ScheduleMinute`| A collection of minutes at which the profile takes effect.
164
160
|`ScheduleTimeZone` |The timezone for the hours of the profile.
165
161
166
-
### Apply the autoscle settings
162
+
### Apply the autoscale settings
167
163
168
-
After fining the rules and profile, apply the autoscale settings using [`New-AzAutoscaleSetting`](https://learn.microsoft.com/powershell/module/az.monitor/new-azautoscalesetting). To update existing autoscale setting use [`AzAutoscaleSetting`](https://learn.microsoft.com/powershell/module/az.monitor/add-azautoscalesetting)
164
+
After fining the rules and profile, apply the autoscale settings using [`New-AzAutoscaleSetting`](https://learn.microsoft.com/powershell/module/az.monitor/new-azautoscalesetting). To update existing autoscale setting use [`Update-AzAutoscaleSetting`](https://learn.microsoft.com/powershell/module/az.monitor/add-azautoscalesetting)
Add notifications to your sale setting to trigger a webhook or send email notifications when a scale event occurs.
185
180
For more information on webhook notifications, see [`New-AzAutoscaleWebhookNotificationObject`](https://learn.microsoft.com/powershell/module/az.monitor/new-azautoscalewebhooknotificationobject)
Set up autoscale profiles to scale differently for specific events. For example, for a day when demand will be higher than usual, create a profile with increased maximum and minimum instance limits.
231
+
232
+
The following example uses the same rules as the default profile defined above, but sets new instance limits for a specific date. You can also configure different rules to be used with the new profile.
Recurring profiles let you schedule a scaling profile that repeats each week. For example, scale to a single instance on the weekend from Friday night to Monday morning.
257
+
258
+
While scheduled profiles have a start and end date, recurring profiles don't have an end time. The profile remains active until another profile becomes active. You must therefore create recurring default profile to start when you want the previous recurring profile to finish.
259
+
For example, to configure a weekend profile that starts on Friday nights and ends on Monday mornings, create one profile that starts on Friday night, and a copy of the default profile that starts on Monday morning.
260
+
261
+
The following script creates a weekend profile and an addition default profile to end the weekend profile.
262
+
```azurepowershell
263
+
$fridayProfile=New-AzAutoscaleProfileObject `
264
+
-Name "Weekend" `
265
+
-CapacityDefault 1 `
266
+
-CapacityMaximum 1 `
267
+
-CapacityMinimum 1 `
268
+
-RecurrenceFrequency week `
269
+
-ScheduleDay "Friday" `
270
+
-ScheduleHour 22 `
271
+
-ScheduleMinute 00 `
272
+
-ScheduleTimeZone "Pacific Standard Time" `
273
+
-Rule $rule1, $rule2
232
274
233
-
For a complete list of PowerShell cmdlets for autoscale, see the [Poweshell Module Browser](https://learn.microsoft.com/powershell/module/?term=azautoscale)
For a complete list of PowerShell cmdlets for autoscale, see the [PowerShell Module Browser](https://learn.microsoft.com/powershell/module/?term=azautoscale)
236
300
237
301
## Clean up resources
238
302
239
-
To cleanup the resources you created in this tutorial delete the resource group that you created.
303
+
To clean up the resources you created in this tutorial, delete the resource group that you created.
240
304
The following cmdlet deletes the resource group and all of its resources.
0 commit comments