PowerCLI

 View Only
Expand all | Collapse all

Collecting Performance Data with Powershell.

  • 1.  Collecting Performance Data with Powershell.

    Posted Feb 19, 2010 10:26 AM

    Hi all

    I have a script that I created with a huge amount of help from the internet :smileyhappy: for collecting CPU ready values. I am also wanting to collect the following performance information.

    CPU BUSY

    VM Balloning

    Network I/O

    Disk I/O

    I know the CPU ready script below uses the SDK to bring down information for the last hour and then creates an average. Could I just swap the SDK references for the information about? or do I need to do more.

    Thanks for all your help.

    #Gettin CPU Ready Values for Last Hour

    $filename = "Cpuready"

    echo "Gettin CPU Ready Values for Last Hour"

    $table = @()

    $vms = @((Get-VM | Where {$_.PowerState -eq "PoweredOn"}) | Sort Name)

    $i = 1

    $j = $vms.Length

    ForEach ($VM in $VMs){

    Write-Progress -Activity "Checking CPU Ready Information" -Status "$VM ($i of $j)" -PercentComplete (100*$i/$j)

    For ($cpunum = 0; $cpunum -lt $VM.NumCpu; $cpunum++){

    $Details = "" | Select VM, VMHost, CPU, PercReady

    $Details.VM = $VM.Name

    $Details.VMHost = $VM.Host

    $Details.CPU = $cpunum

    $Details.PercReady = ::Round((($VM | Get-Stat -Stat Cpu.Ready.Summation -RealTime | Where {$_.Instance -eq $cpunum} | Measure-Object -Property Value -Average).Average)/200,1)

    $table += $Details

    }

    $i++

    }

    $table | Export-Csv $outputDir\data\$date.$viserver.$filename.csv -NoTypeInformation



  • 2.  RE: Collecting Performance Data with Powershell.

    Posted Feb 19, 2010 12:07 PM

    The important part of the script (which doesn't use any SDK methods or properties) is the Get-Stat cmdlet.

    If you add the required additional metrics on the -Stat parameter, it is quite straightforward.

    The metrics:

    CPU BUSY cpu.used.summation

    VM Ballooning mem.vmmemctltarget.minimum

    Network I/O net.usage.average

    Disk I/O disk.usage.average

    These values can be obtained in a single call to Get-Stat.

    $stats = $VM | Get-Stat -Stat cpu.used.summation,mem.vmmemctltarget.minimum,net.usage.average,disk.usage.average -RealTime
    

    In the script you can extract the required values by filtering on the metric.

    For example, to get the net.usage.average you could do

    ($stats | where {$_.MetricId -eq "net.usage.average"} | Measure-Object -Property Value -Average).Average
    

    For the ballooning metric you will have to decide what to use, there is only a minimum and a maximum metric, no average.

    In my PowerCLI & vSphere statistics – Part 1 – The basics post there is a link to all the available metrics.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 3.  RE: Collecting Performance Data with Powershell.

    Posted Mar 10, 2010 01:26 PM

    LucD

    I am so sorry I havent responded before now, I was pulled from doing this to work on a vSphere migration for one of my companys large customers. First time I had used vSphere after doing my VCP4 back in November :smileysad: had to remind myself of so much.

    I will experament with the above and give you some feedback ASAP.

    Thanks very much for the infomration.

    Thanks

    Phil



  • 4.  RE: Collecting Performance Data with Powershell.

    Posted Mar 15, 2010 02:24 PM

    Had a go with creating a new script myself rather then using one I found online and butchering it.

    $filename = "Memstats"

    Connect-VIServer

    echo "Memstats"

    $table = @()

    $vms = @((Get-VM | Where {$_.PowerState -eq "PoweredOn"}) | Sort Name)

    ForEach ($VM in $VMs){

    Get-VM $VM |Get-Stat -Stat mem.vmmemctl.average -maxsamples 36 -intervalMins 120

    $Details = "" | select VM, VMhost, Time, Ballon_KBps

    $Details.VM = $VM.Name

    $Details.VMhost = $VM.host

    $Details.Time = $VM.Timestamp

    $Details.Ballon_KBps = $VM.Value

    $table += $Details

    }

    $table | Export-Csv d:\testballon.csv -NoTypeInformation

    that’s what I have but for some reason that I cannot fathom out I am not getting the Timestamp and the Value in the output CSV? it is also outputting on the screen as well.

    Any ideas where I am going wrong? I think it is $VM as the fields are not found in the $VM variable, I have tried to remove it but nothing happens and also adding a variable to it doesn’t seem to work.

    Thanks

    Phil



  • 5.  RE: Collecting Performance Data with Powershell.
    Best Answer

    Posted Mar 15, 2010 02:37 PM

    You are correct, the statistics values are not in the $vm variable.

    The reason you see the data on the screen is because you're not storing the output of the Get-Stat cmdlet in a variable or piping it to the next code block.

    In this adaption I pipe the output of the Get-Stat to a ForEach-Object code block.

    #Gettin CPU Ready Values for Last Hour
    $filename = "Memstats"
    Connect-VIServer
    echo "Memstats"
    
    $table = @()
    
    $vms = @((Get-VM | where {$_.PowerState -eq "PoweredOn"}) | Sort Name)
    foreach ($VM in $VMs){
    	Get-Stat -Entity $vm -Stat mem.vmmemctl.average -maxsamples 36 -intervalMins 120 | %{
    		$Details = "" | select VM, VMhost, Time, Ballon_KBps
    		$Details.VM = $VM.Name 
    		$Details.VMhost = $VM.host 
    		$Details.Time = $_.Timestamp
    		$Details.Ballon_KBps = $_.Value 
    		$table += $Details
    	}
    }
    $table | Export-Csv d:\testballon.csv -NoTypeInformation
    

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 6.  RE: Collecting Performance Data with Powershell.

    Posted Mar 16, 2010 02:06 PM

    OK I ran that script and it compleats in a few seconds and the CSV is blank.....

    what does the mmmstd* in the GET-VM do? and I can also see the % at the end of the GET-STAT, what does that do?

    Thanks

    Phil



  • 7.  RE: Collecting Performance Data with Powershell.

    Posted Mar 16, 2010 02:15 PM

    That was a type, the line is corrected now.

    The % character is an alias for the Foreach-Object cmdlet.

    It takes each object coming from the Get-Stat cmdlet, through the pipeline (|) and executes the lines in the script-block (code between curly braces) on the object. The object coming from the pipeline is repesented by the $_ vriable.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 8.  RE: Collecting Performance Data with Powershell.

    Posted Mar 16, 2010 02:20 PM

    I removed the mmmstd* as i couldnt see what it was doing.

    and it all works now. I need to test it to make sure it is pocking up the correct figures but it looks good.

    Thanks for all your help.



  • 9.  RE: Collecting Performance Data with Powershell.

    Posted Mar 18, 2010 11:49 AM

    Hi there,

    i'am also playing around with Performance Querys.

    primary for all the "Summation" counters i have a Problem.

    For example Vmware advice that "CPU Ready" should not be higher then 5%. so 5%=1000ms.

    in this Case i'am not quiet sure, but i think theire where some changes around Esx 3.5 U1. i don't remember but since an special Version the -IntervalSecs 20 was not working anymore correct. and the Code was not changed for Vsphere as a VM Technical Support told me.

    i opend several Cases because of following Problem:

    for example:

    A costumer told me that he has some Problems with his VM. He ments Performance Problem, but could't not exactly clarify which counter exactly.

    so in this Case it was also interesting to check "CPU Ready" how long the CPU was waiting for his CPU Ressources

    But it seems to be that their are some Problems, because it's not possible to query an ~usable Value for a specified time (last day, week, month, costum).

    the strange thing is, i will not get the correct Value for (summation counters) which the VM had at the Problem time. also little problem with other Rollup Stat "average" counters

    i attach some pictures.

    i had theire 2 Problems:

    1: ver high cpu load in ~ 5 min Steps (>90% cpu load)i marked a time (07:10:40) Live-Time1.jpg

    i made an costum Chart to have a backward sight:2 hours back. so i marked nearly the same time (07:10:00) Cotum1.jpg

    So at this time the CPU Load was at about >26%. and no grave changes. so these are very high differences.

    so these seems to be that they are not working anymore with 20sec interval

    2: Query for CPU-Ready

    real-time.jpg

    lastday.jpg

    costum-chart.jpg

    so as more, longer i queryied Backward as higher was the output value.

    so in this case it's nearly not possible that a VM had 31431 ms Ready value. this would be 155% ready value.

    They checked nearly everything, and told me that this is marked official as a "Bug" and was forwarded to the Developers.

    So until now with Vsphere U1, Problem still exists and i couldn't tell my costumer how high was the value in a specified time.

    we had to avoiding this right now with "Nworks" Monitoring to have an external Database. we also trying to use the new Alert-triggers für a special Condition Time of CPU-Ready.

    Best Regards

    Max



  • 10.  RE: Collecting Performance Data with Powershell.

    Posted Apr 14, 2010 11:40 AM

    Hello bulletp31

    If I run your script I get this error.

    The term 'Math::Round' is not recognized as the name of a cmdlet, function, script file......

    regards, Sven



  • 11.  RE: Collecting Performance Data with Powershell.

    Posted Apr 14, 2010 11:42 AM

    There should be square brackets around math.

    They are probably removed by the forum software.

    Robert



  • 12.  RE: Collecting Performance Data with Powershell.

    Posted Apr 14, 2010 12:11 PM

    thanks Robert!

    solved :smileyhappy:

    regards, Sven