ifconfig 下面的一些字段(errors, dropped, overruns)

  • Post author:
  • Post category:IT
  • Post comments:0评论

一台机器经常收到丢包的报警,先看看最底层的有没有问题:

# 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

发现数值也在不停的增加。G 了一下,发现这些 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% 以上的场景应该能轻松应对。

ref:

http://serverfault.com/questions/561107/how-to-find-out-the-reasons-why-the-network-interface-is-dropping-packets

http://serverfault.com/questions/448768/cat-proc-net-dev-and-ip-s-link-show-different-statistics-which-one-is-lyi

http://www.linuxjournal.com/content/queueing-linux-network-stack

发表回复