Need a VI toolkit scipt to Get performance stats of a particuar VM for the last 2 hours
What metrics (cpu.usage.average, disk.usage.average....) are you looking for ?
Did you try any of the pre-configured metric collections (Cpu, Memory, Disk, Network) that are available in the Get-Stat cmdlet ?
An example with the Cpu metrics
get-vm <VM-name> | Get-Stat -Cpu -Start (Get-Date).addhours(-2) -IntervalMins 2 -MaxSamples 60
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What metrics (cpu.usage.average, disk.usage.average....) are you looking for ?
Did you try any of the pre-configured metric collections (Cpu, Memory, Disk, Network) that are available in the Get-Stat cmdlet ?
An example with the Cpu metrics
get-vm <VM-name> | Get-Stat -Cpu -Start (Get-Date).addhours(-2) -IntervalMins 2 -MaxSamples 60
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello LucD,
Grate fan of you!!!
Could you suggest to modifiy the code to get vm details which having x% of cpu usges for x min in last 7 days ?
The problem is that the metric data for the last 7 days is aggregated (Historical Interval 2) and that it only gives an average over an interval of 30 minutes.
I'm afraid that an average over a 30 minute interval doesn't really allow you to produce what you want.
For more background info on intervals and aggregation have a look at PowerCLI & vSphere statistics – Part 1 – The basics
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for responce,
Is it possible to get avrge,min, max CPU of last 7 days like in vcenter view VM>Monitor> Prerfomance > Advance #Priode = 7days
Yes, but be aware that these are the Minimum and Maximum of the Averages, not absolute minimums and maximums.
And again the values are over a 30-minute interval.
Is that waht you want?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
OK that will work for me
You could do something like this
$vmName = 'MyVM'
$vm = Get-VM -Name $vmName
Get-Stat -Entity $vm -Stat 'cpu.usage.average' -Start (Get-Date).AddDays(-7) |
Measure-Object -Property Value -Minimum -Maximum -Average |
Select-Object @{N = 'VM'; E = {$vm.Name}},
@{N='Minimum';E={[math]::Round($_.Minimum,1)}},
@{N='Average';E={[math]::Round($_.Average,1)}},
@{N='Maximum';E={[math]::Round($_.Maximum,1)}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
How to get details for all VM in VC
if i tried
$vmName = '*'
not good output
and if i tried
Get- VM | Get-Stat -Stat 'cpu.usage.average' -Start (Get-Date).AddDays(-7) |
then
vm1, vm2,vm3.... 7 8 50 like this
please suggest
You can do something like this
$vms = Get-VM
Get-Stat -Entity $vms -Stat 'cpu.usage.average' -Start (Get-Date).AddDays(-7) -ErrorAction SilentlyContinue |
Group-Object -Property Entity -PipelineVariable group |
ForEach-Object -Process {
$group.Group | Measure-Object -Property Value -Minimum -Maximum -Average |
Select-Object @{N = 'VM'; E = {$group.Name}},
@{N='Minimum';E={[math]::Round($_.Minimum,1)}},
@{N='Average';E={[math]::Round($_.Average,1)}},
@{N='Maximum';E={[math]::Round($_.Maximum,1)}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference