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?

2 Answers
2

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.

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:

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?

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.
–
mprillDec 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 RiesDec 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.
–
ionFishDec 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 10.0.3.12 and the guest is on 10.0.3.104 then how can I find the 10.0.3.104 address using strictly Powershell on the host? If it's not possible, it's fine. It would be more of a luxury.
–
ionFishDec 25 '12 at 2:52

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.

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.
–
ionFishDec 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.
–
mprillDec 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.
–
ionFishDec 25 '12 at 3:55