Autoscaling VM scale sets with Azure host metrics

It’s now easier to set up autoscaling with Azure VM scale sets than it used to be. Until recently the only way to set up autoscaling for scale sets was by installing the Azure diagnostics extension in every VM. The diagnostics extension was required to emit performance data to a storage account that you also had to manage. Your autoscale rules would then reference that data to evaluate whether to trigger a scale action.

In October (2016) a more efficient data pipeline for Azure VMs went into production, based on host metrics. Host metrics means the hypervisor host machine which is running the Azure VM collects performance data about the VM and stores it in a free account which is managed on your behalf. This is the data being used when you look at your VM scale set properties in the Azure portal and view or edit a graph..

image

Autoscaling using Azure templates

You can access the host metric data directly, and also set up Azure autoscale rules to use it. The autoscaling templates in Azure Quickstart templates have already been converted to use host based metrics (that is, they no longer install a diagnostics extension, no longer create a storage account for metrics, and reference the host metric display names in the autoscale rules). This makes the templates simpler than they used to be. See the following for example:

https://github.com/Azure/azure-quickstart-templates/tree/master/201-vmss-bottle-autoscale
https://github.com/Azure/azure-quickstart-templates/tree/master/201-vmss-ubuntu-autoscale
https://github.com/Azure/azure-quickstart-templates/tree/master/201-vmss-windows-autoscale

E.g. looking at one of the scale rules in the python-bottle template, the Percentage CPU host metric is referenced:

image

The host metric names you can use in the scale rules are documented here: https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-supported-metrics

E.g. at the time of writing:
Microsoft.Compute/virtualMachineScaleSets

Metric

Metric Display Name

Unit

Aggregation Type

Description

Percentage CPU

Percentage CPU

Percent

Average

The percentage of allocated compute units that are currently in use by the Virtual Machine(s)

Network In

Network In

Bytes

Total

The number of bytes received on all network interfaces by the Virtual Machine(s) (Incoming Traffic)

Network Out

Network Out

Bytes

Total

The number of bytes out on all network interfaces by the Virtual Machine(s) (Outgoing Traffic)

Disk Read Bytes

Disk Read Bytes

Bytes

Total

Total bytes read from disk during monitoring period

Disk Write Bytes

Disk Write Bytes

Bytes

Total

Total bytes written to disk during monitoring period

Disk Read Operations/Sec

Disk Read Operations/Sec

CountPerSecond

Average

Disk Read IOPS

Disk Write Operations/Sec

Disk Write Operations/Sec

CountPerSecond

Average

Disk Write IOPS

If you need to autoscale using other metrics e.g. memory, it is recommended to keep using the diagnostics extensions.

Accessing host metrics directly

You can view the host metrics data coming from scale sets directly using the Azure Monitor REST API (formerly known as the Insights API). Using a simple Python program like this one for example: insights_metrics.py, I can view the same data that the graph in the Azure portal shows me..

image

Or create my own graphs (in this case by just dumping data in a spreadsheet):

image

Here’s another example, this time feeding the data into a matplotlib graph.. vmsscpuplot.py. The graph below shows a case of maxing-out the CPU of the 201-vmss-bottle-autoscale scale set, starting with a capacity of 1 and then autoscale kicking in to scale out to 2 VMs. It looks like it may have scaled out to 3 and then back to a steady state of 2

..

image

Advertisements
This entry was posted in Cloud, Computers and Internet, Python, VM Scale Sets. Bookmark the permalink.

One Response to Autoscaling VM scale sets with Azure host metrics

  1. Pingback: How to add autoscale to an Azure VM scale set | MSFT Stack

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s