VMware Powershell Get Network Usage Metrics
VMware Powershell Get Network Usage Metrics
I was asked how it might be possible to get network usage metrics for Virtual Machines that where hosted on older versions of the VMware ESXi hypervisor the other week. The request came about as the organization in question is looking to replace a platform and wants to get a better understanding of the network traffic being processed by the estate.
First port of call with any request like this is the VMware communities, because to be honest the chances of Luc Dekens having not written something to do this over the years is pretty remote. Sure enough there are PowerShell scripts and structure that can be used as the basis to answer our question.
The requestor would ideally like to review ingress and egress data going back over an extended period of time. This isn’t achievable unless this data has been rolled up into another service (such as vROPs) as both ‘net.transmitted.average‘ and ‘net.received.average‘ are realtime only statistics. ‘net.usage.average‘ is retained for a longer period and is the sum of the received and transmitted data, so this is the metric that is going to get us as close as possible to the requirement.
LucD does an excellent job of covering the roll-up of statistics in this post
The settings in the script are based on knowing this information.
VMware Powershell Get Network Usage Metrics
The below script assumes you are already connected to a Virtual Center. If you want to focus on VMs from a particular cluster, host or datastore you can add a location/host parameter after Get-VM.
The data range can be adjusted by changing the number in () after .AddDays, currently this is looking back 7 days. The IntervalMins number should be adjusted in line with statistic roll-up configurations, for 7 days an interval of 30 mins is appropriate.
$vm = Get-VM Get-Stat -entity $vm -Start (Get-Date).AddDays(-7) -IntervalMins 30 -stat ‘net.usage.average’ | ? { $_.instance -eq "" } | select Entity,Timestamp,Value |Sort-Object Timestamp | export-csv -path C:\Temp\report.csv
The captured data is exported to a CSV, which can then be used for visualizations, charting and reporting however is needed.
Hopefully this is useful to someone!
Thanks
Simon