Automation

 View Only
  • 1.  Get-stat with hung vm cpu process

    Posted Sep 05, 2013 08:31 PM

    I am thinking to produce a daily report of vms with hung process -  vms with an average of cpu utilization 80%+ over the last 4 fours is a sign and needs to be look up.

    This script will kick off everyday at 5am and sweep 500+ vms, is there anything else I should put in the consideration?

    $vm = "abcd"

    $statcpu = Get-Stat -Entity $vm -Stat cpu.usage.average -Start (Get-Date).AddHours(-4) -Finish (Get-Date).AddHours(-0)

    $Avgcpu = $statcpu | where {$_.Value -ne 0} | Measure-Object -Property value -Average -Maximum | select Average

    if ($Avgcpu.Average -gt 80) {write-host $vm}



  • 2.  RE: Get-stat with hung vm cpu process

    Posted Sep 05, 2013 09:16 PM

    Your script is ok, but instead of calling Get-Stat 500+ times, I would only call it once with all 500+ VMs

    And then use the Group-Object cmdlet to split the results per VM.

    Something like this

    $vms = Get-VM

    $now = Get-Date

    Get-Stat -Entity $vms -Stat cpu.usage.average -Start $now.AddHours(-4) |

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

        $avgCpu = $_.Group | Where {$_.Value -ne 0} | Measure-Object -Property Value -Average |

            Select -ExpandProperty Average

        if($avgCpu -gt 80) {$_.Name}

    }

    You will have to change the Get-VM to get the 500+ VMs you want to monitor