Written by 5:49 pm Microsoft, PowerShell, Virtualization, Windows Server • 7 Comments

Hyper-V VM Resource Metering via PowerShell

Hyper-V VM Resource Metering

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*

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

 

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 *

Measure-VM

To get the network traffic use the properties of the NetworkMeteredTrafficReport.

(Measure-VM -VMName SQL2012).NetworkMeteredTrafficReport

Measure-VM 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

add-vmnetworkadapteracl measure-vm

Of course, you can reset the statistics for the VM.

Get-VM SQL2012 | Reset-VMResourceMetering

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: , , , , , , , , , , , , , , Last modified: September 23, 2019
Close Search Window
Close