vNIC transmit and receive rates

The VMTN PowerCLI Community is a constant source of inspiration for blog posts. User roswellevent raised, in the thread Any way to get virtual machine Nic card usage?, the question if it was possible to get the transmit and receive rate for each vNIC in virtual machines.

Since I’m interested in all things statistics in vSphere I decided to tackle the question. Finding the metrics to use for this kind of report is not too difficult. Under the PerformanceManager Network section we find the metrics net.received.average and net.transmitted.average. And, provided your Statistics Level is set to 3 for the timeframe you want to report on, the metrics capture statistics on the device level.

Great, exactly what we need! A quick check in the Performance tab in the vSphere Client showed an additional problem to solve. The instance didn’t mention Network Adapter 1 but a number.

Background

It turns out that this number is the internal Key used for the vNICs. Could have been a bit more user-friendly in the vSphere Client 🙂

The solution is quite simple, the script fetches all the vNICs of a VM and then stores the Key together with the human-understandable name in a hash table. This hash table allows the script to replace the Instance value by the Name of the vNIC.

The script

Annotations

Line 33: The metrics the functions uses.

Line 37: Retrieve the statistical data for the virtual machines over the selected timeframe.

Line 39: The function uses the Group-Object cmdlet to split the returned statistical by VM.

Line 40-45: Look at all the vNICs connected to the VM and create a hash table, linking the Key with the Name of the vNIC.

Line 47: The Where-clause will filter out the statistical data for the vNICs of the VM

Line 48: Use the Group-Object to to split the statistical data per vNIC

Line 49-60: Create an object per vNIC per VM

Line 53: Use the hash table to fetch the “Network Adapter x” name of the vNIC

Line 54-59: Calculate the average transmit and recieve values over the selected timeframe.

Sample usage

You can use the function like this

And you can also use it in a pipeline, like this

The resulting output looks like this

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

This site uses Akismet to reduce spam. Learn how your comment data is processed.