Hello
Thank you for your suggestions, all ideas are welcome
The optimization part won't be done by me, I'm tasked with gathering the data, but I will suggest that it might not work as intended.
I've done some reading and currently have this PoweCLI script:
$Hosts = @(
"xx.xx.xx.1",
"xx.xx.xx.2")
Connect-viserver -Server $Hosts -user xxx -password "xxx"
$alldata = @()
$metrics = "cpu.usage.average"
foreach ($Server in $Hosts){ $stats = Get-Stat -Entity $Server -Realtime -Stat $metrics -MaxSamples 1 $stats | Group-Object -Property Entity | %{ $hoststat = "" | Select HostName, VMName, CPUAvg $hoststat.HostName = $_.name $cpu = $_.Group | where {$_.MetricId -eq "cpu.usage.average"} | Measure-Object -Property value -Average $hoststat.CPUAvg = [int]$cpu.Average $hostname = $hoststat.HostName $alldata += $hoststat } $vms = Get-Vm -Server $Server | where {$_.PowerState -eq "PoweredOn"} $stats = Get-Stat -Entity $vms -Realtime -Stat $metrics -MaxSamples 1 $stats | Group-Object -Property Entity | %{ $vmstat = "" | Select HostName, VmName, CPUAvg $vmstat.VmName = $_.name $cpu = $_.Group | where {$_.MetricId -eq "cpu.usage.average"} | Measure-Object -Property value -Average $vmstat.CPUAvg = [int]$cpu.Average $vmstat.HostName = $hostname $alldata += $vmstat }
}
$alldata | Export-Csv "c:\tmp\Data.csv" -noTypeInformation
Disconnect-viserver *
First, a stupid question:
is the data I'm gathering the current CPU load/usage or should I be checking a different stat?
This script does exactly what I need, but is slow, it takes 90 seconds to gather info from 9 hosts with 60 VMs total.
I'm looking for a way to make it faster, ideally keeping the output format unchanged, example:
"HostName","VmName or blank if Host","Value"
"Host1",,"10"
"Host1","Vm1","9"
"Host2",,"15"
"Host2","Vm1","9"
"Host2","Vm2","5"
I've found this thread:
http://communities.vmware.com/thread/341055
and I will try to rewrite the script accordingly, probably during the weekend.
Regards
Genoan