Hi, I am newbie here, can i have a sample of script for 3 minutes interval in 1 hour?
Ok, try something like this
$vms = Get-VM
Get-Stat -Entity $vms -Stat cpu.usagemhz.average -Instance "" -Realtime -Start (Get-Date).AddHours(-1) | `
Group-Object -Property EntityId,{[math]::Floor(($_.Timestamp.Hour * 60 + $_.Timestamp.Minute)/2)} | %{
New-Object PSObject -Property @{
VM = $_.Group[0].Entity.Name
Timestamp = (@($_.Group | Sort-Object -Property Timestamp))[0].Timestamp
CpuAvg2 = [math]::Round(($_.Group | Measure-Object -Property Value -Average).Average,2)
}
} | Select VM,Timestamp,CpuAvg2
The Realtime interval uses a 20 seconds interval.
Witht the Group-Object cmdlet the script gets all the values together that belong to the same 2 minute interval.
Once that is done, the average is done with the Measure-Object cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Do you want that for ESX(i) hosts or guests ?
As an aside, this is only possible with the Realtime statistics.
See my PowerCLI & vSphere statistics – Part 1 – The basics post for further details about intervals.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am sorry for leaking some info, its for GUESTS
Ok, try something like this
$vms = Get-VM
Get-Stat -Entity $vms -Stat cpu.usagemhz.average -Instance "" -Realtime -Start (Get-Date).AddHours(-1) | `
Group-Object -Property EntityId,{[math]::Floor(($_.Timestamp.Hour * 60 + $_.Timestamp.Minute)/2)} | %{
New-Object PSObject -Property @{
VM = $_.Group[0].Entity.Name
Timestamp = (@($_.Group | Sort-Object -Property Timestamp))[0].Timestamp
CpuAvg2 = [math]::Round(($_.Group | Measure-Object -Property Value -Average).Average,2)
}
} | Select VM,Timestamp,CpuAvg2
The Realtime interval uses a 20 seconds interval.
Witht the Group-Object cmdlet the script gets all the values together that belong to the same 2 minute interval.
Once that is done, the average is done with the Measure-Object cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Just noticed you changed the 2 minutes interval into a 3 minutes interval.
No problem, change this
Group-Object -Property EntityId,{[math]::Floor(($_.Timestamp.Hour * 60 + $_.Timestamp.Minute)/2)} | %{
into this
Group-Object -Property EntityId,{[math]::Floor(($_.Timestamp.Hour * 60 + $_.Timestamp.Minute)/3)} | %{
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Great, the script is helpful.
By the way, can I know why I couldnt get the output for Network input / output by using the command below:
i) net.packetsRx.summation
ii) net.packetsTx.summation
isn't it that I need to increase the stats level in my system?
Yes, those 2 metrics live in level 3.
So each Historical Interval where you want to use these should have at least level 3.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry for interrupted, can i know why the script you provided to me only displaying an Average CPU load for 1 VM? since i have 63 VMS, can i know how to list down all Average CPU load for each?
The first line
$vms = Get-VM
will get all the guests (VMs) in the variable $vms.
If you do a Get-VM, do you see all your guests ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Alright, thanks again LucD