search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Virtual Machine Manager, Windows Powershell | No Comment | 7,671 views | 22/10/2010 10:59

In one of the Technet question, John said:

“When the Hyper-V role is enabled, the physical machine becomes a virtual machine known as the parent partition. The virtual machines are called child partitions. Each partition is isolated from the other. Task Manager in any partition shows only the load on the cpus in that partitions. If the child partitions are heavily taxing the physical cpus, Task Manager in the parent partition shows little cpu activity (assuming you don’t have some heavy load in the parent, which you shouldn’t – best practice is to not have things running in the parent).”

So that means, looking task manager is not a way to know exact resource usage of Hyper-V. If you need to monitor CPU usages of child partitions (virtual machines), you should use Perfmon or.. yes, Powershell :) I wrote a little script to see CPU usages. In my environment, we use Windows Server 2008 with Powershell v1, so I have to write it in version 1. But If you have Powershell v2, you surely can use Get-Counter command.

Function HyperVCPU($InstanceName)
{
$CategoryName = "Hyper-V Hypervisor Virtual Processor"
$CounterName = "% Guest Run Time"
$PerfCounter = New-Object System.Diagnostics.PerformanceCounter($CategoryName, $CounterName, $InstanceName)
$Result = $PerfCounter.NextValue()
$Result = $PerfCounter.NextValue()
$Result
}
 
Function ShowPerfmon
{
$PerfMon = New-Object System.Diagnostics.PerformanceCounterCategory
$PerfMon.CategoryName = "Hyper-V Hypervisor Virtual Processor"
$Instances = $PerfMon.GetInstanceNames()
Foreach ($Instance in $Instances)
{
$CPU = HyperVCPU $Instance
$Results = New-Object Psobject
$Results | Add-Member Noteproperty Name $Instance
$Results | Add-Member Noteproperty CPU $CPU
$Results
}
}
 
ShowPerfmon

But be careful. You need to run Powershell as an Administrator to reach perfmon counters. If not, you will get “Category does not exist” error.