This blog posts consists of 3 parts:
- Automating the shut down process of your Azure VMs (virtual machines) as a backup for when we forget to do it
- Setting up reminders for Azure billing thresholds when it goes beyond a certain spend amount or usage
- Understanding what “shut down” does and doesn’t mean in Azure
A quick history on Windows Azure pricing. Until a few months ago, Azure billed for any Virtual Machine (VM) that was in your account, even if it was not running. To much ballyhoo, legions of Microsoft techies applauded the change to not charge you for a VM when it is “shut down”. This is a great feature if you do not need to have your machines always up and running (i.e., demos, test, dev), but the reality is we are all human and I have met countless people that at some point have forgotten to turn them off (I am the poster child for this particular issue unfortunately). I hope this article will help you with some proactive steps you can take to avoid any unfortunate billing issues occurring.
1. Automating the Shut Down Process / Shutting Down of Your Azure VMs (Virtual Machines) as a Backup for When We Forget to Turn Them Off
- AzureWatch – This is a 3rd party paid product I was told that can do this and only bills for the time your VMs are up and running
- Stopping your VMs via scheduled PowerShell task –Marc Klein (unsure of functionality success)
- Azure Commander – a new tool from Wictor Wilén that can restart Azure web sites, maintenance tasks for Virtual Machines, Web/Worker Roles & Azure Web Sites (Only available on Windows Phone or Windows Devices, not IoS or Android)
- Using Node.js to access the ShutDownRoleOperation to turn off your VMs
- PowerShell Script to Shut Down Cloud Service & VM (see bottom of page) – Jason Himmelstein
- Turning Off Your VM in Azure Via the Screen Saver Triggering a PowerShell Script – Estyn Edwards (I have not tried this, not sure if it would be 100% reliable or not but creative that it is!!!)
- Using the new Azure Automation feature & Runbooks – Thanks to Scott Hoag for letting me know about this 🙂
- *NEW 12-1-14 – There is a new feature called Batch Jobs that is current in preview. I have not had time to explore this in depth but if you looking for a way to bring up VMs and bring them down programmatically this might be of use if you have time explore it.
2. Setting up Email / Text / Phone Reminders for Azure Billing Usage
If you can’t get something to automatically shut down your VMs, you could at least set up an Azure billing alert email (which could also forward to a text or phone call via a 3rd party service if desired). The good thing about this is that it is a reminder for the subscription’s total usage. This means if you have a lot of charges from things other than VMs such as bandwidth, storage or other items, the alert will still trigger. I have written a detailed blog post on how to do that here.
3. Understanding What “Shut Down” Does and Doesn’t Mean in Azure
YES IT’S SHUT DOWN
Stop the VM from the management portal:
or through Azure PowerShell
Use the Azure Service Management API (I think this can only be done in C# but not sure as I am a bit of novice on this part), YES this is shut down:
ExecuteClientActionInOCS(null, CommandRuntime.ToString(), s => this.Channel.ShutdownRole(s, this.ServiceName, CurrentDeployment.Name, roleName, PostShutdownAction.StoppedDeallocated));
NO IT’S NOT SHUT DOWN
‘PostShutdownAction’ equal to “Stopped”. Running this code (I think in C#) will NOT shut down your VM from billing:
ExecuteClientActionInOCS(null, CommandRuntime.ToString(), s => this.Channel.ShutdownRole(s, this.ServiceName, CurrentDeployment.Name, roleName, PostShutdownAction.Stopped));
The Azure Portal will soon include monitoring for VMs in their dashboard, however as of April 2014 it is not available yet. I am continuing to investigate new ways such as the preview of Azure Watch & Scheduled Jobs to see if they may be other options available. If you figure out any yourself, please let me know and comment below!!!!