Home | 简体中文 | 繁体中文 | 杂文 | 知乎专栏 | Github | OSChina 博客 | 云社区 | 云栖社区 | Facebook | Linkedin | 视频教程 | 打赏(Donations) | About
知乎专栏多维度架构 微信号 netkiller-ebook | QQ群:128659835 请注明“读者”

4.7. Network IO

4.7.1. netstat

netstat 监控TCP状态

#netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’
		
状态:		描述
CLOSED:		无连接是活动的或正在进行
LISTEN:		服务器在等待进入呼叫
SYN_RECV:	一个连接请求已经到达,等待确认
SYN_SENT:	应用已经开始,打开一个连接
ESTABLISHED:正常数据传输状态
FIN_WAIT1:	应用说它已经完成
FIN_WAIT2:	另一边已同意释放
ITMED_WAIT:等待所有分组死掉
CLOSING:	两边同时尝试关闭
TIME_WAIT:	另一边已初始化一个释放
LAST_ACK:	等待所有分组死掉
		

4.7.2. ss

# ss
State      Recv-Q Send-Q      Local Address:Port          Peer Address:Port
CLOSE-WAIT 1      0           192.168.3.124:19644       130.75.116.209:http
CLOSE-WAIT 1      0           192.168.3.124:31289       170.224.194.69:https
CLOSE-WAIT 1      0           192.168.3.124:64903         198.20.8.241:https
CLOSE-WAIT 1      0           192.168.3.124:64902         198.20.8.241:https
CLOSE-WAIT 1      0           192.168.3.124:27528      170.224.160.205:https
CLOSE-WAIT 1      0           192.168.3.124:10152         198.20.8.241:https
CLOSE-WAIT 1      0           192.168.3.124:18263       170.224.194.69:http
CLOSE-WAIT 1      0           192.168.3.124:18262       170.224.194.69:http
CLOSE-WAIT 1      0           192.168.3.124:27792         129.89.61.70:http
CLOSE-WAIT 1      0           192.168.3.124:27595         129.89.61.70:http
CLOSE-WAIT 1      0           192.168.3.124:28970         129.89.61.70:http
CLOSE-WAIT 1      0           192.168.3.124:28158       130.75.116.210:http
CLOSE-WAIT 1      0           192.168.3.124:26186       130.75.116.210:http
CLOSE-WAIT 1      0           192.168.3.124:26185       130.75.116.210:http
CLOSE-WAIT 1      0           192.168.3.124:42563         74.125.71.99:http
CLOSE-WAIT 1      0           192.168.3.124:42564         74.125.71.99:http
CLOSE-WAIT 1      0           192.168.3.124:63459       130.75.116.202:http
CLOSE-WAIT 1      0           192.168.3.124:63458       130.75.116.202:http
ESTAB      0      0           192.168.3.124:30829         192.168.3.17:3260
ESTAB      0      0           192.168.3.124:13234         192.168.3.15:3260
ESTAB      0      0        ::ffff:192.168.3.124:ssh        ::ffff:192.168.80.5:5                                                                                        2682
ESTAB      0      1960     ::ffff:192.168.3.124:ssh        ::ffff:192.168.80.5:5                                                                                        2957


$ ss
State      Recv-Q Send-Q                Local Address:Port                    Peer Address:Port
ESTAB      0      0                      192.168.80.1:38281                     64.4.61.72:1863
ESTAB      0      0                      192.168.80.1:54504                  112.95.240.77:8000
ESTAB      0      0                      192.168.80.1:14698                  74.125.71.125:5222
ESTAB      0      0                      192.168.80.1:14697                  74.125.71.125:5222
ESTAB      0      0                      192.168.80.1:54123                   64.12.28.171:https
ESTAB      0      0                      192.168.80.1:4225                     64.4.61.171:1863
ESTAB      0      0                      192.168.80.1:ssh                     192.168.80.5:51291
ESTAB      0      0               ::ffff:192.168.80.1:microsoft-ds          ::ffff:192.168.80.5:51094
ESTAB      0      0                      192.168.80.1:22074                  205.188.1.241:https
ESTAB      0      0                      192.168.80.1:59340                    64.4.34.213:1863
ESTAB      0      0                      192.168.80.1:9766                   91.189.89.114:https
ESTAB      0      0                      192.168.80.1:3300                      64.4.44.78:1863

		

4.7.2.1. 查看tcp流量控制相关参数值

			
root@netkiller ~ % ss -itn
State                    Recv-Q                     Send-Q                                            Local Address:Port                                           Peer Address:Port                      
ESTAB                    0                          0                                                  192.168.3.14:22                                              192.168.3.4:63044                     
	 cubic wscale:6,7 rto:212 rtt:10.681/8.769 ato:40 mss:1448 pmtu:1500 rcvmss:1392 advmss:1448 cwnd:10 ssthresh:16 bytes_acked:33428 bytes_received:9337 segs_out:377 segs_in:522 data_segs_out:360 data_segs_in:160 send 10.8Mbps lastsnd:68 lastrcv:72 lastack:56 pacing_rate 13.0Mbps delivery_rate 20.8Mbps app_limited busy:668ms rcv_rtt:7 rcv_space:28960 rcv_ssthresh:45776 minrtt:1.302
			
				

4.7.3. iftop - display bandwidth usage on an interface by host

# yum install -y iftop
	    

4.7.4. iptraf - Interactive Colorful IP LAN Monitor

[root@development ~]# yum -y install iptraf
		

4.7.5. nload: Console application which monitors network traffic and bandwidth

CentOS

# yum install nload -y
		

Ubuntu

# sudo apt-get install nload
		

运行监控命令

# nload
		
Device eth0 [172.16.3.90] (1/5):
=============================================================================
Incoming:

                                                     Curr: 10.00 kBit/s
                                                     Avg: 103.95 kBit/s
                                                     Min: 0.00 Bit/s
             ||                                      Max: 3.23 MBit/s
             ##                                      Ttl: 1090.93 GByte
Outgoing:

                                                     Curr: 12.84 kBit/s
                                                     Avg: 15.29 kBit/s
                                                     Min: 0.00 Bit/s
                                                     Max: 206.63 kBit/s
                                                     Ttl: 48.57 GByte
		

4.7.6. bwm - Bandwidth Monitor

Bandwidth Monitor 1.1.0

       Iface        RX(KB/sec)   TX(KB/sec)   Total(KB/sec)

          lo            8.366        8.366          16.732
        eth0           24.120      100.005         124.125
        eth1            0.000        0.000           0.000

       Total           32.486      108.371         140.857

Hit CTRL-C to end this madness.
		

4.7.7. iptstate - A top-like display of IP Tables state table entries

# yum install iptstate -y
		
                           IPTState - IPTables State Top
Version: 2.2.2        Sort: SrcIP           b: change sorting   h: help
Source                        Destination                  Prt  State       TTL
0.0.0.0                       224.0.0.1                    igmp               0:09:49
192.168.2.1:45981             192.168.2.1:22               tcp  TIME_WAIT     0:01:33
192.168.2.1:46009             192.168.2.1:22               tcp  TIME_WAIT     0:01:57
192.168.2.1:45915             192.168.2.1:22               tcp  TIME_WAIT     0:00:58
192.168.2.1:45975             192.168.2.1:22               tcp  TIME_WAIT     0:01:31
192.168.2.1:54922             202.141.160.110:80           tcp  TIME_WAIT     0:00:57
192.168.2.1:46000             192.168.2.1:22               tcp  TIME_WAIT     0:01:54
192.168.2.1:45973             192.168.2.1:22               tcp  TIME_WAIT     0:01:31
192.168.2.1:45855             192.168.2.1:22               tcp  TIME_WAIT     0:00:26
192.168.2.1:45990             192.168.2.1:22               tcp  TIME_WAIT     0:01:36
192.168.2.1:45822             192.168.2.1:22               tcp  TIME_WAIT     0:00:01
192.168.2.1:45926             192.168.2.1:22               tcp  TIME_WAIT     0:01:01