If you’re not using your Infrastructure turn if off! Saving costs on Azure
One of the most common questions I get is How does Azure charge for my VM?
Azure charges an hourly price based on the VM’s size and operating system. For partial hours, Azure charges only for the minutes of use. So if your virtual machine ran for less than an hour, you will be charged for the number of minutes your virtual machine is running, rounded up to the nearest minute, not hour. If you create the VM with a VM image containing certain pre-installed software, additional hourly software charges may apply but you will be clearly informed of these when you provision the VM. Azure does however charges separately for storage for the VM’s operating system and data disks. Temporary disk storage is free.
You are charged when the VM status is Running or Stopped, but you are not charged when the VM status is Stopped (De-allocated). So the key thing is if your not using stop it you will still pay for storage associated as the VHD (the Image sits on Azure Storage so you pay minimal costs for de-allocated VMs) see the FAQ at https://azure.microsoft.com/en-gb/pricing/details/virtual-machines/linux/
Getting Started with Virtual Machines
Using Resource Groups
Top Tip: When creating new VMS if you should ideally organise your related resources into resource groups. Resource Groups helps us to logically group the Azure resources together and monitor and manage them. As An Example a resource group per machine or class. i.e. Deep Learning Resource Group, Which holds the VM and Associated services once the class is complete, you can delete the entire resource group with a few clicks, which should help manage costs and resources again you may simply want to de-allocate these and restart the services for the next Semester.
Documentation on VMs
Overview of Azure
For getting started the following On demand Webinar may be of use How to Get Started on Azure - https://info.microsoft.com/UK-MSFT-WBNR-FY17-11Nov-24-HowtoGetStartedonAzure-269444_Registration.html
Documentation on Azure
Azure is a huge service which is growing a tremendous rate last we added over 500 services we have now began to consolidate all our documentation under a single location see /en-us/azure/
To put a VM in the Stopped (De-allocated) state, do one of the following:
For SDK and cmd line tools to script and automation
- Azure SDK https://docs.microsoft.com/en-us/azure/#pivot=sdkstools&panel=sdkstools-all
- Powershell https://docs.microsoft.com/en-gb/powershell/azureps-cmdlets-docs/
- Azure CLI ‘Command Line Interface’ https://docs.microsoft.com/en-gb/cli/azure/install-azure-cli
For specific details on Linux VMs scripts see /en-us/azure/virtual-machines/virtual-machines-linux-tutorial-manage-vm?toc=/azure/virtual-machines/linux/toc.json
For Azure CLI tips on Connecting to an Azure subscription from the Azure Command-Line Interface (Azure CLI) For basic Azure CLI commands in Resource Manager (ARM), please also check this article: Use the Azure CLI for Mac, Linux, and Windows with Azure Resource Manager
Scripts and Resources
Microsoft Technet and the IT Pro/DevOps community also provided a number Using pre-created scripts see https://gallery.technet.microsoft.com/scriptcenter
Manually Shut down or delete the VM from the Azure portal. https://portal.azure.com Again you manage these via https://portal.azure.com but I presume you would like things automated
Use the Stop-AzureVM cmdlet, available in the Azure PowerShell module or Azure Command Line https://docs.microsoft.com/en-us/azure/#pivot=sdkstools&panel=sdkstools-all
Use the Shutdown Role operation in the Service Management REST API and specify StoppedDeallocated for the PostShutdownAction element. https://msdn.microsoft.com/en-
Stop All VMs in Specified Azure Resource Group
- Using Azure Automation to Start/Stop machines https://docs.microsoft.com/en-us/azure/automation/automation-solution-vm-management Using ARM-based Virtual Machines to auto-shutdown With this feature, setting auto-shutdown can’t be easier:
- Go to your VM blade in Azure portal. https://portal.azure.com, 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.
- Using Azure Logic Apps - This post illustrates how you can set up an Azure logic app to send auto-shutdown notification.
For more details, see Virtual Machines Pricing.
So as I stated above is that you will still pay for storage associated as the VHD (the Image sits on Azure Storage so you pay minimal costs for de-allocated VMs) see the FAQ at https://azure.microsoft.com/en-gb/pricing/details/virtual-machines/linux/
Key Tips
If the status says “Stopped (De-allocated)”, you aren’t being billed.
If it says “Stopped Allocated”, you’re still being billed for allocated virtual cores (not the software licence itself).
Top Tip : To ensure you aren’t being billed, always stop virtual machines from the management portal. You can also stop the virtual machine via Powershell by calling ShutdownRoleOperation with “PostShutdownAction” equal to “StoppedDeallocated”.
Removing a VM and all associated VHDs
This workflow deletes an Azure VM in a given subscription, together with associated disks and specified VM images. First check to see if the given VM exists. If it exists, then delete the vm together with all disks from the VM's disk repository https://gallery.technet.microsoft.com/scriptcenter/Remoe-VM-Together-with-4e9bb64d
Clean-up Services, VM's & VHD's deployed under a Cloud Service Using this script you can delete all the VM's, linked VHD's and other deployments under the specific cloud service. https://gallery.technet.microsoft.com/scriptcenter/Azure-Cloud-Service-VM-4e210bea
Stop All VMs in Specified Azure Resource Group this PowerShell Workflow script, intended to run in an Azure Automation runbook, stops all the Azure VMs in a specific Azure Resource Group. This sample runbooks stops all of the virtual machines in the specified Azure Resource Group. https://gallery.technet.microsoft.com/scriptcenter/Stop-All-VMs-in-Specified-40c8531e
Remove one or more Azure resource groups and contained resources This runbook connects to Azure and removes resource groups with names that have substrings that match the name filter. All of the resources in each resource group are also removed. An option is to run in preview mode to verify before actual removal. https://gallery.technet.microsoft.com/scriptcenter/Remove-one-or-more-Azure-9c43ef46