PowerCLI

 View Only
  • 1.  Sample script for retrieving VM Stats over one week

    Posted Mar 02, 2010 04:42 PM

    The attached script is a sample which I wrote to gather various stats from a VM over a period of one week. Some of the techniques in the code are borrowed from various sources including Virtu-Al, Hugo Peeters, Hal Rottenberg, and of course Luc Dekkens. I'm sure this is not the most efficient form of the script but it seems to get the job done. Suggestions for improvement are welcome. Basically it takes all VM's in a datacenter and collects a large number of stats on memory, CPU, disk and network and formats the report into a CSV file. It can easily be adapated to report only on a datacenter or a cluster by piping the VM list through the correct commands.

    Regards,

    Ed



  • 2.  RE: Sample script for retrieving VM Stats over one week

    Posted Mar 02, 2010 04:58 PM

    Great script.

    If I may make a suggestion, you can get all the data with one call to Get-Stat, just add all the metrics as an array to the -Stat parameter.

    You can then extract the required data with a Where-Object cmdlet.

    I'm pretty sure it will make the script a bit faster.

    And you populate the $row properties directly, no need to store the data first in a separate variable.

    Example

    ...
    $metrics =  "cpu.usage.average","cpu.usagemhz.average"
    $stats = Get-Stat -Stat $metrics -Start $DateStart -Finish $DateFinish
    ...
    $row.CPUUsageAvg_Avg = [Math]::Round(($stats | where {$_.MetricId -eq  "cpu.usage.average"} | Measure-Object -Property Value -Average).Average,1)
    $row.CPUUsageAvg_Max = [Math]::Round(($stats | where {$_.MetricId -eq  "cpu.usage.average"} | Measure-Object -Property Value -Maximum).Maximum),1)
    ...
    

    ____________

    Blog: LucD notes

    Twitter: lucd22