This time I thought of doing something related to vSphere networking as while working on cases like packet drops issue, network connectivity issue and performance issues, we are also required to check every aspect of underlying network associated to cluster nodes along with underlying storage so that we can ask or point out efficiently whether we have physical or logical network issue to troubleshoot.
Attached script is a one shot solution to get all necessary information in a manner for us to efficiently capture the possible issue if at all it exists. Following traits can be gathered in few moments without wasting hours on troubleshooting. The script needs to be run on ESXi.
- ESXi information e.g. system and few VIBs version, status of virtual machines running on node
- Port numbers of the connected client associated with particular vSwitch in ESXi.
- Status and Stats of ports associated with vSwitch
- Client name, its MAC & Client port type e.g. 3 (vmkernel), 4 (PNIC) or 5 (virtual NIC)
- Tx and Rx of packets associated to ports related to individual vSwitches.
- Dropped packets associated with them.
- VLAN stats associated to every vmnic e.g. Tx, Rx packets.
- World-ID of running virtual machines.
- Ports associated with the given world-ID of virtual machines.
- Retrieve the vSwitch statistics of packet transmitted and received for ports.
- Received and transmitted packet drop for ports.
- Retrieves filter stats and information for ports.
- vSwitch associated with the port and detail of uplink assigned.
Along with above information the script is also capable of capturing the following: NIC being used, NIC driver information, their advanced parameter which can be used to modify/set properties, Rx/Tx ring buffers stats, Rx Mini (is for undersized frames), Rx jumbo (jumbo for oversized) and packet summary and stats.
#!/bin/sh
echo "//////////////////////////////Version 0.1///////////////////////////////////"
echo "///////////////// This script is created by Kapil Soni /////////////////////"
echo "////////////////////////////////////////////////////////////////////////////"
echo "////////////////////////////////////////////////////////////////////////////"
echo "Running the script...."
sleep 2
echo ""; echo "System information :===========";esxcli system version get | sed 's/^ *//'; echo ""; esxcli hardware platform get;echo "";echo "Some VIBs:===========";esxcli software vib list | grep -iE "marvin|vxrail|nsx|ptagent|ism|vsan";echo "";echo host maintenance status : ;vim-cmd hostsvc/hostsummary | grep -i maintenance | sed 's/ //g';echo "";for vid in $(vim-cmd vmsvc/getallvms | awk '{print $1}' | grep -vi Vmid);do echo vmid : $vid;vim-cmd vmsvc/power.getstate $vid;echo "";done;echo Here is the vm list;esxcli network vm list;echo "";vim-cmd vmsvc/getallvms | awk '{print $1,$2}';echo "";esxcli vsan cluster get;echo "";esxcli vsan network list;echo "";echo "";echo Cluster resync summary : ;esxcli vsan debug resync summary get;esxcli vsan debug object health summary get;echo "";echo vsan health red alerts : ;esxcli vsan health cluster list | grep -i red
echo "";echo =============================================================;echo ""
echo "vmnics detail:";esxcli network nic list; for i in $(esxcli network nic list | grep -i vmnic* | awk '{print $1}');do echo "Gathering the information for:";echo $i;vmkchdev -l | grep $i | awk '{printf "PCIslot "$1 "\n" "VID&DID "$2 "\n" "SVID&SDID "$3 "\n" "Add.Info "$4 " " $5"\n"}';esxcli network nic get -n $i | egrep -i "name|link*|cable|virtual|driver|version";echo Dropped packets and errors are :;esxcli network nic stats get -n $i | grep -iE "vmnic|dropped|errors";echo "";echo "Enabling the VLAN stats on $i for now:=========";esxcli network nic vlan stats set -e true -n $i;echo The VLAN stats for $i:;esxcli network nic vlan stats get -n $i;echo "";echo "Disabling the VLAN stats on $i:===============";esxcli network nic vlan stats set -e false -n $i;echo "";done;echo "";echo IPv4 address associated with VMK ports:;esxcli network ip interface ipv4 get
echo "";echo =============================================================;echo ""
net-stats -l;echo "";for switch in $(net-stats -l | awk '{print $4}' | grep -vi switchname | uniq);do echo "For this switch: $switch:========================";for port in $(net-stats -l | awk '{print $1}' | grep -vi portnum); do echo ""; echo Switch $switch and port $port:;echo "Status :";vsish -e cat /net/portsets/$switch/ports/$port/status 2>/dev/null | grep -i client ;echo "";echo "Stats :";vsish -e cat /net/portsets/$switch/ports/$port/stats 2>/dev/null | grep -iv "packet stats";done;done
echo "";echo =============================================================;echo ""
for nic in $(esxcli network nic list | grep -i vmnic* | awk '{print $1}');do echo "";echo Nic $nic :;echo Max supported ring buffer:;esxcli network nic ring preset get -n $nic;echo "";echo Currently set ring buffer:;esxcli network nic ring current get -n $nic;echo "";echo "Current ring stats of $nic"; vsish -e cat /net/pNics/$nic/stats | grep -iE "rxq[0-9]|txq[0-9]";echo "=========================";done;echo "";echo List of NIC drivers:;for drvr in $(esxcli network nic list | awk '{print $3}' | grep -viE "device|------" | uniq);do echo "====================";echo -n Driver name:;esxcli system module list | grep $drvr | awk '{print $1}';esxcli system module get -m $drvr | sed 's/^ *//';echo "";echo Parameters list:;esxcli system module parameters list -m $drvr;done
echo "";echo =============================================================;echo ""
echo VMs with world id : ; esxcli network vm list;echo "";for vm in $(esxcli network vm list | awk '{print $1}' | grep -viE "world|--------");do echo "For this world id :$vm following are the ports associated :==========" ;esxcli network vm port list -w $vm | grep -iw "port id" | grep -vi "uplink" | sed 's/ //' | awk '{print $3}';for j in $(esxcli network vm port list -w $vm| grep -iw "port id" | grep -vi "uplink" | sed 's/ //' | awk '{print $3}');do echo "";esxcli network port stats get -p $j;echo Port filter stats for $j:;esxcli network port filter stats get -p $j;done;echo "";esxcli network vm port list -w $vm | grep -iEw "port id|vswitch|team uplink|mac address";echo "==========================";done
Snippets:
This post has been about serving a single Bash script to have all the network related information in order to troubleshoot underlying Network issue in our vSphere environment. Script needs to be run on ESXi shell (or remotely via SSH) to collect and easily identify possible network issue, we may also redirect script output to text file as stdout will be lengthy to go through.
I am open for suggestions/feedback/improvements in order to provide intended solution. I am working on few more scripts, also upgrading the existing ones in order to accommodate few more actions to ease our day to day life. Thank you for reading through. Please be social and share it socially if found useful.






