Automation

 View Only
  • 1.  Average CPU usage with get-stat

    Posted Oct 17, 2013 05:39 PM

    With get-stat I can get average CPU Usage in MHz using the usagemhz metric.

    however, by default the maximum and minimum in MHz is not included in the data points from 2 months ago.  That is fine if I just want the average but I also need average peak values.  Is average peak CPU usage possible with powerCLI?

    The thing is that when you are getting these averages and you only have one day or one week worth of data it isn't enough to really give you a true picture- you need 2-3 months.  Haw can I get to that with PowerCLI?



  • 2.  RE: Average CPU usage with get-stat

    Posted Oct 18, 2013 08:01 AM

    You can get the minimum and maximum of the averages for the past 2 months like this for examle.

    $entity = Get-vm -Name MyVM
    $stat = "cpu.usagemhz.average"

    $start = (Get-Date).AddMonths(-2)

    Get-Stat -Entity $entity -Stat $stat -Start $start |
    Measure-Object -Property Value -Minimum -Maximum -Average

    But note that, due to aggregation, these values will not be the same as the actual minima and maxima of the collected data.

    Depending on why you want to use the values, this approximation might be sufficient though.



  • 3.  RE: Average CPU usage with get-stat

    Posted Oct 18, 2013 11:22 PM

    OK thanks for the great info.  I think really I need two things:

    First I need to take a group of VMs and see what the average CPU usage is in MHz.  It looks like just the regular

    cpu.usagemhz.average

    is just fine for that, as per this great website article I found

    http://www.lucd.info/2009/12/30/powercli-vsphere-statistics-part-1-the-basics/

    However the second thing I need is akin to the concept of the 95th percentile in vCOps.  The concept is that you are looking at your average usage, and then you are looking to see what happens during peak periods in your enviornment.  The two questions are:

    What should I expect my VMs to demand normally

    What should I be prepared for my VMs to demand during a peak usage period (example - a large accounting firm with 5000 vms during quarter end processing).

    I want to get the average and the "average peak" for my cpu.usagemhz

    From what I can see, powerCLI is great for the average.  Can it do the average peak such as a 95th percentile?

    (BTW looking forward to this new performance reporting with PowerCLI book that I see coming out on Amazon)



  • 4.  RE: Average CPU usage with get-stat

    Posted Oct 19, 2013 09:34 AM

    Ok, I think I see what you want to do.

    The following code will, per VM, display the average CPU usage and the 95 percentile CPU usage over the last 7 days.

    Note that this is a rather simple way to calculate the 95 percentile (in the book there should be more elaborate methods).

    $start = (Get-Date).AddDays(-7)
    $stat = "cpu.usagemhz.average"
    $vm = Get-VM

    Get-Stat -Entity $vm -Stat $stat -Start $start  |
    Group-Object -Property {$_.Entity.Name} | %{
       
    $calc = $_.Group | Measure-Object -Property Value -Average
       
    New-Object PSObject -Property @{
           
    VM = $_.Group[0].Entity.Name
           
    AvgCPUMhz = [Math]::Round($calc.Average)
           
    Avg95pCPUMhz = ($_.Group | Sort-Object -Property Value )[[math]::Round($calc.Count * 0.95)]
        }
    }
    | Select VM,AvgCPUMhz,Avg95pCPUMhz


  • 5.  RE: Average CPU usage with get-stat

    Posted Oct 21, 2013 05:04 PM

    OK great thanks.  This report works as I run it but inputting a VM or set of VMs and report on this one metric for the set of VMs.  In my case 'm trying to actually run this report in such a way that I am listing a set of VMs, then for each VM caclulating a certain set of properties, in which this is one.

    For example:

     

    $stat = "cpu.usagemhz.average"

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

    get-vm myvm | select name, numcpu,

    @{N="Average CPU Usage";E={

      Get-Stat -Entity $_ -Stat $statCPUMHzAvg -Start $start  |

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

      $calc = $_.Group | Measure-Object -Property Value -Average 

      New-Object PSObject -Property @{  

      AvgCPUMhz = [Math]::Round($calc.Average)  

       }

       } | Select AvgCPUMhz

      }}

    1. Is it possible to modify the report to do this?
    Also,  The output of the report is

    @{AvgCPUMHz=150}

    instead of just

    150

    2. How can I remove the @{} from the output?

    Thanks!



  • 6.  RE: Average CPU usage with get-stat
    Best Answer

    Posted Oct 21, 2013 05:18 PM

    1. You can easily adapt the Get-VM cmdlet to produce the result for 1 or a limited set of the VM

    For example:

    Get-VM -Name MyVM | Select ...

    will return the result for 1 VM called MyVM

    If you do

    Get-VM -Name My* | Select ...

    it will return results for all VMs whose name starts with "My"

    2. That's because the Select-Object produces a hash table, and PowerShell by default displays hash tables like that.

    To only get the actual value change the last Select like this

    ...

    } | Select -ExpandProperty AvgCPUMhz

    ...



  • 7.  RE: Average CPU usage with get-stat

    Posted Oct 21, 2013 06:26 PM

    works great - thanks again.