9 Replies Latest reply on May 17, 2019 5:50 AM by LucD

    Percentage of VMs with CPU Ready higher then 5%

    mibiras Novice

      Hi all

      Is possible to create script which returns Percentage (or number) of VMs with CPU Ready higher then 5% for specific cluster ?

      Thanks

        • 1. Re: Percentage of VMs with CPU Ready higher then 5%
          LucD Guru
          User ModeratorsvExpertCommunity Warriors

          Try something like this to get the VMs that have at an interval a ready% higher than 5%.

          If you want to count them, you should probably say over which interval (1 hour, 1 day...)

           

          Get-Stat -Entity (Get-Cluster -Name MyCluster | Get-VM) -Stat cpu.ready.summation -Start (Get-Date).AddDays(-1) -Instance '' -ErrorAction SilentlyContinue|

          where{$_.Value/($_.intervalSecs*10) -ge 5} |

          Select @{N='VM';E={$_.Entity.Name}},Timestamp,

             @{N='Ready%';E={"{0:p}" -f ($_.Value/($_.intervalSecs*1000))}}

          1 person found this helpful
          • 2. Re: Percentage of VMs with CPU Ready higher then 5%
            mibiras Novice

            Thanks LucD,

            I need count them just for last sampling interval (5 minutes), what I exactly need is (Number of VMs with CPU ready > 5% / Number of runnig VMs) * 100

            • 3. Re: Percentage of VMs with CPU Ready higher then 5%
              LucD Guru
              User ModeratorsCommunity WarriorsvExpert

              Something like this?

               

              $clusterName = 'MyCluster'

              $vms = Get-Cluster -Name $clusterName | Get-VM

              $vmsReady = Get-Stat -Entity $vms -Stat cpu.ready.summation -Start (Get-Date).AddMinutes(-5) -Instance '' -ErrorAction SilentlyContinue |

              where { $_.Value / ($_.intervalSecs * 10) -ge 1 } |

              Select @{ N = 'VM'; E = { $_.Entity.Name } } |

              Sort-Object -Unique


              Write-Host ("{0:p0} VMs with a ready value >= 5%" -f ($vmsReady.Count / $vms.Count))

              1 person found this helpful
              • 4. Re: Percentage of VMs with CPU Ready higher then 5%
                mibiras Novice

                $vmsReady.Count is always zero or nothing

                And I think better counter for us will be cpu.latency.average, should you also change it in script?

                • 5. Re: Percentage of VMs with CPU Ready higher then 5%
                  LucD Guru
                  Community WarriorsvExpertUser Moderators

                  In that case, the Where-clause condition has to be changed.
                  Latency is already expressed in percent.

                   

                  $clusterName = 'MyCluster'

                  $vms = Get-Cluster -Name $clusterName | Get-VM

                  $vmsHighLatency = Get-Stat -Entity $vms -Stat cpu.latency.average -Start (Get-Date).AddMinutes(-5) -Instance '' -ErrorAction SilentlyContinue |

                  where { $_.Value -ge 5 } |

                  Select @{ N = 'VM'; E = { $_.Entity.Name } } |

                  Sort-Object -Unique


                  Write-Host ("{0:p0} VMs with a latency value >= 5%" -f ($vmsHighLatency.Count / $vms.Count))

                  1 person found this helpful
                  • 6. Re: Percentage of VMs with CPU Ready higher then 5%
                    mibiras Novice

                    I think problem should be in

                    Sort-Object -Unique

                    I changed script  to:

                     

                    $vmsReady = Get-Stat -Entity $vms -Stat cpu.latency.average  -Start (Get-Date).AddMinutes(-1) -MaxSamples 1  -Instance '' -ErrorAction SilentlyContinue | where { $_.Value -ge 5 } | Select @{ N = 'VM'; E = { $_.Entity.Name } }

                     

                    And I think it produces output what I need.

                    Do you think is to OK ?

                    • 7. Re: Percentage of VMs with CPU Ready higher then 5%
                      LucD Guru
                      Community WarriorsvExpertUser Moderators

                      No, the Unique switch is there to avoid that the same VM is counted multiple times.
                      For the interval of the last 5 minutes, the Get-Stat will retrieve values at 20-second intervals.

                       

                       

                      If a VM is above the threshold more than once, it will appear more than once in the $vmsReady variable, and hence the percentage will not be correct.

                      • 8. Re: Percentage of VMs with CPU Ready higher then 5%
                        mibiras Novice

                        No, the Unique switch is there to avoid that the same VM is counted multiple times.

                        According this I suggest use switch -MaxSamples 1  in Get-Stat.

                        I know some samples should not be in same time, but this is OK

                        • 9. Re: Percentage of VMs with CPU Ready higher then 5%
                          LucD Guru
                          vExpertUser ModeratorsCommunity Warriors

                          Like this?

                           

                          $clusterName = 'MyCluster'

                          $vms = Get-Cluster -Name $clusterName | Get-VM

                          $vmsHighLatency = Get-Stat -Entity $vms -Stat cpu.latency.average -Realtime -MaxSamples 1 -Instance '' -ErrorAction SilentlyContinue |

                          where { $_.Value -ge 5 } |

                          Select @{ N = 'VM'; E = { $_.Entity.Name } }


                          Write-Host ("{0:p0} VMs with a latency value >= 5%" -f ($vmsHighLatency.Count / $vms.Count))