PowerCLI

 View Only
  • 1.  Cpu ready values in % via get-stat

    Posted Jan 09, 2010 10:27 PM

    I have written a performance script in my previous post using get- stat. One of the metric I have used is the cpu.ready.summation. This gives large figure values, but I want the cpu ready figure in percentage as seen in esxtop. I was told that I can get that value by dividing it by the intervalmins which in this case would be 30 and then mulitply by 100. I tried to add that to the end of the script, but it does not seem to work. Can anyone assist in how I change the script below to the cpu ready values in percentages. The script is below:

    @{N="CPU REady";E={(get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat cpu.ready.summation | Measure-Object -Property Value -Average).Average}},



  • 2.  RE: Cpu ready values in % via get-stat

    Posted Jan 09, 2010 11:49 PM

    You have to understand the units in which the interval and the cpu.ready.summation value are returned.

    The IntervalSecs property is expressed in seconds, the metric value is returned in milliseconds (see the Unit property).

    To get the percentage becomes a standard "rule of three" calculation

    percentage = Value / (IntervalSecs * 1000) * 100
    

    That means, after some simplification of the mathematical part, your code could be something like this

    Get-VM <your-VM> | Select Name,
    @{N="CPU Ready";E={[math]::Round((Get-Stat -entity $vm `
    				-Start ((Get-Date).AddHours(-12)) `
    				-Finish (Get-Date) `
    				-stat cpu.ready.summation | %{
    	$_.Value / ($_.IntervalSecs * 10)
    } | Measure-Object -Average).Average,2)}}
    

    I also included the Round method and selected 2 decimal digits for the value.



  • 3.  RE: Cpu ready values in % via get-stat

    Posted Jan 10, 2010 11:57 AM

    Thanks Lucd

    So just to confirm this value will be the cpu ready time in %. Same as the % value we see in Esxtop.



  • 4.  RE: Cpu ready values in % via get-stat

    Posted Jan 10, 2010 12:13 PM

    Just to make this code even more complicated, I want to get values from Mon - Fri between 5.30 - 17.30, on these week days. The code I got from your previous post was :

    $businessDays = "Monday","Tuesday","Wednesday","Thursday","Friday"

    $dayStart = New-Object DateTime(1,1,1,7,30,0)

    $dayEnd = New-Object DateTime(1,1,1,17,30,0)

    and then the where statement: Where-object {$businessDays -contains $_.Timestamp.DayOfWeek -and $_.timestamp.timeofday -gt $daystart.timeofday -and $_.timestamp.timeofday -lt $dayend.timeofday}

    Would I place this code after the get-stat statement or after the multiplication code. Would this have any affect on the Math Round code. I placed it after the get-stat, after a | but then got no value for cpu ready.

    Any advice.



  • 5.  RE: Cpu ready values in % via get-stat

    Posted Jan 10, 2010 12:28 PM

    The Where-Object cmdlet is used to only pass the values for the time periods in which you are interested.

    So you would place the Where-Object cmdlet after the Get-Stat but before the Select-Object with the calculation of the Ready%.

    In abstract notation

    Get-Stat ... | Where-Object {<your-filter>} | Select-Object ...
    

    You can test if values come through the filter by using a simple "Select-Object Timestamp, Value".

    But you should be aware that you are looking at 30 minute intervals. A peak in the Ready% of some seconds will hardly be visible !

    See also my previous reply of the difference between esxtop and the Realtime value.



  • 6.  RE: Cpu ready values in % via get-stat

    Posted Jan 10, 2010 12:18 PM

    Not really, esxtop uses it's own measurement interval of 5 seconds.

    The closest you can get is to use the latest sample from the Realtime interval (20 seconds).

    Something like this

    Get-VM <your-VM> | Select Name,
    @{N="CPU Ready";E={[math]::Round((Get-Stat -entity $vm `
    				-Realtime `
    				-MaxSamples 1 `
    				-stat cpu.ready.summation | %{
    	$_.Value / ($_.IntervalSecs * 10)
    } | Measure-Object -Average).Average,2)}}
    

    This should still give you a good idea of your guest's Ready percentage.

    But the number won't fluctuate as much since the interval is 4 times longer.

    Suppose esxtop shows you 1 rather high value followed by 3 normal values, the performance metric will not show you this higher peak since you will get the sum of the four 5-second intervals which in it's turn will give you a lower percentage.

    Example:

    esxtop 10% 0% 2% 1%

    get-stat 3.25%