VMware Cloud Community
AlbertWT
Virtuoso
Virtuoso
Jump to solution

How to get CPU Ready in percentage ?

Hi people,

When I read this blog from Mr. Epping http://www.yellow-bricks.com/esxtop/ it seems that the CPU ready is stated in % percentage, while in the vsphere console Performace | Advanced tab, it only shows you in milliseconds per 20 seconds.

So can anyone here assist me in creating or modifying the script (created by Luc D) to calculate the CPU Ready in percentage ?

$metrics = "cpu.usage.average","cpu.ready.summation","cpu.swapwait.summation","mem.active.average"
$entities = Get-VM -Name
$start = (Get-Date).AddDays(-5)
$report = Get-Stat -Entity $entities -Stat $metrics -Realtime -Start $start |
Group-Object -Property EntityId,Timestamp | %{
    New-Object PSObject -Property @{
        Name = $_.Group[0].Entity.Name
        Time = $_.Group[0].Timestamp
        CpuAvg = ($_.Group | where {$_.MetricId -eq "cpu.usage.average"}).Value
        CpuRdy = ($_.Group | where {$_.MetricId -eq "cpu.ready.summation" -and $_.Instance -eq ""}).Value
        CpuSwpWait = ($_.Group | where {$_.MetricId -eq "cpu.swapwait.summation" -and $_.Instance -eq ""}).Value
        MemActAvg = ($_.Group | where {$_.MetricId -eq "mem.active.average"}).Value
    }
}
$report | Sort-Object Name,Time | Export-Csv "C:\VMstats.csv" -NoTypeInformation -UseCulture

Any kind of help would be greatly appreciated.

Thanks.

/* Please feel free to provide any comments or input you may have. */
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

It depends on the interval you are looking at.

The 20000 is valid if you get Realtime stats, where the interval duration is 20 seconds.

In the example above, the script gets stats from Historical Interval 1, which has an interval of 300 seconds.

That's what I do with $_.Interval * 1000 which is 300 * 1000 = 300000


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

A small example of how it could be done.

$metric = "cpu.ready.summation" 
$entity
= Get-VM MyVM
$start = (Get-Date).AddHours(-8) Get-Stat -Entity $entity -Start $start -Stat $metric |
Select @{N="VM";E={$_.Entity.Name}}, Timestamp, @{N="CPU Ready %";E={"{0:p}" -f ($_.Value / ($_.IntervalSecs * 1000))}}

To cpu.ready.summation metric returns the ready time in milliseonds over the sample interval.

With a rule-of-three calculation the script converts the time to a percentage


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

AlbertWT
Virtuoso
Virtuoso
Jump to solution

Many thanks for the reply Luc,

I read the information from this page http://www.boche.net/blog/index.php/2010/10/21/cpu-ready-to-rdy-conversion/ it is confirmed that any value displayed in the vsphere client must be divided by 20.000 ms, why is this only divided by 1000 in your script above ?

/* Please feel free to provide any comments or input you may have. */
0 Kudos
LucD
Leadership
Leadership
Jump to solution

It depends on the interval you are looking at.

The 20000 is valid if you get Realtime stats, where the interval duration is 20 seconds.

In the example above, the script gets stats from Historical Interval 1, which has an interval of 300 seconds.

That's what I do with $_.Interval * 1000 which is 300 * 1000 = 300000


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
njcmdrx
Contributor
Contributor
Jump to solution

If the Virtual Machine is multiple vCPU, for example 4 vcpu, do I divide the %Ready by CPU's?  I have read this in other place but its unclear to me if this is part of the equation.

For example:

maximum summation value for 1 week  = 176701

So, I have 176701 / (1800 * 1000) * 100 = 9.816

However, 9.8 would look high, however this is a 4 vCPU VM.  So would I then divide 9.816 / 4 = 2.454 ?

this can make a difference when assessing performance.

0 Kudos