VMware Cloud Community
gboskin
Enthusiast
Enthusiast
Jump to solution

Get performance stats of a particuar VM for the last 2 hours

Need a VI toolkit scipt to Get performance stats of a particuar VM for the last 2 hours

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
DD_DeenDayal
Contributor
Contributor
Jump to solution

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 ?

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
DD_DeenDayal
Contributor
Contributor
Jump to solution

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  

 

DD_DeenDayal_0-1671109394405.png

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
DD_DeenDayal
Contributor
Contributor
Jump to solution

OK that will work for me

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
DD_DeenDayal
Contributor
Contributor
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos