Skip to content

Commit 1606f29

Browse files
committed
added Powershel
1 parent c7b7e2f commit 1606f29

File tree

1 file changed

+59
-2
lines changed

1 file changed

+59
-2
lines changed

articles/azure-monitor/autoscale/autoscale-multiprofile.md

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ms.reviewer: akkumari
1717

1818
Scaling your resources for a particular day of the week, or a specific date and time can reduce costs while still providing the capacity you need when you need it.
1919

20-
Use multiple profiles in autoscale to scale in different ways at different times. If for example, your business isn't active on the weekend, create a recurring profile to scale back your resources on Saturdays and Sundays.
20+
Use multiple profiles in autoscale to scale in different ways at different times. If for example, your business isn't active on the weekend, create a recurring profile to scale in your resources on Saturdays and Sundays. If black Friday is a busy day, create a profile to automatically scale out your resources on black Friday.
2121

2222
This article explains the different profiles in autoscale and how to use them.
2323

@@ -323,7 +323,7 @@ where `VMSS1-autoscale.json` is the the file containing the JSON object below.
323323

324324
## [CLI](#tab/cli)
325325

326-
The CLI can be used to create addition profiles in your autoscale settings.
326+
The CLI can be used to create multiple profiles in your autoscale settings.
327327

328328
The following steps show how to create an autoscale profile using the CLI.
329329
1. Create the profile using `az monitor autoscale profile create`. Specify the `--start` and `--end` time and the `--recurrence`
@@ -361,6 +361,63 @@ az monitor autoscale rule create -g rg-vmss1--autoscale-name VMSS1-Autoscale-607
361361
az monitor autoscale rule create -g rg-vmss1--autoscale-name VMSS1-Autoscale-607 --scale out 8 --condition "Percentage CPU > 52 avg 5m" --profile-name "{\"name\": \"Auto created default scale condition\", \"for\": \"Thursdays\"}"
362362
```
363363

364+
## [Powershell](#tab/powershell)
365+
366+
Powershell can be used to create multiple profiles in your autoscale settings.
367+
368+
The following steps show how to create an autoscale profile using Powershell.
369+
370+
1. Create rules using `New-AzAutoscaleRule`
371+
1. Create profiles using `New-AzAutoscaleProfile` using the rules from the previous step
372+
1. Use `Add-AzureRmAutoscaleSetting` to apply the profiles to your autoscale setting.
373+
374+
## Add a recurring profile using Powershell
375+
376+
The example below shows how to create default profile and a recurring autoscale profile, recurring on Wednesdays and Fridays between 07:00 and 19:00.
377+
The default profile uses the CpuIn and CpuOut Rules. The recurring profile uses the HTTPRuleIn and HTTPRuleOut rules
378+
379+
```azurepowershell
380+
$ResourceGroup="ed-rg-001"
381+
$TargetResourceId="/subscriptions/d0567c0b-5849-4a5d-a2eb-5267eae1bbc7/resourcegroups/ed-rg-001/providers/Microsoft.Web/serverFarms/ScaleableAppServicePlan"
382+
383+
$ScaleSettingName="MultipleProfiles-001"
384+
385+
$CpuOut = New-AzAutoscaleRule -MetricName "CpuPercentage" -MetricResourceId $TargetResourceId -Operator GreaterThan -MetricStatistic Average -Threshold 50 -TimeGrain 00:01:00 -ScaleActionCooldown 00:05:00 -ScaleActionDirection Increase -ScaleActionScaleType ChangeCount -ScaleActionValue "1"
386+
387+
$CpuIn = New-AzAutoscaleRule -MetricName "CpuPercentage" -MetricResourceId $TargetResourceId -Operator GreaterThan -MetricStatistic Average -Threshold 30 -TimeGrain 00:01:00 -ScaleActionCooldown 00:05:00 -ScaleActionDirection Decrease -ScaleActionScaleType ChangeCount -ScaleActionValue "1"
388+
389+
$DefaultProfile = New-AzAutoscaleProfile -DefaultCapacity "1" -MaximumCapacity "10" -MinimumCapacity "1" -Rule $CpuOut,$CpuIn -Name '{"name":"Default scale condition","for":"WednesdaysFridays"}' -RecurrenceFrequency week -ScheduleDay "Wednesday","Friday" -ScheduleHour 19 -ScheduleMinute 00 -ScheduleTimeZone "Pacific Standard Time"`
390+
391+
$HTTPRuleIn = New-AzAutoscaleRule -MetricName "HttpQueueLength" -MetricResourceId $TargetResourceId -Operator GreaterThan -MetricStatistic Average -Threshold 3 -TimeGrain 00:01:00 -ScaleActionCooldown 00:05:00 -ScaleActionDirection Decrease -ScaleActionScaleType ChangeCount -ScaleActionValue "1"
392+
393+
$HTTPRuleOut = New-AzAutoscaleRule -MetricName "HttpQueueLength" -MetricResourceId $TargetResourceId -Operator GreaterThan -MetricStatistic Average -Threshold 10 -TimeGrain 00:01:00 -ScaleActionCooldown 00:05:00 -ScaleActionDirection Increase -ScaleActionScaleType ChangeCount -ScaleActionValue "1"
394+
395+
$RecurringProfile=New-AzAutoscaleProfile -Name WednesdaysFridays -DefaultCapacity 2 -MaximumCapacity 12 -MinimumCapacity 2 -RecurrenceFrequency week -ScheduleDay "Wednesday","Friday" -ScheduleHour 7 -ScheduleMinute 00 -ScheduleTimeZone "Pacific Standard Time" -Rule $HTTPRuleOut, $HTTPRuleIn
396+
397+
Add-AzureRmAutoscaleSetting -Location "West Central US" -name $ScaleSettingName -ResourceGroup $ResourceGroup -TargetResourceId $TargetResourceId -AutoscaleProfile $DefaultProfile, $RecurringProfile
398+
```
399+
400+
> [!NOTE]
401+
> Each recurring profile must have a corresponding default profile.
402+
> The `-Name` parameter of the default profile is is an object in the format: `'{"name":"Default scale condition","for":"recurring profile"}'` where *recurring profile* is the profile name from the `New-AzAutoscaleProfile` command for the recurring profile.
403+
> The default profile also has a recurrence parameters as the recurring profile but it starts at the time you want the recurring profile to end.
404+
> A distinct default profile is created for each recurring profile.
405+
406+
## Updating the default profile when you have recurring profiles
407+
408+
If you have multiple recurring profiles and want to change your default profile, the change must be made to each default profile corresponding to a recurring profile.
409+
410+
For example, if you have two recurring profiles called *SundayProfile* and *ThursdayProfile*, you need two `New-AzAutoscaleProfile` commands to change to the default profile.
411+
412+
```azurepowershell
413+
414+
415+
$DefaultProfileSundayProfile = New-AzAutoscaleProfile -DefaultCapacity "1" -MaximumCapacity "10" -MinimumCapacity "1" -Rule $CpuOut,$CpuIn -Name '{"name":"Default scale condition","for":"SundayProfile"}' -RecurrenceFrequency week -ScheduleDay "Sunday" -ScheduleHour 19 -ScheduleMinute 00 -ScheduleTimeZone "Pacific Standard Time"`
416+
417+
418+
$DefaultProfileThursdayProfile = New-AzAutoscaleProfile -DefaultCapacity "1" -MaximumCapacity "10" -MinimumCapacity "1" -Rule $CpuOut,$CpuIn -Name '{"name":"Default scale condition","for":"ThursdayProfile"}' -RecurrenceFrequency week -ScheduleDay "Thursday" -ScheduleHour 19 -ScheduleMinute 00 -ScheduleTimeZone "Pacific Standard Time"`
419+
```
420+
364421
---
365422

366423
## Next steps

0 commit comments

Comments
 (0)