Tuesday 10 April 2018

Azure Subscription Limits

During my time of doing a migrate of IaaS workload in to Azure I came across an issue where it reported that I had ran out of "core" resources. I was thinking how could I run out of resources? this is the cloud isn't it? is it not unlimited? After a quick case logged with Microsoft I was told we hit our "default limits" set by Microsoft.  You can raise these default limits by raising a case and as long as it is not an Azure limit you are hitting then they increase it free of charge for you. Every subscription for Azure has service limits, quotas, and constraints which are documented here on their website. To see your usage in your subscription you would select your "subscription", then "usage + quotas" and it will then display all your service quotas and how much you have used. You will see a button where you can request to increase the quotas.


This is good visually but ultimately we want to run a script where we can get the information so that  we can be manipulated it. For example we may want to run the script daily and then if the usage is above 75% then alert me then at least I can be more proactive. As you can see the above diagram has service limits for networks, IP addresses and NSG which at the moment I am not working on. As I am using Azure as a IaaS platform the information I am interested are related to CPU, storage accounts and number of VMs. There is a powershell command "Get-AzureRMVMUsage" which I will demostrate below on my script below. The script just goes through the subscription and every Azure location and returns the information about VM usages in each of the Azure location. The full script is available here at github. So here is the breakdown of my script

First we store some variables such as your Subscription name and the file name where we will store all the output of the information. The file will write to the current working directory that you are in. If there is a specific location you want to write the file to then please put in the full path and name of the file you want.
# Variables
$SubName = "Your Subscription Name"
# The file will be written in current directory that you have ran this script from
$FileName = "you file name.txt"

Next we login to your subscription and select the subscription you have defined above in the variable. We select the subscription in case your account has multiple subscriptions attached to it and we want to focus on a specific one
# Login to Azure Account
Login-AzureRmAccount
# Select Subscription to be used
Select-AzureRmSubscription -SubscriptionName $SubName

We run a command to store all the locations Azure has in a variable
# Get all available locations in Azure
$locations = Get-azureRmLocation

We are now at the heart of the script where we are looping through all the locations in Azure and running the command to gather all the VM usage in that particular location and write that information out to the text file
Foreach ($location in $Locations)
{
# Print to screen which location we are looping through
Write-Host $Location.Location
# Write the location to the file
$Location.Location | Out-File $FileName -Append
# Write the usage to the file
Get-AzureRMVMUsage -Location $location.Location | Out-File $FileName -Append
}

That's all in my script to get going. Once you run the script you will see something similar to what I have below showing just one of the Azure locations.

As you can see there are important information such as "current value" and "limits" against resources. So my example above you can see for "Total Regional vCPUs" for West Europe. I am currently using 6 and my limit is 20. As this information is retrieved via script it means that we can think of ways to apply some logic to only alert us when maybe a certain value is hit or a % value is met. Hope this script will get you started to expand and make it more powerful.

No comments:

Post a Comment

New Azure KMS IP and domain Addresses for activation

For Windows virtual machines deployed into Azure using marketplace images you may have created rules in your NSG or firewalls to allow the s...