分析ESXI主機的網絡流量時,通常使用net-stats、pktcap-uw、nc、iperf這幾個工具。
1、net-stats
該指令可以收集端口統計資訊。可以通過net-stats -h指令顯示所有标志。最常見的是使用net-stats -l來确定所有VMkernel接口、vmnic上行鍊路和vNIC端口的交換機端口号和MAC位址。
1.1 檢視所有支援的标志
[root@localhost:~] net-stats -h
Usage:
-l : List ports in system
-a : Print absolute counts instead of per second counts
-c <start>:<end> : specify vsi-cache files instead of live kernel
-d <level> : verbose/debug level
-f : ignore version check
-h : this message
-i <interval> : Interval for stats collection (default=30 seconds)
-n <iterations> : number of iterations to run (default = 1)
-o <outfile> : output file
Specify ports of interest as one of (Prioritized List of options)
-A : Get stats for all ports on host
-S <switchName> : switch name
Lists stats for all non mgmt/test ports
-N <pnicName> : pnic name
List stats for all ports on switch that contains 'N'
-V <vmname> : VM name
Find switches that contains the VM's ports. Print stats for VM's ports and uplinks
-s : Get storage world stats
-I : Get SCSI and VSCSI storage I/O stats
-D <name> : Name of SCSI device/adapter/path or VM
To be used along with storage stat specs
Can be used multiple times
eg: net-stats -I -ta -D vmhba0 -D vmhba1
OR specify port spec on command line
-p <portid> : portNum
-t <type> : specify a string with types of stats needed
OR specify port spec in a config file
-C <cfgFile> : config file to read stats from
File Format: <portNum/switchName> <StatsSpec>
Stats Spec can contain one or more of these characters
c : Coalesce Stats: Only for vnics
i : Interrupt stats: Only for vmnics
h : Cluster and Packet size histograms
v : virtual nic stats
e : Detailed error stats
q : Queue Stats for port/nic
Q : Detailed Queue stats for the port/nic
f : Detailed Queue filter information for port/nic
W : world stats for the tx, vmnic/vmknic worlds
V : vcpu histograms
S : System time breakdown by pcpus
n : NIOC stats
p : Passthru/sriov stats
P : Detailed sriov/passthru stats
E : Enable stats collection for ENS module
For ENS lcore stats:
lcore in : vnic tx/pnic rx
lcore out : vnic rx/pnic tx
I : IOChain InputFilters stats
O : IOChain OutputFilters stats
Stats Spec for Storage stats (-I)
d : SCSI Device Stats
a : SCSI Adapter Stats
t : SCSI Path Stats
s : VSCSI Stats
Note:
net-stats reads multiple vsi nodes, one at a time, using system calls
As data in the vsi nodes are continuously updated, there is going to
be some inconsistency in numbers, hopefully, not a lot
For ENS lcore stats:
lcore in : vnic tx/pnic rx
lcore out : vnic rx/pnic tx
1.2 檢視vmkernel、vNic及MAC位址等的對應關系
net-status –l
1.3 檢視NetQueue或Receive Side Scaling (RSS)是否被vmnic激活
net-stats -A -t vW
1.4 檢視ENS module的端口狀态
net-stats -A -t E
2、Pktcap-uw
vSphere ESXi 5.5及之後版本用pktcap-uw代替了tcpdump-uw工具,tcpdump-uw工具隻能捕獲VMkernel接口級别的資料包。pktcap-uw工具還能捕獲uplink、vSwith或vnic級别的資料幀。
從下圖可以了解從虛拟機vNic到實體網卡的資料流量和抓包點:
具體抓包指令請參考:ESXI主機之pktcap-uw抓包
3、NC
NC是NetCat的縮寫,是一個老式的linux指令,用來驗證特定端口連接配接。
例如如果要驗證磁陣的iSCSI路徑及端口是否可達,可以用以下指令:
nc -z <destination IP> 3260
4、Iperf
Iperf是一個帶寬工具,它用來測試源和目的地之間的最大帶寬。它通常在VM内部使用,也可以在ESXI主機内部使用,它可以使用ESXi主機上的任何VMkernel接口,包括管理網路、磁陣網絡、vmotion網絡等。
4.1拷貝iperf3檔案
預設情況下,ESXi不允許在伺服器模式下從shell運作iperf3,解決方式是建立一個iperf的副本:
cp /usr/lib/vmware/vsan/bin/iperf3 /usr/lib/vmware/vsan/bin/iperf3.copy
4.2關閉防火牆
因為在預設情況下,iperf3運作在ESXi防火牆不允許的端口上。可以通過下面指令暫時關閉防火牆:
esxcli network firewall set --enabled false
注意:測試完後要啟用ESXI防火牆
esxcli network firewall set –enabled true
4.3目的主機(server)使用iperf3綁定IP
在目标ESXi主機上使用-s标記複制。這樣做的好處是,所有的VMkernel IP都可以被使用。是以,如果需要測試管理網絡,請将iperf3與管理IP綁定。vMotion網絡或任何其他VMkernel接口也一樣。
Server (ESXi host 1):
/usr/lib/vmware/vsan/bin/iperf3.copy -s -B [IP]
4.4 源主機(client)發送連接配接測試請求
Client (ESXi host 2):
/usr/lib/vmware/vsan/bin/iperf3.copy -c [IP]