VMware Cloud Community
jingleharish
Contributor
Contributor

Stats reports

Hello-

I am looking out for a script that will provide the realtime performace report for a set of VM's. Sample report attached.

Reports can be in CSV file and graph is not mandatory. Seperate report for both CPU and Memory is required.

0 Kudos
1 Reply
LucD
Leadership
Leadership

The following script produces all the CSV files.

The input has to be provided in a CSV file with the names of the VMs you want to handle.

This CSV looks like this

Name

VM1

VM2

$vms = Import-Csv "C:\VM-list.csv" -UseCulture | %{$_.Name}
$metrics = "cpu.usage.average","cpu.usagemhz.average","mem.usage.average" $stats = Get-Stat -Entity $vms -Stat $metrics -Realtime $stats | Group-Object -Property EntityId | %{
    $filename = $_.Group[0].Entity.Name
    $cpuArr = @()
    $memArr = @()
    $_.Group | Group-Object -Property Timestamp | %{
        $cpuRow = "" | Select Timestamp,CPUAvg,CPUAvgMHz
        $memRow = "" | Select Timestamp,MemAvg
        foreach($elem in ($_.Group | where {$_.Instance -eq ""})){
            switch($elem.MetricId){
                "cpu.usage.average"{
                    $cpuRow.Timestamp = $elem.Timestamp
                    $cpuRow.CPUAvg = $elem.Value
                } 
                "cpu.usagemhz.average"{
                    $cpuRow.CPUAvgMHz = $elem.Value
                } 
                "mem.usage.average"{
                    $memRow.Timestamp = $elem.Timestamp
                    $memRow.MemAvg = $elem.Value
                }
            }
        }
        $cpuArr += $cpuRow
       
$memArr += $memRow
    }     $cpuArr | Export-Csv ("C:\" + $filename + "-CPU.csv") -NoTypeInformation -UseCulture     $memArr | Export-Csv ("C:\" + $filename + "-MEM.csv") -NoTypeInformation -UseCulture }

This script produces no graphs.

If you want graphs I would suggest to have a look at my Beyond Export-Csv: Export-Xls post.

The Export-XLS function will allow you to produce 1 XLS with each table in a seperate worksheet, including a graph.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference