Vertically scale Windows VMs with Azure Automation
Vertical scaling is the process of increasing or decreasing the resources of a machine in response to the workload. In Azure this can be accomplished by changing the size of the Virtual Machine. This can help in the following scenarios
- If the Virtual Machine is not being used frequently, you can resize it down to a smaller size to reduce your monthly costs
- If the Virtual Machine is seeing a peak load, it can be resized to a larger size to increase its capacity
The outline for the steps to accomplish this is as below
- Setup Azure Automation to access your Virtual Machines
- Import the Azure Automation Vertical Scale runbooks into your subscription
- Add a webhook to your runbook
- Add an alert to your Virtual Machine
Because of the size of the first Virtual Machine, the sizes it can be scaled to, may be limited due to the availability of the other sizes in the cluster current Virtual Machine is deployed in. In the published automation runbooks used in this article we take care of this case and only scale within the below VM size pairs. This means that a Standard_D1v2 Virtual Machine will not suddenly be scaled up to Standard_G5 or scaled down to Basic_A0.
|VM sizes scaling pair|
Setup Azure Automation to access your Virtual Machines
The first thing you need to do is create an Azure Automation account that will host the runbooks used to scale a Virtual Machine. Recently the Automation service introduced the "Run As account" feature which makes setting up the Service Principal for automatically running the runbooks on the user's behalf very easy. You can read more about this in the article below:
Import the Azure Automation Vertical Scale runbooks into your subscription
The runbooks that are needed for Vertically Scaling your Virtual Machine are already published in the Azure Automation Runbook Gallery. You will need to import them into your subscription. You can learn how to import runbooks by reading the following article.
The runbooks that need to be imported are shown in the image below
Add a webhook to your runbook
Once you've imported the runbooks you'll need to add a webhook to the runbook so it can be triggered by an alert from a Virtual Machine. The details of creating a webhook for your Runbook can be read here
Make sure you copy the webhook before closing the webhook dialog as you will need this in the next section.
Add an alert to your Virtual Machine
- Select Virtual Machine settings
- Select "Alert rules"
- Select "Add alert"
- Select a metric to fire the alert on
- Select a condition, which when fulfilled will cause the alert to fire
- Select a threshold for the condition in Step 5. to be fulfilled
- Select a period over which the monitoring service will check for the condition and threshold in Steps 5 & 6
- Paste in the webhook you copied from the previous section.
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.