Use Performance Monitor to get VM performance statistics
June 19, 2012 5 Comments
In PowerCLI you can use the Get-Stat cmdlet to get performance statistics. But for Microsoft Windows virtual machines with the VMware Tools installed there is another way to get the statistics. Even without using PowerCLI.
Performance Monitor
The VMware Tools for a Microsoft Windows computer adds VMware specific counters to the Performance Monitor. The counters are in two categories: “VM Memory” and “VM Processor”. These categories contain the following counters (vSphere 4.1):
VM Memory
- Memory Active in MB
- Memory Ballooned in MB
- Memory Limit in MB
- Memory Mapped in MB
- Memory Overhead in MB
- Memory Reservation in MB
- Memory Shared in MB
- Memory Shared Saved in MB
- Memory Shares
- Memory Swapped in MB
- Memory Target Size
- Memory Used in MB
VM Processor
- % Processor Time
- CPU stolen time
- Effective VM Speed in MHz
- Host processor speed in MHz
- Limit in MHz
- Reservation in MHz
- Shares
In figure 1 you see some of the VMware counters in the Performance Monitor Add Counters window.
Figure 1. Performance Monitor Add Counters window.
After adding these counters you can see them in action in figure 2.
Figure 2. Performance Monitor VMware counters in action.
The PowerShell Get-Counter cmdlet
The PowerShell Get-Counter cmdlet gets performance counter data from local and remote computers. The PowerShell script of listing 1 shows all the VMware performance counters for a server.
$ComputerName = "server01" Get-Counter -ComputerName $ComputerName -ListSet VM* | Select-Object -Expandproperty Counter
Listing 1. PowerShell script to get all VMware counters for server Server01.
Sample output of this script is shown in output 1.
\\server01\VM Processor(*)\Limit in MHz \\server01\VM Processor(*)\Reservation in MHz \\server01\VM Processor(*)\Shares \\server01\VM Processor(*)\CPU stolen time \\server01\VM Processor(*)\% Processor Time \\server01\VM Processor(*)\Effective VM Speed in MHz \\server01\VM Processor(*)\Host processor speed in MHz \\server01\VM Memory\Memory Active in MB \\server01\VM Memory\Memory Ballooned in MB \\server01\VM Memory\Memory Limit in MB \\server01\VM Memory\Memory Mapped in MB \\server01\VM Memory\Memory Overhead in MB \\server01\VM Memory\Memory Reservation in MB \\server01\VM Memory\Memory Shared in MB \\server01\VM Memory\Memory Shared Saved in MB \\server01\VM Memory\Memory Shares \\server01\VM Memory\Memory Swapped in MB \\server01\VM Memory\Memory Target Size \\server01\VM Memory\Memory Used in MB
Output 1. Sample output of the script of listing 1.
The PowerShell script of listing 2 will list not only the VMware counters, but it will list all the Performance Monitor counters for server Server01.
$ComputerName = "server01" Get-Counter -ComputerName $ComputerName -ListSet * | Select -Expandproperty Counter
Listing 2. PowerShell script to get all Performance Monitor counters for server Server01.
The PowerShell script of listing 3 gets all VMware counters for server Server01, and retrieves the counter values, ten times with a two second interval. A sample output of this script for one interval is shown in output 2.
$ComputerName = "Server01" Get-Counter -ComputerName $ComputerName -ListSet VM* | Get-Counter -MaxSamples 10 -SampleInterval 2
Listing 3. PowerShell script to get all VMware counter values for server Server01.
Annotations
Line 2: Get all the VMware counters.
Line 3: Get the values for all the VMware counters, 10 times with a 2 seconds interval.
Output 2 shows the output of the script of listing 3 for one interval.
Timestamp CounterSamples --------- -------------- 2012-06-19 18:11:20 \\server01\vm processor(_total)\limit in mhz : 4294967295 \\server01\vm processor(_total)\reservation in mhz : 0 \\server01\vm processor(_total)\shares : 2000 \\server01\vm processor(_total)\cpu stolen time : 5E-06 \\server01\vm processor(_total)\% processor time : 16.25 \\server01\vm processor(_total)\effective vm speed in mhz : 400 \\server01\vm processor(_total)\host processor speed in mhz : 2800 \\server01\vm memory\memory active in mb : 491 \\server01\vm memory\memory ballooned in mb : 0 \\server01\vm memory\memory limit in mb : 4294967295 \\server01\vm memory\memory mapped in mb : 3054 \\server01\vm memory\memory overhead in mb : 122 \\server01\vm memory\memory reservation in mb : 0 \\server01\vm memory\memory shared in mb : 22 \\server01\vm memory\memory shared saved in mb : 21 \\server01\vm memory\memory shares : 30720 \\server01\vm memory\memory swapped in mb : 17 \\server01\vm memory\memory target size : 3050 \\server01\vm memory\memory used in mb : 3033
Output 2. Sample output of the script of listing 3 for one interval.
Export the output to a .csv file
You can use the PowerShell Export-Counter cmdlet to export performance counter data to log files in binary performance log (.blg), comma-separated value (.csv), or tab-separated value (.tsv) format.
Listing 4 shows you how to use the Export-Counter cmdlet to export to a .csv file. You can use this .csv file for further analysis of the counters in a spreadsheet. Or to import them in another PowerShell script.
$ComputerName = "server01" $Path = "vSphereCounters.csv" Get-Counter -ComputerName $ComputerName -ListSet VM* | Get-Counter -MaxSamples 10 -SampleInterval 2 | Export-Counter -Path $Path -FileFormat Csv -Force
Listing 4. PowerShell script to get all VMware counters for server Server01 and export them to vSphereCounters.csv.
When you open the vSphereCounters.csv file in Excel, the output will look like output 3. Every counter has its own column.
Output 3. Output of the Export-Counter cmdlet imported in Excel.
Conclusion
The VMware Tools adds performance counters to the Windows Performance Monitor. You can use The PowerShell Get-Counter and Export-Counter cmdlets to retrieve the counter values.
HI Robert
Very interesting article, helps quite a bit. I tried monitoring the VM Processor(_total)\CPU Stolen time via the Perf Mon and no data arrived. Your article provided a way to test that the counters are actually working on the server but that Perf Mon is not working with these additional counters on 1 of 6 servers I have to solve an issue with. I added them into Perf Mon but there is nothing in the .blg file after I stop the collection. Seems even more odd now as the Powershell does. Must be something with the Perf Mon on this server as another server seems to work. Maybe a bug.
I was wondering if you have any information about the very small numbers returned by this counter and how one should interpret them. I have collected some other metrics on the server and at times the CPU Queue Length grows a bit, sometimes quite periodically….
Great article….
Hi Rodney,
I am glad that you like my article. And I am sorry that it took me so long to respond.
According to “Timekeeping in VMware Virtual machines” (http://www.vmware.com/files/pdf/techpaper/Timekeeping-In-VirtualMachines.pdf) CPU Stolen Time is “time when the guest operating system was ready to run, but the virtual machine was descheduled by the host scheduler”. So IMHO this means small numbers are better than large numbers.
Why is my VM processor time so much higher than my normal processor time on perfmon? this is a Vmware VM which one should i be looking at if i’m looking for trouble areas?
Thanks … can you also write some article on vm performance in general ? This topic is so vast & so many script are there which cover mainly cpu/ram & ready.. but then disk io & network io etc is not covered & get-esxtop is so complex too .. so a consolidated script will help thanks
Pingback: VMWare VMotion causing performance to increase?