In this blog post I will show you how you can measure the usage of host resources by Hyper-V virtual machines. This is yet another feature that was introduced in Windows Server 2012 Hyper-V that isn’t immediately obvious and is driven by using Windows PowerShell. So why should you use resource metering in Hyper-V? Read on to see why this feature is so important.
The American National Institute of Standards and Technology gives us one of the best definitions of a cloud in their Special Publication 800-145, entitled “The NIST Definition of Cloud Computing.” In this document they describe a cloud as having five essential characteristics. One of the traits that they describe as being necessary to have a cloud is a measured service:
Cloud systems automatically control and optimize resource use by leveraging a metering capability at some level of abstraction appropriate to the type of service (e.g., storage, processing, bandwidth, and active user accounts). Resource usage can be monitored, controlled, and reported, providing transparency for both the provider and consumer of the utilized service.
What does this mean? A cloud enables a tenant to consume just what they need and pay for what they use. The cloud must be able to measure that usage. Using this information, a cloud vendor can charge the tenant for their resource usage.
That’s fine for a hosting company. What about in a private cloud, that is, an infrastructure that runs on premise? Traditionally the IT department is run as a cost center, or as the board of directors unfortunately see it, as a budgetary black hole. IT can change this incorrect perception in one of two ways:
In my opinion, these sorts of actions could misfire and lead to talk of out-sourcing and off-shoring, so be careful!
Resource metering will collect the following data for each enabled virtual machine:
Note that in the case of dynamic virtual hard disks, the potential size, not the actual size, is reported for maximum physical amount of disk. Also note that all data is stored with the virtual machine and moves with the virtual machine as it migrates between hosts.
Resource metering is made available using PowerShell. You can write scripts using PowerShell or you can use other tools to leverage the functionality.
You must first enable metering on a per-virtual machine basis. The following snippet will enable metering on all virtual machines on a host:
Get-VM -ComputerName Demo-Host2 | Enable-VMResourceMetering
Tip: Remember to enable metering on any virtual machine created afterwards because the above cmdlet will only affect existing virtual machines.
By default, resource metering will collect metrics every hour. This is based on a per-host setting called ResourceMeteringSaveInterval. You might want to change this setting to match your billing rate in a cloud. If you are just testing resource metering, then you might want a more frequent collection. This example will change the setting to every 10 seconds:
Set-VMHost –ComputerName Demo-Host2 –ResourceMeteringSaveInterval 00:00:10
After the resource metering interval has passed, you will want to collect some metrics. Here’s a quick way to see all collected data:
Get-VM -ComputerName Demo-Host2 | Measure-VM
You could do something more targeted:
Measure-VM -ComputerName Demo-Host2 -Name VM01
You can get a breakdown of bandwidth usage using:
(Measure-VM -ComputerName Demo-Host2 -Name VM01).NetworkMeteredTrafficReport
Armed with this information, it won’t take you too long to find resource hogs on your hosts:
Get-VM -ComputerName Demo-Host2 | Measure-VM | Sort-Object -Property AverageProcessorUsage -Descending | Select-Object -First 3 –Property VMName,AverageProcessorUsage
Resource metering is a tool that can show the value of IT to the business or enable a service provider to earn revenue. And with this data, you even have some ability to track usage for diagnostics reasons.