Azure Virtual Machine auto-shutdown

image

A few months ago I wrote this post https://blogs.msdn.microsoft.com/uk_faculty_connection/2017/03/31/if-your-not-using-your-infrastructure-turn-if-off-saving-costs-on-azure-2/ and this post where I share the top 8 tips for saving your Azure Account $/£ see https://blogs.msdn.microsoft.com/uk_faculty_connection/2017/07/07/tips-and-tricks-to-save-money-when-using-azure/

In this post I just want to focus on the methods available to auto-shutdown VMs within Azure.

Using Auto-Shutdown within Portal.Azure.com

This is available to all the ARM-based Azure VMs.

With this feature, setting auto-shutdown can’t be easier simply select the auto-shutdown time and Time Zone in https://portal.azure.com 

image

  • Go to your VM blade in Azure portal.
  • Click Auto-shutdown in the resource menu on the left-side.
  • You will see an auto-shutdown settings page expanded, where you can specify the auto-shutdown time and time zone. You can also configure to send notification to your webhook URL 15 minutes before auto-shutdown. This post illustrates how you can set up an Azure logic app to send auto-shutdown notification.

Azure Automation with Power Shell

Azure automation by creating a PowerShell script which reads from the Azure metrics API. For more details see https://docs.microsoft.com/en-us/azure/automation/automation-scenario-start-stop-vm-wjson-tags At some point you would call the  Virtual Machines API at the right time (and optionally send a notification)  https://codehollow.com/2016/07/automatically-shutdown-virtual-machines-azure/

VMPower

Using 3rd party software such as VMPower. It allows you to set Azure VMs to shutdown based on CPU, Disk, and Network utilization average or maximum values. It also handles sending your team notifications via email and Slack see https://blogs.msdn.microsoft.com/stevenedouard/2017/01/25/how-to-schedule-azure-vm-shutdown-based-on-cpu-disk-network-usage/

Stop Azure Virtual Machine using Azure Automation Runbook

Demonstrates stopping all Microsoft Azure Virtual Machine in a specific Azure subscription. The script could be associated with the new Azure Automation Scheduler to stop Virtual Machines at specific time. Great for developers for saving on Azure Compute, if they forget to shut.

Please refer to the following articles for using JSON based templates for managing machines.

Azure Automation – Using JSON formatted tags to create a week schedule for virtual machine start-up and shutdown with Azure Automation Runbooks

Azure Automation scenario: Using JSON-formatted tags to create a schedule for Azure VM start-up and shutdown

Example from TechNet script gallery https://gallery.technet.microsoft.com/scriptcenter/Stop-Azure-Virtual-Machine-0b1fea97/view/Discussions

Azure Automation for Scheduled Start-up and Shutdown of ARM Virtual Machines template on GitHub

https://github.com/ratchetnclank/Invoke-Autoshutdown

If your interested in contributing to Open Source Projects the following may be of interest

https://github.com/blndev/azure-vm-costsaver

Resources

https://blogs.msdn.microsoft.com/uk_faculty_connection/2016/11/23/saving-your-azure-by-auto-shutting-down-your-services/

https://blogs.msdn.microsoft.com/uk_faculty_connection/2016/09/09/utilising-microsoft-data-science-virtual-machine-dsvm-for-your-labs/

https://blogs.msdn.microsoft.com/uk_faculty_connection/2017/03/31/if-your-not-using-your-infrastructure-turn-if-off-saving-costs-on-azure-2/

https://blogs.msdn.microsoft.com/uk_faculty_connection/2017/07/07/tips-and-tricks-to-save-money-when-using-azure/