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
4
4
author: EdB-MSFT
5
5
ms.author: edbaynash
@@ -16,19 +16,19 @@ Benefits of using Poowershell to configurye autoscale
16
16
Prereqs
17
17
- give powershell to create VMSS ? ( how do they create load ?)
18
18
- Windows or linux ? ( linux)
19
-
- provide a vm image ? (git, galery ? which user owns it ?)
19
+
- provide a vm image ? (git, galery ? which user owns it ?)
20
20
- assume VMSS exists ?
21
21
- create an image - too complicated
22
22
23
23
Define the scenario
24
-
scripts to create the objects.
24
+
scripts to create the objects.
25
25
For each Object define what is required with example
26
26
27
27
28
28
---
29
29
30
30
# Configure autoscale with PowerShell
31
-
31
+
32
32
Autoscale settings help ensure that you have the right amount of resources running to handle the fluctuating load of your application.Cyou can configure autoscale using the Azure portal, Azure CLI, PowerShell or ARM or Bicep templates.
33
33
34
34
This article shows you haw to configure autoscale for a Virtual Machine Scale Set using Powershell
@@ -52,11 +52,13 @@ Create a scale set using the following commands
@@ -97,19 +88,19 @@ To create autoscale setting using Powershell, follow the sequence below:
97
88
Create scale in and scale out rules then associated them with a profile.
98
89
Rules are created using the [`New-AzAutoscaleScaleRuleObject`](https://learn.microsoft.com/powershell/module/az.monitor/new-azautoscalescaleruleobject).
99
90
100
-
The wolloing Powershell script created two rules.
91
+
The following Powershell script created two rules.
Set the autoscale trigger metric using `MetricTriggerMetricName` and `MetricTriggerMetricResourceUri`. The `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`.
145
-
146
-
`MetricTriggerTimeGrain` is 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`.
147
-
148
-
`MetricTriggerTimeAggregation` is 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.
149
-
150
-
`MetricTriggerStatistic` is the aggregation method used to aggregate the sampled metrics. For example, TimeAggregation = "Average" will aggregate the sampled metrics by taking the average.
151
-
152
-
`MetricTriggerTimeWindow` is 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.
153
-
154
-
`MetricTriggerThreshold` defines the value of the metric that triggers a scale event.
155
-
156
-
`MetricTriggerOperator` specifies the logical comparative operating to use when evaluating the metric value.
157
-
158
-
`MetricTriggerDividePerInstance`, when st 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.
159
-
160
-
Specify scaling in or out using `ScaleActionDirection`. Valid values are *Increase* and *Decrease*
161
-
162
-
Use `ScaleActionType` to scale by a number of instance, to a specific instance count, or by percentage of the current instance count. Valid value include `ChangeCount`, `ExactCount`, and `PercentChangeCount`.
163
-
164
-
`ScaleActionValue` spefices the value of the `ScaleActionType` to scale the reource by, for example, When `ScaleActionType` is *PercentChangeCount* setting `ScaleActionValue` to *50* scales the resource by 50% of the current instance count.
165
-
166
-
`ScaleActionCooldown` is the minimum amount of time to wait between scale operations. This is to allow the metrics to stabilize and avoiuds [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.
133
+
|Parameter| Description|
134
+
|---|---|
135
+
|`MetricTriggerMetricName` |Sets the autoscale trigger metric
136
+
|`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`.
137
+
|`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`.
138
+
|`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.
139
+
|`MetricTriggerStatistic` |The aggregation method used to aggregate the sampled metrics. For example, TimeAggregation = "Average" will aggregate the sampled metrics by taking the average.
140
+
|`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.
141
+
|`MetricTriggerThreshold`|Defines the value of the metric that triggers a scale event.
142
+
|`MetricTriggerOperator` |Specifies the logical comparative operating to use when evaluating the metric value.
143
+
|`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.
144
+
| `ScaleActionDirection`| Specify scaling in or out. Valid values are `Increase` and `Decrease`.
145
+
|`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`.
146
+
|`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.
167
147
168
148
169
149
### Create an autoscale profile and associate the rules
170
150
171
151
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 thew [`New-AzAutoscaleProfileObject`](https://learn.microsoft.com/powershell/module/az.monitor/new-azautoscaleprofileobject) command to create a new autoscale profile.
the start time for the profile in ISO 8601 format.
189
-
-`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.
190
-
-`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.
191
-
-`CapacityMinimum` the minimum number of instances for the resource.
192
-
-`FixedDateEnd` the end time for the profile in ISO 8601 format.
193
-
-`FixedDateStart` the start time for the profile in ISO 8601 format.
194
-
-`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.
195
-
-`RecurrenceFrequency` How often the scheduled profile takes effect. This value must be *week*.
196
-
-`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)
197
-
-`ScheduleHour` A collection of hours that the profile takes effect on. Values supported are 0 to 23.
198
-
-`ScheduleMinute` A collection of minutes at which the profile takes effect at.
199
-
-`ScheduleTimeZone` The timezone for the hours of the profile.
167
+
|Parameter| Description|
168
+
|---|---|
169
+
|`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.
170
+
| `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.
171
+
| `CapacityMinimum` |The minimum number of instances for the resource.
172
+
|`FixedDateEnd`| The end time for the profile in ISO 8601 format for.
173
+
|`FixedDateStart` |The start time for the profile in ISO 8601 format.
174
+
| `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.
175
+
|`RecurrenceFrequency` | How often the scheduled profile takes effect. This value must be `week`.
176
+
|`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)
177
+
|`ScheduleHour`| A collection of hours that the profile takes effect on. Values supported are 0 to 23.
178
+
|`ScheduleMinute`| A collection of minutes at which the profile takes effect at.
179
+
|`ScheduleTimeZone` |The timezone for the hours of the profile.
180
+
181
+
### Apply the autoscle settings
182
+
183
+
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)
Add notifications to your sale setting to trigger a webhook or send email notifications when a scale event occurs.
200
+
For more information on webhook notifications, see [`New-AzAutoscaleWebhookNotificationObject`](https://learn.microsoft.com/powershell/module/az.monitor/new-azautoscalewebhooknotificationobject)
Configure the notification using the webhook and set up email notification using the [`New-AzAutoscaleNotificationObject`](https://learn.microsoft.com/powershell/module/az.monitor/new-azautoscalenotificationobject) command:
0 commit comments