This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
10-create-autoscaler.bat
60 lines (51 loc) · 2.39 KB
/
10-create-autoscaler.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@echo off
REM #############################################################################################
REM # Ensure you have logged in to Azure with your credentials prior to running this script
REM # az login
REM # Ensure that you have the Azure subscription ID, it should show up after you have logged in and it has the format:
REM # "id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
REM # Ensure that you have a virtual machine scale set already in place
REM #############################################################################################
REM #############################################################################################
REM # General variables used in the different Azure CLI commands run from this script
SET YOURSUBSCRIPTIONID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
SET RESOURCEGROUPNAME=myResourceGroup
SET REGIONNAME=japanwest
SET PREFIX=myGameBackend
REM # Variables for setting up the virtual machine scale set autoscaler
SET VMSSNAME=%PREFIX%VMSS
SET VMSSVMTOCREATE=2
SET VMSSAUTOSCALERNAME=%PREFIX%Autoscaler
SET VMSSAUTOSCALERCRITERIA=Percentage CPU
SET VMSSAUTOSCALERMAXCOUNT=10
SET VMSSAUTOSCALERMINCOUNT=%VMSSVMTOCREATE%
SET VMSSAUTOSCALERUPTRIGGER=50 avg 5m
SET VMSSAUTOSCALERDOWNTRIGGER=30 avg 5m
SET VMSSAUTOSCALEROUTINCREASE=1
SET VMSSAUTOSCALERINDECREASE=1
REM #############################################################################################
REM # Connect to Azure
CALL az login
REM # Set the Azure subscription
CALL az account set --subscription %YOURSUBSCRIPTIONID%
ECHO Defining the autoscaling profile
CALL az monitor autoscale create ^
--resource-group %RESOURCEGROUPNAME% ^
--resource %VMSSNAME% ^
--resource-type Microsoft.Compute/virtualMachineScaleSets ^
--name %VMSSAUTOSCALERNAME% ^
--min-count %VMSSAUTOSCALERMINCOUNT% ^
--max-count %VMSSAUTOSCALERMAXCOUNT% ^
--count %VMSSVMTOCREATE%
ECHO Enabling virtual machine autoscaler for scaling out
CALL az monitor autoscale rule create ^
--resource-group %RESOURCEGROUPNAME% ^
--autoscale-name %VMSSAUTOSCALERNAME% ^
--condition "%VMSSAUTOSCALERCRITERIA% > %VMSSAUTOSCALERUPTRIGGER%" ^
--scale out %VMSSAUTOSCALEROUTINCREASE%
ECHO Enabling virtual machine autoscaler for scaling in
CALL az monitor autoscale rule create ^
--resource-group %RESOURCEGROUPNAME% ^
--autoscale-name %VMSSAUTOSCALERNAME% ^
--condition "%VMSSAUTOSCALERCRITERIA% < %VMSSAUTOSCALERDOWNTRIGGER%" ^
--scale in %VMSSAUTOSCALERINDECREASE%