VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

Average Network throughput for a VM with PowerCLI

I would like to get the average network throughput for a VM with PowerCLI including all virtual NICs the VM has for the last week (not including NFS or storage-related traffic).

How should I best add that to this report:

get-vm myvm | select name, numcpu

Thanks!

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-VM | 
Select Name, @{N="Avg Network Throughput MBPs";E={
    [
math]::Round((Get-Stat -Entity $_ -Start (Get-Date).AddDays(-7) -Stat "net.throughput.usage.average" |
   
where {$_.Instance -eq ""} |
   
Measure-Object -Property Value -Average | Select -ExpandProperty Average)/1KB,2)
}}

The script only takes the aggregated value for all vNICs (the one where the Instance is an empty string).

Then it takes the average and converts the KBPs to MBPs.


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

View solution in original post

0 Kudos
25 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-VM | 
Select Name, @{N="Avg Network Throughput MBPs";E={
    [
math]::Round((Get-Stat -Entity $_ -Start (Get-Date).AddDays(-7) -Stat "net.throughput.usage.average" |
   
where {$_.Instance -eq ""} |
   
Measure-Object -Property Value -Average | Select -ExpandProperty Average)/1KB,2)
}}

The script only takes the aggregated value for all vNICs (the one where the Instance is an empty string).

Then it takes the average and converts the KBPs to MBPs.


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

0 Kudos
TheVMinator
Expert
Expert
Jump to solution

OK great thanks again.

0 Kudos
bvi1006
Enthusiast
Enthusiast
Jump to solution

Hi,

When I run this I get The metric counter "net.throughput.usage.average" doesn't exist for entity....

Does anyone know why?
Thanks!

0 Kudos
bvi1006
Enthusiast
Enthusiast
Jump to solution

Looks like (maybe it's my version of esx or vsphere, but I have to use

net.usage.average


LucD
Leadership
Leadership
Jump to solution

The net.throughput.usage.average counter requires statistics level 3, perhaps that is the cause of the problem ?


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

bvi1006
Enthusiast
Enthusiast
Jump to solution

thanks, probably it !

Is there a way to get the top talkers (vms) to the Datastores?

Thanks!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You might want to look at datastore.write.average and datastore.read.average for VMs.

These require statistics level 2.


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

Madmax01
Expert
Expert
Jump to solution

@Lucd: net.throughput.usage.average    is not working for me.  guessing it's  for 5.5?  or lower then 5.5?  then with 5.1 it's not working.

Anyway  i have planned to query Stats from >1000 VM's.

with the normal translated cmdlets  its horrible slow.

i remember some threads where somebody tested to talk nativ with the Api without translation.

Anybody does have knowledge through that?  so because it would be massive time saving.

thx

max

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That counter is available in vSphere 5.5, but make sure you are at statistics level 3 to get it.

net-throughput.png

You might want to give my Get-Stat2 a try. It should be faster than the Get-Stat cmdlet.


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

Madmax01
Expert
Expert
Jump to solution

Hi LucD,

thx for the Info.

Just a Mind-question.   Is it primary Possible to use new Function as nativ cmdlets?  So what i mean > is it possible to have  "Get-Stat2"  as cmdlet started through powercli?  would like to avoid loading up in script directly. once a new function is usefull > would be good starting up with powercli directly.

PS:  would be happy if you could give us short info differences between stat + stat2 Smiley Wink.

muchas thx

max

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I did some annotations in my 1st publication of my Get-Stat2 function.

See Datastore usage statistics

The difference with the Get-Stat cmdlet that comes with PowerCLI, is that my Get-Stat2 function uses the same underlying PerformanceManager properties and methods.

The explanation that my function tends to be faster, is most probably due to the fact that I had take less aspects into account, and that I could optimise my function for the functionality I wanted from the function. While the PowerCLI Dev Team has to code more general.

And yes, a PowerShell function can be used just like a cmdlet.

I store my often used functions in my personal PowerShell profile.


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

0 Kudos
Madmax01
Expert
Expert
Jump to solution

Hi Lucd,

many thx.  i pushed it into the Profile. works fine.  So now but the Difference beetween get-stat and get-stat2 are confusing me.

follwoing code i used:

1:

(get-vm test |get-stat -stat net.usage.average -Start (get-date).date.adddays(-30) |measure-object value -average).average

2:

(get-stat2 -Entity $vm.extensiondata -Stat "net.usage.average" -Start (get-date).date.adddays(-30) -Finish (get-date) -Interval "HI3" |measure-object value -average).average

1: = 126.19

2: = 625.60

so i ever though that the get-stat is using the correct Interval ?  so seems to be it's using not correct ones.

If i push for Version 1:   -IntervalSec  7200  > then i get same Value then  from get-stat2

are i'am wrong or was it working for a specific version of powercli to have correct Interval once using   -Start + -Finish?

but in my test the execution was amazing fast Smiley Wink >5x faster then the normal cmdlet

thx

Best regards

Max

PS: could you please have a look what i have done false? So because with get-stat  everything is working (but runs several hours). But with get-stat2   i get errors after i pooling through some vm's. thx.

-Instance parameter invalid for requested stat: net.usage.average. Valid values are: "" At C:\Users\xxx\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:179 char:9 +         Throw "-Instance parameter invalid for requested stat: $st.`nValid value ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~     + CategoryInfo          : OperationStopped: (-Instance param... values are    : "":String) [], RuntimeException     + FullyQualifiedErrorId : -Instance parameter invalid for requested stat:    net.usage.average. Valid values are: ""

0 Kudos
Madmax01
Expert
Expert
Jump to solution

Hi theire,

ok found the Problem.  get-stat2 is stopping once attaching an shuted down vm which is longer offline then the interval time.   i integrated now a PowerState query for (get-vm). now get-stat2 script is running.

get-stat is running through > and alerts at the end.

now i will run the script.   Smiley Wink nosy about the time difference.  other ones was  ~3h running. now i test with that Smiley Wink.

Best regards

Max

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid that is how the PerformanceManager methods work.

They look at the start of the interval, and if no data is there, they seems to return nothing.


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

0 Kudos
Madmax01
Expert
Expert
Jump to solution

Hi Lucd,

no Problem anyway Smiley Wink. i'am glad that's working so fast.   output of 1200 Vm's     with average+maximum  was finished in  ~30min.  hat's 6 times faster.  holy Smiley Wink.

i have the Fealing that PowerCli is not prepared from DevTeam for a bigger Farm.  nearly every command runs slow.  ;(. they support a Mass vm's per Esx/vCenter > but code is not prepared using it like that. haha ;(.

Also i won little time for installing the XMLSerializers.

Luc  > you know maybe how to analyze the Code from the current cmdlets beeing able maybe changing it to a faster ones?  don't know where they are hidden.

Best regards

Max

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The PowerCLI Dev Team has to write code that is a "fit for all", and that does a lot of additional computations.

They are for example selecting/calculating a number of properties that are not provided directly by the API.

That's afaik where a lot of the overhead goes into.

By using the API directly (the Get-View cmdlet was a stroke of genius in that sence) one can optimise the code.

But it requires knowledge of the API and some additional time investment in the coding of your scripts/functions.

Note that the PowerCLI Dev Team also helped by providing the 'Get-View -ViewType ... -Property ... ' parameterset.

And don't forget the way the ExtensionData property works.

These are all timesavers.

To analyse the code you can use the Onyx Project, but that will only show you (most of) the API that are used.

It will not show you what other calculations are done on the data returned by the API calls.

I did write some optimised code for often used functions (Get-Stat2, Get-VIEventPlus...), and there are some others available in the blogosphere.

But in the end, to have optimised code, you will have to do some coding yourself I'm afraid, since you know best what works best in your environment.


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

0 Kudos
Madmax01
Expert
Expert
Jump to solution

thx LucD > you're completely right. wish nice sunday Smiley Wink

0 Kudos
AlbertWT
Virtuoso
Virtuoso
Jump to solution

OK, after increasing the Statistics to level 3 today, would it be possible to run the same PowerShell script to get the stats for the past months or weeks ?

/* Please feel free to provide any comments or input you may have. */
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid not.

The aggregation only starts collecting that data today.

You'll have to wait a month


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