I am writing a control-panel for Hyper-V (new to it; please forgive). Using this as a reference:[link]

Problem 1:I can only get the CPU usage as seen by the host-OS, which could be maximum 11-12% on a single-core guest. (I could divide this by [1/8] for a 8-core server and it would be approximate). On the guest, it would say '100%' for example. How can I get the guest's interpretation of CPU usage?

Problem 2: How can I get the disk-use as seen by the guest-OS from the server's PowerShell? I could take the size of the VHD file as seen by the host, but that's often not the same as the guest reports.

Problem 3: Is there a way to find the IP-address of the guest-OS if the network adapter is bridged?


I'll attempt it and I'll try to give some Hyper-V specific information here. I'm using Hyper-V Server 2012 as an example.

Problem 1: I can only get the CPU usage as seen by the host-OS

No, you can get the CPU usage however you want to get it. If you want to get the overall CPU usage of the guest OS as the guest itself sees it (an average of all its vCPUs,) Just do

$(Get-WMIObject -Computername $VM Win32_Processor).LoadPercentage

(Handling credentials if that VM happens to be in another domain is a separate issue but still entirely possible. If it's in the same domain as the machine you're taking the measurement from, the above command will "just work" via the magic of Kerberos domain authentication.) That isn't the only counter that will get you to the same place either, but that's as good an example as any.

You can of course get the load percentage of each "core" or vCPU individually on the guest OS if you wanted. Or if it's a Linux VM, just do top or something. Just be aware that VMs are not very good at calculating their own processor usage. They don't have the precision clocks that physical machines do for one thing. Even worse if the VM doesn't have the virtualization tools installed, as the integration tools are actual modifications to kernel code (called enlightenments in Windows) that give the guest VM better capabilities and compatibility as the guest is now aware that it's a VM.

Also be aware that the host operating system that has Hyper-V installed on it (aka the root partition) is actually just another guest VM itself, albeit a special guest with privileged access to the Hypervisor.

| Host OS | Guest VM | Guest VM | Guest VM | 
            Physical Hardware

There are special counters that are exposed to only the Host OS by the hypervisor, about it and all the other guest VMs running on the system.

There are seriously a ton of these Hyper-V specific performance counters and they let you slice up the data in practically every conceivable way.

Take the following counters for instance: \\HYPERVSERVER\Hyper-V Hypervisor Logical Processor\% Guest Run Time, % Hypervisor Run Time, % Total Run Time, etc. For each of those counters, you will find a separate instance for each VM currently on the system, as well as _Total, of course. You will see on your root partition (host OS,) that each VM on the system has its own user-mode VM worker process. (1 vmmp.exe per VM, plus 1 vmms.exe for the host.) In fact, if you are a hypervisor, you can think of each virtual machine on the system as a separate thread of execution subject to thread scheduling in the same way as if you had 10 instances of Skifree.exe running on your Windows system. But vmwp.exe is only part of the picture, so don't go thinking you can measure the CPU usage of that user-mode process on the host OS and call it good.

Notice that there is also a \\HYPERVSERVER\Hyper-V Hypervisor Root Virtual Processor\*, which gives the Logical Processor objects as the hypervisor has abstracted them from their associated physical processors and presented them to the Host OS. There are more counters; too many for me to go over. But you can read the descriptions of all the counters right in Perfmon.

There are some counters in the root\Virtualization namespace, and there are also some Hyper-V counters in the root\CIMv2 namespace. Here are some I just dug up:

PS C:\> Get-WmiObject -List | Where Name -Match Hyper | Select Name


These counters are from the hypervisor itself, which is as close as you can get to the real hardware in this case. These counters will be much more accurate.

Problem 2: How can I get the disk-use as seen by the guest-OS from the server's PowerShell?

Get-WMIObject -Computername $VM Win32_LogicalDisk

As far as I know that is your best bet. Because the hypervisor doesn't care what the guest OS does with its storage. It only cares about the size of the associated .vhd's/.vhdx's, which as you pointed out isn't usually an accurate measure of how much data the VM thinks it has used on its logical drives.

Problem 3: Is there a way to find the IP-address of the guest-OS if the network adapter is bridged?

PS C:\> $(Get-WmiObject -ComputerName $VM win32_networkadapterConfiguration).IPAddress

I think you're likely to have follow-up questions, so if you post them, I'll edit my post to try to answer them.


To answer your question about getting the IP addresses of the virtual machines from the Hyper-V Host, without needing access to the VMs:

PS C:\> Get-VMNetworkAdapter *

Name            IsManagementOs VMName SwitchName             MacAddress   Status IPAddresses
----            -------------- ------ ----------             ----------   ------ -----------
Network Adapter False          WEB01  Hyper-V Virtual Switch 00155D015F00 {Ok}   {, fe80::858c:f47e:9bac:...
Network Adapter False          ECA01  Hyper-V Virtual Switch 00155D015F05 {Ok}   {, fe80::6890:cc44:2e50:...
| improve this answer | |
  • As @ionFish commented on my answer, the VMs are handled by his customers so he can't use WMI on them directly. I think that using CIM (WMI) on the host to query Hyper-V is his best bet on doing this. – mprill Dec 25 '12 at 1:18
  • Ah, well if OP has no access to the customer's VMs, then he needs to invent some sort of agent that runs on the customer's VMs to expose that data so that it can be collected, and you need a contract with your customers that they agree to run it. You're asking that the virtual machines give up privileged data about how they operate, yet at the same time you want to tell your customers that they have a "private" VM. You might as well be asking for user and process lists on the customer's VMs as well. It's a cake and mastication non-congruence paradigm. – Ryan Ries Dec 25 '12 at 2:23
  • Thanks for your comprehensive response. I will take the time tomorrow afternoon to try to work this out before I begin the database aspect of the panel. I would share what I have currently, but I'm not how to safely publish it. Perhaps you'd like to contact me by clicking my username, homepage, contact page and drop me a line. Thanks again, and have a happy and safe holiday. – ionFish Dec 25 '12 at 2:47
  • @RyanRies - First question: I can run that command to get the IP of the host server. I'm actually polling the servers with the script via their LAN IP. They run a simple PHP-Powershell passthru system with some authentication, and then the frontend-script contacts those. But for example, if the host is on and the guest is on then how can I find the address using strictly Powershell on the host? If it's not possible, it's fine. It would be more of a luxury. – ionFish Dec 25 '12 at 2:52
  • Added that to my answer. I'm using Powershell 3. – Ryan Ries Dec 25 '12 at 23:28

It seems to me that it would be a better idea to run all your queries from the guest OS. Since you want an accurate guest view from the hypervisor's perspective this poses some challenges:

For problem 1 there is an issue of the hypervisor overhead - the "real" CPU utilization for a VM as seen from the hypervisor will be higher than what's being reported from the guest OS. By how much? That depends on a lot of factors like the load type, virtualization technologies being used, to name a few. Different versions of Hyper-V require different technologies - the latest requires SLAT, so it's hard to judge how it'll affect your cases.

Disk usage is hard as well because you can't easily tell what file system is being used inside the VHD. And even if you can (and it's NTFS) then there's the matter of different VHD types that would make it even harder to measure.

For the third problem I'm assuming that you're referring to the external virtual switch that Hyper-V can use for sharing a physical network connection with the guest VMs (and the host itself, if configured).

Since Windows 2008 R2 it's possible to access this information (by querying the underlying Hyper-V infrastructure that's running in the guest) from the host using CIM (WMI), here is a nice example.

If you're using Windows as the only guest OS I suggest that you take a look at those articles about PowerShell Remoting.

Or you can dive further into Hyper-V's CIM, here is a good introduction and here is the documentation.

| improve this answer | |
  • Actually, the panel is for customers to rent machines with, and therefore I have no access to the actual guest software. Most machines are linux-based, some Windows, but I have no access to them. – ionFish Dec 24 '12 at 22:51
  • I've edited my answer with a reference to Hyper-V's CIM interface that could prove useful in your endeavours. But for it to work to the fullest the Integration Services for Hyper-V have to be running in the guest OS. – mprill Dec 24 '12 at 22:57
  • That article on the IP address of VM is exactly what I was looking for from what I can tell. I will look at it tomorrow. Thanks. – ionFish Dec 25 '12 at 3:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.