CPU Ready Percentage with PowerCLI

An important statistic to always be aware of is CPU Ready Time.

CPU Ready Time is the amount of time a VM is ready with a workload to use CPU but has to wait to be assigned a slot on the actual hardware CPU. Having a High CPU time can mean you have a host that is under CPU Contention.

CPUGUI

Looking at the pic above, that is the CPU Ready of a VM over the past week. On average, it seems this VM has to wait over 1 second(>1000ms) each time it wants to use CPU cycles. That kind of seems like a lot to me.

But we have to rememeber that the above is a sample taken over a period of time so all is not as it seems. A better way is to look at the CPU Ready Percentage….it involves math 🙂

Straight from a KB Article:

To calculate the CPU ready % from the CPU ready summation value, use this formula:

(CPU summation value / (<chart default update interval in seconds> * 1000)) * 100 = CPU ready %

Perfect sense right!!! Maybe not so let’s do it with our example

(1421/1800 seconds * 1000)*100= .08%(rounded)

So around .08% of time it has to wait for CPU resources. Said a different way 99.02% of the time it doesn’t have to wait.

This means that despite what we may have concluded just by looking at the summation value, this VM almost never has to wait on CPU resources, which is good!

So let’s look at the PowerCLI


param($vms="*", $interval)
 Switch ($interval)
 {
 "day" {$days=-1;$mins=5;$divider=3000}
 "week" {$days=-7;$mins=30;$divider=18000}
 "month" {$days=-30;$mins=120;$divider=72000}
 }

$groups=Get-Stat -Entity (get-vm $vms ) -Stat cpu.ready.summation -start (get-date).adddays($days) -finish (get-date) -interval $mins -instance "" -ea silentlycontinue|group entity

$output=@()

ForEach ($group in $groups)
 {
 $temp= ""|select-Object Name, "Ready%"
 $temp.name=$group.name

$temp."ready%"= “{0:n2}” -f (($group.group |measure-object value -ave).average/$divider)

$output+=$temp
 }

$output

It is pretty straightforward. You give it a vm/vms, or it will grab all of them. You give the script an interval: day, week,month. Then it is on its way. Be warned any time you are grabbing stats with PowerCLI it might take a while. This becomes even more true for the number of VMs you are grabbing stats for….

CPUCLI

Hope this helps and here are two places you can get even more info!

CPU Ready Time in VMware and How to Interpret its Real Meaning

Converting between CPU summation and CPU % ready values

9 Responses to CPU Ready Percentage with PowerCLI

  1. Hi,
    thanks for this script.
    Ready summation is also given for an ESXi… Is it like the worst CPU Ready VM stat ? Is it maximum or average.
    It would be easier for us to look at ESXi to get contention evolution.

    Cedric.

  2. Very useful thanks. Can you tell me how it could be modified so it can be run with a vmname as a switch? i.e .\getcpuready -interval week -server “servername”

  3. Hi,
    I don’t understand, i’ve got error : “param not recognized”
    I’m noobs on powershell.
    Could you help me ?
    Regards

      • Sorry, I’m a noob at this…so when you say give it a vm/vms I’m a little confused. I’m trying to feed it two or more like this “linuxabc,unixbca” it its not liking that format, any suggestions as to what I’m doing wrong?
        example
        you – param($vms=”*”, $interval)
        me – param($vms=”linuxabc,unixbca”, $interval)

        • So when you run it like the screenshot I posted, you don’t need to change anything, just run it like

          .\cpuready.ps1 -vms ”linuxabc”,”unixbca”

          That should make it work.

          The vms=”*” is the script just acts as a default value when the script is run in case a value isn’t specified.

          Hope that helps!

          • That totally did, thanks so much. We have over 7K hosts yup hosts and looking at CPUReady from an Application perspective vrs an Administrator view helps…the admins are after overall whereas I’m targeting a handful like 20 servers that could be on any number of hosts, clusters, vCenters and so on…so I’m logging on to about 5 vCenters and issuing commands to capture data for thoes servers, thanks for the assistance….

Leave a Reply