VMware Cloud Community
downatone
Contributor
Contributor

Cmdlet get-stat not limiting results as expected

I have the following command:

get-vm | get-stat -Network -Stat net.usage.average -IntervalSecs 3600 | clip

The 2 parameters that aren't limiting as I expected are Stat and IntervalSecs.

1) I just want net.usage.average stats not, but its currently returning net.transmitted.average & net.received.average as well.

2) I only want the last hours worth of network data, seems to be returning the last 2 days thereabouts ...

What needs tweaked to get this going as expected?

0 Kudos
2 Replies
LucD
Leadership
Leadership

The -Network parameter is a package of the following 3 metrics: net.usage.average, net.received.average and net.transmitted.average.

With the -Stat parameter you ask for 1 or more specific metrics.

The Get-Stat cmdlet by default returns all data available for the interval you specified.

To get what you want use the Get-Stat cmdlet like this

Get-VM <VM-name> | Get-Stat -Stat net.usage.average -Start (Get-Date).Addminutes(-60)

This will return data for the last hour.

If you want to see for example the last 4 hours you can do

Get-VM <VM-name> | Get-Stat -Stat net.usage.average -Start (Get-Date).Addhours(-4)

Note that in this case the interval will jump to 5 minutes since the 20 second intervals are only kept for +/- 1 hour.


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

0 Kudos
downatone
Contributor
Contributor

Thanks for the explanation in regards to -Network & -Stat, that cleared that one up.

Also the get-date with add hours function works like a treat.

cheers

0 Kudos