AlbertWT
Virtuoso
Virtuoso

Request to modify script to gather CPU Ready in percentage per VM instead of milliseconds

Jump to solution

Hi All,

I'd like to ask some help here with the script that I've found in this forum by Mr. LucD to gather VM CPU Ready % to be modified as per the well-known formula to calculate VM CPU Ready percentage:

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



From my understanding, The script needs to be modified because:

  1. Doesn't divide the CPU Ready percentage by the number of vCPU for each VM
  2. The refresh interval is not set for the "past week". for the sake of simplicity, this script will be used to gather past week performance data ( $start = (Get-Date).AddDays(-7) )

Note: Refresh rate can be looked from this KB: VMware KB: Converting between CPU summation and CPU % ready values

the goal of this script is to categorize which VM from the result is higher than 10% to determined as having problem with CPU Ready. Source KB article: http://docs.media.bitpipe.com/io_10x/io_107330/item_605784/Basic%20VMware%20vSphere%20Performance%20...)

I have tested and executed below script:

$allvms = @()

$vms = Get-VM 

$start = (Get-Date).AddDays(-7)

$metrics = "cpu.usage.average","mem.usage.average","cpu.ready.summation"

Get-Stat -Entity $vms -Start $start -Stat $metrics |

Group-Object -Property {$_.Entity.Name} | %{

  $cpu = $_.Group | where {$_.MetricId -eq "cpu.usage.average" -and $_.Instance -eq ""} | Measure-Object -Property value -Average -Maximum -Minimum

  $mem = $_.Group | where {$_.MetricId -eq "mem.usage.average"} | Measure-Object -Property value -Average -Maximum -Minimum

  $vmstat = "" | Select Time,VmName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin, CPURDYMaxPercent

  $vmstat.VmName = $_.Group[0].Entity.Name

  $vmstat.Time = $_.Group | Sort-Object -Property Timestamp | Select -First 1 | Select -ExpandProperty Timestamp

  $vmstat.CPUMax = [Math]::Round($cpu.Maximum,2)

  $vmstat.CPUAvg = [Math]::Round($cpu.Average,2)

  $vmstat.CPUMin = [Math]::Round($cpu.Minimum,2)

  $vmstat.MemMax = [Math]::Round($mem.Maximum,2)

  $vmstat.MemAvg = [Math]::Round($mem.Average,2)

  $vmstat.MemMin = [Math]::Round($mem.Minimum,2)

  $vmstat.CPURDYMaxPercent = &{

  $interval = $_.Group[0].IntervalSecs * 10

    ($_.Group | where {$_.MetricId -eq "cpu.ready.summation" -and $_.Instance -eq ""} |

  Sort-Object -Property Value -Descending |

    Select -First 1 |

    Select -ExpandProperty Value) / $interval

  }

  $allvms += $vmstat

}

$allvms | Select Time,VMName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin, CPURDYMaxPercent |

Export-Csv "C:\TEMP\AllVMs-7days.csv" -noTypeInformation -UseCulture

Hopefully, this will be the most useful script to get some understanding in which particular VM is currently having problem with CPU Ready percentage.

Thanks in advance,

/* Any kind of comment or input would be greatly appreciated */
1 Solution

Accepted Solutions
kunaludapi
Expert
Expert

I have my version here, I use to pull CPU contention.

function Get-Ready {

    <#

    .SYNOPSIS

    This single function provide multiple reports and information. ie: convert ready value to readable format (for realtime, day, week, month, year).

    .DESCRIPTION

    This single function provides multiple information from esxi host, as list below,

    VM's CPU usage, CPU usage Mhz, CPU ready

    vCPU allocated to VM (breaked into Sockets and Core)

    VMHost Name

    Physical CPU information of VMhost (breaked into Sockets and Core)

    To convert between the CPU ready summation value in vCenter's performance charts and the CPU ready % value that you see in esxtop, you must use a formula.

    The formula requires you to know the default update intervals for the performance charts. These are the default update intervals for each chart:

    Realtime: 20 seconds

    Past Day: 5 minutes (300 seconds)

    Past Week: 30 minutes (1800 seconds)

    Past Month: 2 hours (7200 seconds)

    Past Year: 1 day (86400 seconds)

    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 %

    Example: The Realtime stats for a virtual machine in vCenter might have an average CPU ready summation value of 1000. Use the appropriate values with the formula to get the CPU ready %.

    (1000 / (20s * 1000)) * 100 = 5% CPU ready

    For more infor check on vmware KB 2002181

    .PARAMETER VM

    Virtual machine name

    .INPUTS

    String.System.Management.Automation.PSObject.

    .OUTPUTS

    None.

    .EXAMPLE

    If you wrap this script inside function you can use it as a command.

    To wrap this script

    PS>Get-VMHost esxihost.fqdn | Get-Ready

    Retrive report for vm from perticular VMHost

     .NOTES

    To see the examples, type: "get-help Set-VMHostSSH -examples".

    For more information, type: "get-help Set-VMHostSSH -detailed".

    For technical information, type: "get-help Set-VMHostSSH -full".

    http://kunaludapi.blogspot.com

    #>

    [CmdletBinding()]

    param(

    [Parameter(Mandatory=$true,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$true)]

    [String]$Name) #param

    begin {}#begin

    process {

        $Stattypes = "cpu.usage.average", "cpu.usagemhz.average", "cpu.ready.summation"

        foreach ($esxi in $(Get-VMHost $Name)) {

            $vmlist = $esxi | Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"}

            $esxiCPUSockets = $esxi.ExtensionData.Summary.Hardware.NumCpuPkgs 

            $esxiCPUcores = $esxi.ExtensionData.Summary.Hardware.NumCpuCores/$esxiCPUSockets

            $TotalesxiCPUs = $esxiCPUSockets * $esxiCPUcores

            foreach ($vm in $vmlist) {

                $VMCPUNumCpu = $vm.NumCpu

                $VMCPUCores = $vm.ExtensionData.config.hardware.NumCoresPerSocket

                $VMCPUSockets = $VMCPUNumCpu / $VMCPUCores

                $GroupedRealTimestats = Get-Stat -Entity $vm -Stat $Stattypes -Realtime -Instance "" -ErrorAction SilentlyContinue | Group-Object MetricId

                $RealTimeCPUAverageStat = "{0:N2}" -f $($GroupedRealTimestats | Where {$_.Name -eq "cpu.usage.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $RealTimeCPUUsageMhzStat = "{0:N2}" -f $($GroupedRealTimestats | Where {$_.Name -eq "cpu.usagemhz.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $RealTimeReadystat = $GroupedRealTimestats | Where {$_.Name -eq "cpu.ready.summation"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average

                $RealTimereadyvalue = [math]::Round($(($RealTimeReadystat / (20 * 1000)) * 100), 2)

                $Groupeddaystats = Get-Stat -Entity $vm -Stat $Stattypes -Start (get-date).AddDays(-1) -Finish (get-date) -IntervalMins 5 -Instance "" -ErrorAction SilentlyContinue | Group-Object MetricId

                $dayCPUAverageStat = "{0:N2}" -f $($Groupeddaystats | Where {$_.Name -eq "cpu.usage.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $dayCPUUsageMhzStat = "{0:N2}" -f $($Groupeddaystats | Where {$_.Name -eq "cpu.usagemhz.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $dayReadystat = $Groupeddaystats | Where {$_.Name -eq "cpu.ready.summation"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average

                $dayreadyvalue = [math]::Round($(($dayReadystat / (300 * 1000)) * 100), 2)

                $Groupedweekstats = Get-Stat -Entity $vm -Stat $Stattypes -Start (get-date).AddDays(-7) -Finish (get-date) -IntervalMins 30 -Instance "" -ErrorAction SilentlyContinue | Group-Object MetricId

                $weekCPUAverageStat = "{0:N2}" -f $($Groupedweekstats | Where {$_.Name -eq "cpu.usage.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $weekCPUUsageMhzStat = "{0:N2}" -f $($Groupedweekstats | Where {$_.Name -eq "cpu.usagemhz.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $weekReadystat = $Groupedweekstats | Where {$_.Name -eq "cpu.ready.summation"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average

                $weekreadyvalue = [math]::Round($(($weekReadystat / (1800 * 1000)) * 100), 2)

                $Groupedmonthstats = Get-Stat -Entity $vm -Stat $Stattypes -Start (get-date).AddDays(-30) -Finish (get-date) -IntervalMins 120 -Instance "" -ErrorAction SilentlyContinue | Group-Object MetricId

                $monthCPUAverageStat = "{0:N2}" -f $($Groupedmonthstats | Where {$_.Name -eq "cpu.usage.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $monthCPUUsageMhzStat = "{0:N2}" -f $($Groupedmonthstats | Where {$_.Name -eq "cpu.usagemhz.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $monthReadystat = $Groupedmonthstats | Where {$_.Name -eq "cpu.ready.summation"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average

                $monthreadyvalue = [math]::Round($(($monthReadystat / (7200 * 1000)) * 100), 2)           

                $Groupedyearstats = Get-Stat -Entity $vm -Stat $Stattypes -Start (get-date).AddDays(-365) -Finish (get-date) -IntervalMins 1440 -Instance "" -ErrorAction SilentlyContinue | Group-Object MetricId

                $yearCPUAverageStat = "{0:N2}" -f $($Groupedyearstats | Where {$_.Name -eq "cpu.usage.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $yearCPUUsageMhzStat = "{0:N2}" -f $($Groupedyearstats | Where {$_.Name -eq "cpu.usagemhz.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $yearReadystat = $Groupedyearstats | Where {$_.Name -eq "cpu.ready.summation"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average

                $yearreadyvalue = [math]::Round($(($yearReadystat / (86400 * 1000)) * 100), 2)   

                $data = New-Object psobject

                $data | Add-Member -MemberType NoteProperty -Name VM -Value $vm.name

                $data | Add-Member -MemberType NoteProperty -Name VMTotalCPUs -Value $VMCPUNumCpu

                $data | Add-Member -MemberType NoteProperty -Name VMTotalCPUSockets -Value $VMCPUSockets

                $data | Add-Member -MemberType NoteProperty -Name VMTotalCPUCores -Value $VMCPUCores

                $data | Add-Member -MemberType NoteProperty -Name "RealTime Usage Average%" -Value $RealTimeCPUAverageStat

                $data | Add-Member -MemberType NoteProperty -Name "RealTime Usage Mhz" -Value $RealTimeCPUUsageMhzStat

                $data | Add-Member -MemberType NoteProperty -Name "RealTime Ready%" -Value $RealTimereadyvalue

                $data | Add-Member -MemberType NoteProperty -Name "Day Usage Average%" -Value $dayCPUAverageStat

                $data | Add-Member -MemberType NoteProperty -Name "Day Usage Mhz" -Value $dayCPUUsageMhzStat

                $data | Add-Member -MemberType NoteProperty -Name "Day Ready%" -Value $dayreadyvalue

                $data | Add-Member -MemberType NoteProperty -Name "week Usage Average%" -Value $weekCPUAverageStat

                $data | Add-Member -MemberType NoteProperty -Name "week Usage Mhz" -Value $weekCPUUsageMhzStat

                $data | Add-Member -MemberType NoteProperty -Name "week Ready%" -Value $weekreadyvalue

                $data | Add-Member -MemberType NoteProperty -Name "month Usage Average%" -Value $monthCPUAverageStat

                $data | Add-Member -MemberType NoteProperty -Name "month Usage Mhz" -Value $monthCPUUsageMhzStat

                $data | Add-Member -MemberType NoteProperty -Name "month Ready%" -Value $monthreadyvalue

                $data | Add-Member -MemberType NoteProperty -Name "Year Usage Average%" -Value $yearCPUAverageStat

                $data | Add-Member -MemberType NoteProperty -Name "Year Usage Mhz" -Value $yearCPUUsageMhzStat

                $data | Add-Member -MemberType NoteProperty -Name "Year Ready%" -Value $yearreadyvalue

                $data | Add-Member -MemberType NoteProperty -Name VMHost -Value $esxi.name

                $data | Add-Member -MemberType NoteProperty -Name VMHostCPUSockets -Value $esxiCPUSockets

                $data | Add-Member -MemberType NoteProperty -Name VMHostCPUCores -Value $esxiCPUCores

                $data | Add-Member -MemberType NoteProperty -Name TotalVMhostCPUs -Value $TotalesxiCPUs

                $data

            } #foreach ($vm in $vmlist)

        }#foreach ($esxi in $(Get-VMHost $Name))

    } #process

} #Function Get-Ready

Get-VMHost | Get-Ready

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".

View solution in original post

7 Replies
kunaludapi
Expert
Expert

I have my version here, I use to pull CPU contention.

function Get-Ready {

    <#

    .SYNOPSIS

    This single function provide multiple reports and information. ie: convert ready value to readable format (for realtime, day, week, month, year).

    .DESCRIPTION

    This single function provides multiple information from esxi host, as list below,

    VM's CPU usage, CPU usage Mhz, CPU ready

    vCPU allocated to VM (breaked into Sockets and Core)

    VMHost Name

    Physical CPU information of VMhost (breaked into Sockets and Core)

    To convert between the CPU ready summation value in vCenter's performance charts and the CPU ready % value that you see in esxtop, you must use a formula.

    The formula requires you to know the default update intervals for the performance charts. These are the default update intervals for each chart:

    Realtime: 20 seconds

    Past Day: 5 minutes (300 seconds)

    Past Week: 30 minutes (1800 seconds)

    Past Month: 2 hours (7200 seconds)

    Past Year: 1 day (86400 seconds)

    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 %

    Example: The Realtime stats for a virtual machine in vCenter might have an average CPU ready summation value of 1000. Use the appropriate values with the formula to get the CPU ready %.

    (1000 / (20s * 1000)) * 100 = 5% CPU ready

    For more infor check on vmware KB 2002181

    .PARAMETER VM

    Virtual machine name

    .INPUTS

    String.System.Management.Automation.PSObject.

    .OUTPUTS

    None.

    .EXAMPLE

    If you wrap this script inside function you can use it as a command.

    To wrap this script

    PS>Get-VMHost esxihost.fqdn | Get-Ready

    Retrive report for vm from perticular VMHost

     .NOTES

    To see the examples, type: "get-help Set-VMHostSSH -examples".

    For more information, type: "get-help Set-VMHostSSH -detailed".

    For technical information, type: "get-help Set-VMHostSSH -full".

    http://kunaludapi.blogspot.com

    #>

    [CmdletBinding()]

    param(

    [Parameter(Mandatory=$true,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$true)]

    [String]$Name) #param

    begin {}#begin

    process {

        $Stattypes = "cpu.usage.average", "cpu.usagemhz.average", "cpu.ready.summation"

        foreach ($esxi in $(Get-VMHost $Name)) {

            $vmlist = $esxi | Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"}

            $esxiCPUSockets = $esxi.ExtensionData.Summary.Hardware.NumCpuPkgs 

            $esxiCPUcores = $esxi.ExtensionData.Summary.Hardware.NumCpuCores/$esxiCPUSockets

            $TotalesxiCPUs = $esxiCPUSockets * $esxiCPUcores

            foreach ($vm in $vmlist) {

                $VMCPUNumCpu = $vm.NumCpu

                $VMCPUCores = $vm.ExtensionData.config.hardware.NumCoresPerSocket

                $VMCPUSockets = $VMCPUNumCpu / $VMCPUCores

                $GroupedRealTimestats = Get-Stat -Entity $vm -Stat $Stattypes -Realtime -Instance "" -ErrorAction SilentlyContinue | Group-Object MetricId

                $RealTimeCPUAverageStat = "{0:N2}" -f $($GroupedRealTimestats | Where {$_.Name -eq "cpu.usage.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $RealTimeCPUUsageMhzStat = "{0:N2}" -f $($GroupedRealTimestats | Where {$_.Name -eq "cpu.usagemhz.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $RealTimeReadystat = $GroupedRealTimestats | Where {$_.Name -eq "cpu.ready.summation"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average

                $RealTimereadyvalue = [math]::Round($(($RealTimeReadystat / (20 * 1000)) * 100), 2)

                $Groupeddaystats = Get-Stat -Entity $vm -Stat $Stattypes -Start (get-date).AddDays(-1) -Finish (get-date) -IntervalMins 5 -Instance "" -ErrorAction SilentlyContinue | Group-Object MetricId

                $dayCPUAverageStat = "{0:N2}" -f $($Groupeddaystats | Where {$_.Name -eq "cpu.usage.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $dayCPUUsageMhzStat = "{0:N2}" -f $($Groupeddaystats | Where {$_.Name -eq "cpu.usagemhz.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $dayReadystat = $Groupeddaystats | Where {$_.Name -eq "cpu.ready.summation"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average

                $dayreadyvalue = [math]::Round($(($dayReadystat / (300 * 1000)) * 100), 2)

                $Groupedweekstats = Get-Stat -Entity $vm -Stat $Stattypes -Start (get-date).AddDays(-7) -Finish (get-date) -IntervalMins 30 -Instance "" -ErrorAction SilentlyContinue | Group-Object MetricId

                $weekCPUAverageStat = "{0:N2}" -f $($Groupedweekstats | Where {$_.Name -eq "cpu.usage.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $weekCPUUsageMhzStat = "{0:N2}" -f $($Groupedweekstats | Where {$_.Name -eq "cpu.usagemhz.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $weekReadystat = $Groupedweekstats | Where {$_.Name -eq "cpu.ready.summation"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average

                $weekreadyvalue = [math]::Round($(($weekReadystat / (1800 * 1000)) * 100), 2)

                $Groupedmonthstats = Get-Stat -Entity $vm -Stat $Stattypes -Start (get-date).AddDays(-30) -Finish (get-date) -IntervalMins 120 -Instance "" -ErrorAction SilentlyContinue | Group-Object MetricId

                $monthCPUAverageStat = "{0:N2}" -f $($Groupedmonthstats | Where {$_.Name -eq "cpu.usage.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $monthCPUUsageMhzStat = "{0:N2}" -f $($Groupedmonthstats | Where {$_.Name -eq "cpu.usagemhz.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $monthReadystat = $Groupedmonthstats | Where {$_.Name -eq "cpu.ready.summation"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average

                $monthreadyvalue = [math]::Round($(($monthReadystat / (7200 * 1000)) * 100), 2)           

                $Groupedyearstats = Get-Stat -Entity $vm -Stat $Stattypes -Start (get-date).AddDays(-365) -Finish (get-date) -IntervalMins 1440 -Instance "" -ErrorAction SilentlyContinue | Group-Object MetricId

                $yearCPUAverageStat = "{0:N2}" -f $($Groupedyearstats | Where {$_.Name -eq "cpu.usage.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $yearCPUUsageMhzStat = "{0:N2}" -f $($Groupedyearstats | Where {$_.Name -eq "cpu.usagemhz.average"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average)

                $yearReadystat = $Groupedyearstats | Where {$_.Name -eq "cpu.ready.summation"} | Select-Object -ExpandProperty Group | Measure-Object -Average Value | Select-Object -ExpandProperty Average

                $yearreadyvalue = [math]::Round($(($yearReadystat / (86400 * 1000)) * 100), 2)   

                $data = New-Object psobject

                $data | Add-Member -MemberType NoteProperty -Name VM -Value $vm.name

                $data | Add-Member -MemberType NoteProperty -Name VMTotalCPUs -Value $VMCPUNumCpu

                $data | Add-Member -MemberType NoteProperty -Name VMTotalCPUSockets -Value $VMCPUSockets

                $data | Add-Member -MemberType NoteProperty -Name VMTotalCPUCores -Value $VMCPUCores

                $data | Add-Member -MemberType NoteProperty -Name "RealTime Usage Average%" -Value $RealTimeCPUAverageStat

                $data | Add-Member -MemberType NoteProperty -Name "RealTime Usage Mhz" -Value $RealTimeCPUUsageMhzStat

                $data | Add-Member -MemberType NoteProperty -Name "RealTime Ready%" -Value $RealTimereadyvalue

                $data | Add-Member -MemberType NoteProperty -Name "Day Usage Average%" -Value $dayCPUAverageStat

                $data | Add-Member -MemberType NoteProperty -Name "Day Usage Mhz" -Value $dayCPUUsageMhzStat

                $data | Add-Member -MemberType NoteProperty -Name "Day Ready%" -Value $dayreadyvalue

                $data | Add-Member -MemberType NoteProperty -Name "week Usage Average%" -Value $weekCPUAverageStat

                $data | Add-Member -MemberType NoteProperty -Name "week Usage Mhz" -Value $weekCPUUsageMhzStat

                $data | Add-Member -MemberType NoteProperty -Name "week Ready%" -Value $weekreadyvalue

                $data | Add-Member -MemberType NoteProperty -Name "month Usage Average%" -Value $monthCPUAverageStat

                $data | Add-Member -MemberType NoteProperty -Name "month Usage Mhz" -Value $monthCPUUsageMhzStat

                $data | Add-Member -MemberType NoteProperty -Name "month Ready%" -Value $monthreadyvalue

                $data | Add-Member -MemberType NoteProperty -Name "Year Usage Average%" -Value $yearCPUAverageStat

                $data | Add-Member -MemberType NoteProperty -Name "Year Usage Mhz" -Value $yearCPUUsageMhzStat

                $data | Add-Member -MemberType NoteProperty -Name "Year Ready%" -Value $yearreadyvalue

                $data | Add-Member -MemberType NoteProperty -Name VMHost -Value $esxi.name

                $data | Add-Member -MemberType NoteProperty -Name VMHostCPUSockets -Value $esxiCPUSockets

                $data | Add-Member -MemberType NoteProperty -Name VMHostCPUCores -Value $esxiCPUCores

                $data | Add-Member -MemberType NoteProperty -Name TotalVMhostCPUs -Value $TotalesxiCPUs

                $data

            } #foreach ($vm in $vmlist)

        }#foreach ($esxi in $(Get-VMHost $Name))

    } #process

} #Function Get-Ready

Get-VMHost | Get-Ready

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
LucD
Leadership
Leadership

1. In the Where-clause the script fetches the entry where the Instance property is equal to "", in other words the aggregated value.

This is the average over all the vCPU.

So I don't think the script needs to divide by the number of vCPU anymore, that is already done by the PerformanceManager

2. The script gets the the interval duration from the object returned by Get-Stat, more specifically in the IntervalSecs property.

Some further info on the line

    $interval = $_.Group[0].IntervalSecs * 10 

The cpu.ready.summation metric returns a time value in milliseconds.

For the calculation of the CPURDYMaxPercent, the script takes the highest measurement from all the returned counters.

Then it uses the rule of three to calculate the percentage

value (msec) / interval (sec) * 100

or converted to milliseconds

value (msec) /(interval  * 1000 (msec)) * 100

or simplified

value / (interval * 10)

And that is why the script multiplies the interval from the object.with 10.

The CPURDYMaxPercent property will return a percentage (a value between 0 and 100), so you can check which entries have a value greater than 10.


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

AlbertWT
Virtuoso
Virtuoso

Hi Kunal,

Question for you, does the formula to calculate the CPuU ready already divide the CPU ready percentage per vCPU for each of the VMs ?

/* Any kind of comment or input would be greatly appreciated */
0 Kudos
AlbertWT
Virtuoso
Virtuoso

now I begin to understand Luc 🙂

many thanks for the detailed explanation. So in this case the script doesn't need further modifications if I use it to calculate the past week or -7 days.

/* Any kind of comment or input would be greatly appreciated */
0 Kudos
LucD
Leadership
Leadership

That is correct (unless I overlooked something :smileygrin:)


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

AlbertWT
Virtuoso
Virtuoso

As usual you are very-very helpful Luc.

and kunaludapi, thanks for sharing the script here.

/* Any kind of comment or input would be greatly appreciated */
0 Kudos
kunaludapi
Expert
Expert

Physical CPU information of VMhost (breaked into Sockets and Core)

    To convert between the CPU ready summation value in vCenter's performance charts and the CPU ready % value that you see in esxtop, you must use a formula.

    The formula requires you to know the default update intervals for the performance charts. These are the default update intervals for each chart:

    Realtime: 20 seconds

    Past Day: 5 minutes (300 seconds)

    Past Week: 30 minutes (1800 seconds)

    Past Month: 2 hours (7200 seconds)

    Past Year: 1 day (86400 seconds)

    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 %

    Example: The Realtime stats for a virtual machine in vCenter might have an average CPU ready summation value of 1000. Use the appropriate values with the formula to get the CPU ready %.

    (1000 / (20s * 1000)) * 100 = 5% CPU ready

    For more infor check on vmware KB 2002181

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".