ifconfig 查看網絡丟包


一台機器經常收到丟包的報警,先看看最底層的有沒有問題:

# ethtool  em2 | egrep 'Speed|Duplex'
        Speed: 1000Mb/s
        Duplex: Full

# ethtool  -S em2 | grep crc
     rx_crc_errors: 0

Speed, Duplex, CRC 之類的都沒問題,基本可以排除物理層面的干擾。

通過 ifconfig 可以看到 overruns 字段在不停的增大:

# for i in `seq 1 10`; do ifconfig em2 | grep RX | grep overruns; sleep 1; done

dropped 出現問題的倒是遇到過幾次,overruns 的倒是第一次遇到,再看看下面這個:

# ethtool  -S em2 | grep drop
     dropped_smbus: 0
     tx_dropped: 0
     rx_queue_0_drops: 26649441
     rx_queue_1_drops: 26096911
     rx_queue_2_drops: 22712954
     rx_queue_3_drops: 16581572
     rx_queue_4_drops: 27349880
     rx_queue_5_drops: 6178622
     rx_queue_6_drops: 19882243
     rx_queue_7_drops: 18802558

發現數值也在不停的增加。Google了一下,發現這些 errors, dropped, overruns 表示的含義還不大一樣。根據這篇文檔的解釋:

# ifconfig em2
em2       Link encap:Ethernet  HWaddr AC:85:3D:A9:03:0D  
          inet addr:211.211.211.211  Bcast:211.211.211.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:17141208886 errors:0 dropped:0 overruns:164254181 frame:0
          TX packets:14685534428 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2619578349554 (2.3 TiB)  TX bytes:1479317006067 (1.3 TiB)
          Memory:94b00000-94b20000
  • RX errors: 表示總的收包的錯誤數量,這包括 too-long-frames 錯誤,Ring Buffer 溢出錯誤,crc 校驗錯誤,幀同步錯誤,fifo overruns 以及 missed pkg 等等。
  • RX dropped: 表示數據包已經進入了 Ring Buffer,但是由於內存不夠等系統原因,導致在拷貝到內存的過程中被丟棄。
  • RX overruns: 表示了 fifo 的 overruns,這是由於 Ring Buffer(aka Driver Queue) 傳輸的 IO 大於 kernel 能夠處理的 IO 導致的,而 Ring Buffer 則是指在發起 IRQ 請求之前的那塊 buffer。很明顯,overruns 的增大意味着數據包沒到 Ring Buffer 就被網卡物理層給丟棄了,而 CPU 無法即使的處理中斷是造成 Ring Buffer 滿的原因之一,上面那台有問題的機器就是因為 interruprs 分布的不均勻(都壓在 core0),沒有做 affinity 而造成的丟包。
  • RX frame: 表示 misaligned 的 frames。

對於 TX 的來說,出現上述 counter 增大的原因主要包括 aborted transmission, errors due to carrirer, fifo error, heartbeat erros 以及 windown error,而 collisions 則表示由於 CSMA/CD 造成的傳輸中斷。

在梳理這些 error/drop/discard 的時候,由於涉及到不同的 NIC 型號,ethtool/netstat 或者是直接從 proc 里面獲取到的數據所代表的意思還不完全一樣,比如上面通過 ethtool 得到的「丟包」是通過 rx_queue_NUM_drops 這個字段表示的,而通過 netstat 看到的卻是 RX-OVR 表示的,一個是 overruns 一個是 dropped,字面意思完全不同:

# netstat -i | column  -t
Kernel  Interface  table
Iface   MTU        Met    RX-OK        RX-ERR  RX-DRP  RX-OVR     TX-OK        TX-ERR  TX-DRP  TX-OVR  Flg
em2     1500       0      17159519100  0       0       164254181  14701510290  0       0       0       BMRU

不管是使用何種工具,最終的數據無外乎是從下面這兩個文件獲取到的:

  1. /sys/class/net/em2/statistics/
  2. /proc/net/dev
# cat /proc/net/dev | column  -t
Inter-|            Receive      |        Transmit
face               |bytes       packets  errs      drop       fifo  frame  compressed  multicast|bytes  packets      errs  drop  fifo  colls  carrier  compressed
em2:2621515020998  17153788154  0        0         164254181  0     0      0           1480433225509    14696703883  0     0     0     0      0        0

對於上面出現的若干種問題,一方面是做好監控,另外一方面是出現問題的時候及時的想到各種的可能,無外乎那么幾種。Google 過程中發現了 stackexchange 上還沒人回答的問題,結合上面的,我順便回答了一下,基本,遵循里面的四點,95% 以上的場景應該能輕松應對。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM