With Windows Server Hyper-V, Microsoft introduced a new feature in Hyper-V called Resource Metering which allows you to measure the usage of a Hyper-V virtual machine (VM). This will enable you to track CPU, Memory, Disk, and network usage. This is a great feature, especially if you need to do chargeback or maybe even for troubleshooting.
Last week I had the chance to test and implement this feature for a customer. So here is my experience and how you can enable Hyper-V VM Resource Metering using PowerShell. Also, make sure that you have a look at the Microsoft Docs.
First, you can check the available PowerShell cmdlets for Hyper-V or for the commands which include VMResourceMetering.
Get-Command -Module Hyper-V Get-Command *VMResourceMetering*
The resource metering has to be enabled per virtual machine. This is great, so even if you move the virtual machine from one Hyper-V host to another, you still have the usage data.
To enable resource metering, you can use the following cmdlet. In my case, I enable VM Resource Metering for my VM called SQL2012.
Get-VM SQL2012 | Enable-VMResourceMetering
With the cmdlet Measure-VM, you can get the statistic for the VM. Simply run that comment to measure the Hyper-V VM usage.
Measure-VM -VMName SQL2012 Get-VM SQL2012 | Measure-VM | select *
To get the network traffic use the properties of the NetworkMeteredTrafficReport.
(Measure-VM -VMName SQL2012).NetworkMeteredTrafficReport
Here is another great thing, if you want to measure Network from or to a specific network you can use VM Network Adapter ACLs to do so. With ACLs, you can not just allow or deny network traffic, and you can also meter network traffic for a particular subnet or IP address.
Add-VMNetworkAdapterAcl -VMName SQL2012 -Action Meter -RemoteIPAddress 10.10.0.0/16 -Direction Outbound
Of course, you can reset the statistics for the VM.
Get-VM SQL2012 | Reset-VMResourceMetering
And to disable resource metering for the VM use:
Get-VM SQL2012 | Disable-VMResourceMetering
I think this is one of the great new features of Windows Server 2012 Hyper-V which gets not a lot of attention but is essential.
If you want to know more about Resource Metering in Hyper-V, check out the blog post from Lalithra Fernando on the TechNet Virtualization Blog.
If you want to know more or have any questions, please feel free to leave a comment.
Tags: ACL, CPU usage, Hyper-V, Measure, Memory Usage, Microsoft, Network Traffic, PowerShell, Resource Metering, Virtual Machine, VM, VM Resource Metering, Windows Powershell, Windows Server, Windows Server 2012 Last modified: September 23, 2019
Hi great post all the reporting command in one post.
Hi Thomas Maurer,
How to execute this Command with C#
Get-VM SQL2012 | Enable-VMResourceMetering
Please help me.
Thanks
Alok kumar sharma
It seems that this is not working on VM’s running on a Hyper-V cluster (2012R2), did you check this also?
Yes this should also work with Windows Server 2012 R2
Hi Thomas,
How to get the Disk I/O Read/Write statistics of a VM..?
Well for simple things you can use Resource Metering. https://www.thomasmaurer.ch/2012/12/windows-server-2012-hyper-v-vm-resource-metering-via-powershell/
For other things I would recommend perfmon.exe