Auto-scaling/resizing for Azure Virtual Machines without PowerShell

If you are interested in shutting down Azure VMs on a schedule, learn more here.  If shutting down a VM during non-busy hours is impractical, consider scaling it down in power.

In this tutorial, we are going to learn how to Scale/Resize (up or down) cloud-based Microsoft Azure Virtual Machines on a schedule.  The process takes about 1-2 minutes and is easily replicable to any and all VMs in your Azure subscription in just a few minutes more.  It works for Windows and Linux VMs and does not rely on somewhat complex and hard to maintain PowerShell scripts or Azure Automation runbooks.  Also, if any errors occur during execution of scale commands, you will get an immediate notification.

Scheduling scaling of your VMs allows you to save money on Azure costs.  A scaled-down VM incurs lowered Azure charges  This can be beneficial for DEV/QA and other non-production environments, CI/build servers, or for production environments where optimal access to VMs is required only during specific times.  Consider an example: a CI/SourceCode build server must be very powerful during the day time to assist development team with continuous builds after frequent checkins.  However, during the night hours, it can be scaled down in size to support occasional checkins from few developers who are working late.

Step 1 – Get a CloudMonix Account

You will need a CloudMonix account.  If you have not yet registered, do so here.  CloudMonix is a sophisticated monitoring and automation software-as-a-service for Azure.  By using CloudMonix, you’ll have access to a ton of useful performance metrics, logs, alerts, integrations, and other automation features.  While during the 2-week trial period everything in CloudMonix is free, after the trial expires, automated VM Resizing will only be available for users of CloudMonix’s Ultimate plan.  Many companies easily justify the relatively inexpensive cost of CloudMonix by configuring it to power-down or scale-down their unused VMs.

Technical considerations to note: when a VM is resized, it is rebooted.  VM resizing is not recommended for stand-alone servers that need to remain up 24/7.  It is recommended that such servers be a part of multi-server Availability Sets, so that reboots in one server do not cause the whole availability set to be down.

Resizing a VM does not cause any change to OS or underlying data.  It is simply rebooted with more or less power allocated to it by Azure platform.

Step 2 – Connect CloudMonix to your Azure Subscription

Ensure that your Azure Virtual Machines have been added to CloudMonix account.  Simplest way to do so is to run thru the CloudMonix Setup Wizard.  It takes a few minutes and it is very intuitive and straightforward.

CloudMonix Setup Wizard

CloudMonix Setup Wizard

Step 3 – Define Resize Up and Resize Down actions to execute at specific times

After Wizard completes, edit the monitoring definition of a particular Azure VM and on the Actions tab and define two actions; one to resize UP and one to resize DOWN a VM at specific times.  In detail:

  • Bring up an Edit dialog for a specific Azure VM from CloudMonix dashboard
  • On the Actions tab, add a new action.  This will be the action to Resize DOWN the VM at a specific time
  • Specify Name and Severity of the action
  • Ensure that Action execution is based on a Schedule instead of an Expression
  • Define a Start time of the action by creating a new Schedule entry of type Action Execution (keep in mind that the start time is defined in UTC). Schedule setup is quiet flexible and has many more scheduling options than Azure’s native Scheduler.
    Defining the start time for action to execute on
  • Execution target should remain as “Self”
  • Execution Command should be “AzureVmInstanceResize”.  Choose the target size of the VM
  • Keep in mind that CloudMonix will also send out alerts in case of either success or failure of action execution
  • Save and Done.
  • Now rinse and repeat this process to create a similar Resize UP action.  Use “AzureVmInstanceResize” command with a different target size and a different time schedule.
  • Since the Schedule setup is quiet flexible, you are able to create any number of Resize UP and DOWN actions under a single resource to accommodate different schedules for weekdays and weekends, specific weeks of the month, etc.
    CloudMonix action definition to shutdown Azure VM on a schedule

 

Step 4 (Optional) – Automate other Virtual Machines quickly

Configuring other VMs to scale on the same schedule is a fairly trivial task in CloudMonix.

  • Save the configuration of configured VM as a “Template”
  • Navigate to Resource Templates screen under Account Settings and open the previously saved Template
  • “Push” the ResizeUp or ResizeDown actions any other VMs in your monitored setup
    Copying Start/Stop actions to other VMs