Linux网络统计工具/命令-阿里云开发者社区

开发者社区> boxti> 正文

Linux网络统计工具/命令

简介:
+关注继续查看

我在Linux(基于CentOS 或者 Debian 的发行版)中该如何查看当前网络端口吞吐量的统计信息?在Linux操作系统中如何查看当前内核snmp计数器以及网络端口的统计信息?

你可以使用以下任何一个命令:

nstat 命令 : 网络统计工具

键入以下命令:


  1. # nstat

输出样例:


  1. #kernel
  2. IpInReceives 133243 0.0
  3. IpInDelivers 133243 0.0
  4. IpOutRequests 92904 0.0
  5. IcmpOutErrors 97 0.0
  6. IcmpOutTimeExcds 97 0.0
  7. IcmpMsgOutType3 97 0.0
  8. TcpActiveOpens 538 0.0
  9. TcpEstabResets 56 0.0
  10. TcpInSegs 129837 0.0
  11. TcpOutSegs 89720 0.0
  12. TcpRetransSegs 42 0.0
  13. TcpOutRsts 704 0.0
  14. UdpInDatagrams 3255 0.0
  15. UdpNoPorts 97 0.0
  16. UdpOutDatagrams 3270 0.0
  17. Ip6OutNoRoutes 206 0.0
  18. TcpExtTW 141 0.0
  19. TcpExtDelayedACKs 508 0.0
  20. TcpExtDelayedACKLocked 1 0.0
  21. TcpExtDelayedACKLost 42 0.0
  22. TcpExtTCPHPHits 117659 0.0
  23. TcpExtTCPPureAcks 2158 0.0
  24. TcpExtTCPHPAcks 605 0.0
  25. TcpExtTCPSackRecovery 1 0.0
  26. TcpExtTCPLossUndo 16 0.0
  27. TcpExtTCPSackFailures 4 0.0
  28. TcpExtTCPFastRetrans 1 0.0
  29. TcpExtTCPSlowStartRetrans 3 0.0
  30. TcpExtTCPTimeouts 33 0.0
  31. TcpExtTCPDSACKOldSent 40 0.0
  32. TcpExtTCPDSACKRecv 5 0.0
  33. TcpExtTCPAbortOnData 120 0.0
  34. TcpExtTCPAbortOnClose 55 0.0
  35. TcpExtTCPSackShiftFallback 9 0.0
  36. IpExtInOctets 180131682 0.0
  37. IpExtOutOctets 7289106 0.0

ss 命令 : 查询套接字工具

要查看统计汇总, 输入:


  1. # ss -s

输出样例:


  1. Total: 786 (kernel 804)
  2. TCP: 65 (estab 40, closed 7, orphaned 0, synrecv 0, timewait 6/0), ports 56
  3. Transport Total IP IPv6
  4. * 804 - -
  5. RAW 1 1 0
  6. UDP 12 9 3
  7. TCP 58 52 6
  8. INET 71 62 9
  9. FRAG 0 0 0

查看ss 命令教程 获取更多信息。

netstat 命令 : 不错的显示套接字信息的旧工具

查看所有网络端口以及汇总信息表,输入:


  1. # netstat -i

输出样例:


  1. Kernel Interface table
  2. Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
  3. eth0 1500 0 941022 0 0 0 688165 0 0 0 BMRU
  4. lo 16436 0 9304 0 0 0 9304 0 0 0 LRU
  5. ppp0 1496 0 3784 0 0 0 4177 0 0 0 MOPRU

查看每个协议的汇总统计信息,输入:


  1. # netstat -s

输出样例:


  1. Ip:
  2. 1092065 total packets received
  3. 0 forwarded
  4. 0 incoming packets discarded
  5. 1091681 incoming packets delivered
  6. 798913 requests sent out
  7. 895 dropped because of missing route
  8. 759 reassemblies required
  9. 375 packets reassembled ok
  10. Icmp:
  11. 17 ICMP messages received
  12. 0 input ICMP message failed.
  13. ICMP input histogram:
  14. timeout in transit: 8
  15. echo replies: 9
  16. 1747 ICMP messages sent
  17. 0 ICMP messages failed
  18. ICMP output histogram:
  19. destination unreachable: 1730
  20. echo request: 17
  21. IcmpMsg:
  22. InType0: 9
  23. InType11: 8
  24. OutType3: 1730
  25. OutType8: 17
  26. Tcp:
  27. 4822 active connections openings
  28. 1129 passive connection openings
  29. 457 failed connection attempts
  30. 165 connection resets received
  31. 7 connections established
  32. 1062519 segments received
  33. 771394 segments send out
  34. 7158 segments retransmited
  35. 6 bad segments received.
  36. 2578 resets sent
  37. Udp:
  38. 20846 packets received
  39. 1730 packets to unknown port received.
  40. 0 packet receive errors
  41. 19242 packets sent
  42. UdpLite:
  43. TcpExt:
  44. 71 invalid SYN cookies received
  45. 8 resets received for embryonic SYN_RECV sockets
  46. 142 packets pruned from receive queue because of socket buffer overrun
  47. 2109 TCP sockets finished time wait in fast timer
  48. 84 packets rejects in established connections because of timestamp
  49. 19454 delayed acks sent
  50. 6 delayed acks further delayed because of locked socket
  51. Quick ack mode was activated 7306 times
  52. 1 packets directly queued to recvmsg prequeue.
  53. 1 bytes directly received in process context from prequeue
  54. 823921 packet headers predicted
  55. 24412 acknowledgments not containing data payload received
  56. 10150 predicted acknowledgments
  57. 242 times recovered from packet loss by selective acknowledgements
  58. 33 congestion windows recovered without slow start by DSACK
  59. 335 congestion windows recovered without slow start after partial ack
  60. 336 TCP data loss events
  61. TCPLostRetransmit: 35
  62. 1 timeouts after reno fast retransmit
  63. 156 timeouts after SACK recovery
  64. 116 timeouts in loss state
  65. 461 fast retransmits
  66. 5 forward retransmits
  67. 608 retransmits in slow start
  68. 2073 other TCP timeouts
  69. 62 SACK retransmits failed
  70. 43074 packets collapsed in receive queue due to low socket buffer
  71. 8499 DSACKs sent for old packets
  72. 101 DSACKs sent for out of order packets
  73. 308 DSACKs received
  74. 9 DSACKs for out of order packets received
  75. 427 connections reset due to unexpected data
  76. 122 connections reset due to early user close
  77. 28 connections aborted due to timeout
  78. TCPDSACKIgnoredOld: 3
  79. TCPDSACKIgnoredNoUndo: 60
  80. TCPSpuriousRTOs: 4
  81. TCPSackShifted: 282
  82. TCPSackMerged: 740
  83. TCPSackShiftFallback: 1017
  84. IpExt:
  85. InMcastPkts: 47
  86. OutMcastPkts: 51
  87. InBcastPkts: 1
  88. InOctets: 1341508973
  89. OutOctets: 72525352
  90. InMcastOctets: 8649
  91. OutMcastOctets: 7519
  92. InBcastOctets: 328

查看 netstat 命令教程 获取更多信息。

ip / ifconfig 命令 : 配置或者显示网络端口信息

键入以下命令:


  1. # ifconfig

或者


  1. # /sbin/ifconfig

或者


  1. # ifconfig eth0


  1. eth0 Link encap:Ethernet HWaddr b8:ac:6f:65:31:e5
  2. inet addr:192.168.1.5 Bcast:192.168.1.255 Mask:255.255.255.0
  3. inet6 addr: fe80::baac:6fff:fe65:31e5/64 Scope:Link
  4. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  5. RX packets:966334 errors:0 dropped:0 overruns:0 frame:0
  6. TX packets:703297 errors:0 dropped:0 overruns:0 carrier:0
  7. collisions:0 txqueuelen:1000
  8. RX bytes:1186255648 (1.1 GiB) TX bytes:73968238 (70.5 MiB)
  9. Interrupt:17
  10. lo Link encap:Local Loopback
  11. inet addr:127.0.0.1 Mask:255.0.0.0
  12. inet6 addr: ::1/128 Scope:Host
  13. UP LOOPBACK RUNNING MTU:16436 Metric:1
  14. RX packets:9666 errors:0 dropped:0 overruns:0 frame:0
  15. TX packets:9666 errors:0 dropped:0 overruns:0 carrier:0
  16. collisions:0 txqueuelen:0
  17. RX bytes:1399578 (1.3 MiB) TX bytes:1399578 (1.3 MiB)
  18. ppp0 Link encap:Point-to-Point Protocol
  19. inet addr:10.1.11.70 P-t-P:10.0.31.18 Mask:255.255.255.255
  20. UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1496 Metric:1
  21. RX packets:3784 errors:0 dropped:0 overruns:0 frame:0
  22. TX packets:4177 errors:0 dropped:0 overruns:0 carrier:0
  23. collisions:0 txqueuelen:3
  24. RX bytes:2400265 (2.2 MiB) TX bytes:275983 (269.5 KiB)

显示网络端口统计信息,输入:


  1. # ip -s link

输出样例:


  1. 1: lo: mtu 16436 qdisc noqueue state UNKNOWN
  2. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  3. RX: bytes packets errors dropped overrun mcast
  4. 1444187 9960 0 0 0 0
  5. TX: bytes packets errors dropped carrier collsns
  6. 1444187 9960 0 0 0 0
  7. 2: eth0: mtu 1500 qdisc mq state UP qlen 1000
  8. link/ether b8:ac:6f:65:31:e5 brd ff:ff:ff:ff:ff:ff
  9. RX: bytes packets errors dropped overrun mcast
  10. 1221956483 991501 0 0 0 24
  11. TX: bytes packets errors dropped carrier collsns
  12. 75623937 720272 0 0 0 0
  13. 3: wlan0: mtu 1500 qdisc noop state DOWN qlen 1000
  14. link/ether 00:21:6a:ca:9b:10 brd ff:ff:ff:ff:ff:ff
  15. RX: bytes packets errors dropped overrun mcast
  16. 0 0 0 0 0 0
  17. TX: bytes packets errors dropped carrier collsns
  18. 0 0 0 0 0 0
  19. 4: pan0: mtu 1500 qdisc noop state DOWN
  20. link/ether 4a:c7:5f:0e:8e:d8 brd ff:ff:ff:ff:ff:ff
  21. RX: bytes packets errors dropped overrun mcast
  22. 0 0 0 0 0 0
  23. TX: bytes packets errors dropped carrier collsns
  24. 0 0 0 0 0 0
  25. 8: ppp0: mtu 1496 qdisc pfifo_fast state UNKNOWN qlen 3
  26. link/ppp
  27. RX: bytes packets errors dropped overrun mcast
  28. 2419881 3848 0 0 0 0
  29. TX: bytes packets errors dropped carrier collsns
  30. 284151 4287 0 0 0 0

sar 命令: 显示网络统计信息

输入以下命令 (你需要 通过sysstat包安装并启用sar):


  1. sar -n DEV

  1. Linux 2.6.32-220.2.1.el6.x86_64 (www.cyberciti.biz) Tuesday 13 March 2012 _x86_64_ (2 CPU)
  2. 12:00:01 CDT IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
  3. 12:10:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  4. 12:10:01 CDT eth0 127.13 121.32 95.45 18.34 0.00 0.00 0.00
  5. 12:10:01 CDT eth1 98.48 110.62 16.72 96.33 0.00 0.00 0.00
  6. 12:20:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  7. 12:20:01 CDT eth0 139.95 133.41 106.30 19.95 0.00 0.00 0.00
  8. 12:20:01 CDT eth1 110.65 121.85 18.14 107.13 0.00 0.00 0.00
  9. 12:30:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  10. 12:30:01 CDT eth0 147.85 132.49 115.78 20.45 0.00 0.00 0.00
  11. 12:30:01 CDT eth1 111.88 127.39 18.61 117.65 0.00 0.00 0.00
  12. 12:40:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  13. 12:40:01 CDT eth0 136.75 124.64 105.24 19.48 0.00 0.00 0.00
  14. 12:40:01 CDT eth1 101.65 115.32 17.58 104.50 0.00 0.00 0.00
  15. 12:50:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  16. 12:50:01 CDT eth0 131.45 125.69 96.49 19.58 0.00 0.00 0.00
  17. 12:50:01 CDT eth1 101.41 111.31 17.54 96.78 0.00 0.00 0.00
  18. 01:00:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  19. 01:00:01 CDT eth0 140.30 133.27 102.17 20.75 0.00 0.00 0.00
  20. 01:00:01 CDT eth1 106.90 119.51 18.53 103.09 0.00 0.00 0.00
  21. 01:10:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  22. 01:10:01 CDT eth0 152.03 127.74 125.56 19.85 0.00 0.00 0.00
  23. 01:10:01 CDT eth1 115.60 134.57 18.73 126.96 0.00 0.00 0.00
  24. 01:20:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  25. 01:20:01 CDT eth0 138.55 130.55 103.03 20.20 0.00 0.00 0.00
  26. ....
  27. ..
  28. ....
  29. ..
  30. .
  31. 01:00:01 CDT eth1 156.82 169.48 28.83 138.49 0.00 0.00 0.00
  32. 01:10:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  33. 01:10:01 CDT eth0 215.19 194.82 163.11 30.99 0.00 0.00 0.00
  34. 01:10:01 CDT eth1 162.49 183.79 28.36 163.70 0.00 0.00 0.00
  35. 01:20:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  36. 01:20:01 CDT eth0 200.20 192.23 140.64 30.93 0.00 0.00 0.00
  37. 01:20:01 CDT eth1 153.60 166.96 27.32 140.26 0.00 0.00 0.00
  38. 01:30:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  39. 01:30:01 CDT eth0 111.98 103.58 79.12 16.52 0.00 0.00 0.48
  40. 01:30:01 CDT eth1 87.50 95.58 14.74 79.35 0.00 0.00 0.00
  41. Average: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
  42. Average: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  43. Average: eth0 211.21 196.20 156.18 31.20 0.00 0.00 0.01
  44. Average: eth1 159.10 174.52 28.00 149.95 0.00 0.00 0.00

或者输入以下命令:


  1. # sar -n DEV 1 3

输出样例:


  1. Linux 2.6.32-220.2.1.el6.x86_64 (www.cyberciti.biz) Tuesday 13 March 2012 _x86_64_ (2 CPU)
  2. 01:44:03 CDT IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
  3. 01:44:04 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  4. 01:44:04 CDT eth0 161.70 154.26 105.20 26.63 0.00 0.00 0.00
  5. 01:44:04 CDT eth1 145.74 142.55 25.11 144.94 0.00 0.00 0.00
  6. 01:44:04 CDT IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
  7. 01:44:05 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  8. 01:44:05 CDT eth0 162.14 156.31 107.46 42.18 0.00 0.00 0.00
  9. 01:44:05 CDT eth1 135.92 138.83 39.38 104.92 0.00 0.00 0.00
  10. 01:44:05 CDT IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
  11. 01:44:06 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  12. 01:44:06 CDT eth0 303.92 293.14 272.91 37.40 0.00 0.00 0.00
  13. 01:44:06 CDT eth1 252.94 290.20 34.87 263.50 0.00 0.00 0.00
  14. Average: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
  15. Average: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
  16. Average: eth0 210.37 202.34 163.19 35.66 0.00 0.00 0.00
  17. Average: eth1 178.93 191.64 33.36 171.60 0.00 0.00 0.00

原文发布时间为:2015-06-08
本文来自云栖社区合作伙伴“Linux中国”

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
IPerf——网络测试工具介绍与源码解析(5)
本篇随笔讲述一下TCP协议下,双向测试模式和交易测试模式下客户端和服务端执行的情况; 双向测试模式: 官方文档的解释 Run Iperf in dual testing mode. This will cause the server to connect back to the client ...
963 0
比较赞的网络小工具
应用场景 想生成一个二维码,下载CS工具很麻烦,可能还需要安装;想做个漂亮的PPT,没有很多模板;想画脑图等等,一个简单的工具,如果需要使用一时找不到,那怎么办呢?万能的网络提供了一些小工具的在线使用,快来试试吧! 工具示例 1.
666 0
IPerf——网络测试工具介绍与源码解析(2)
对于IPerf源码解析,我是基于2.0.5版本在Windows下执行的情况进行分析的,提倡开始先通过对源码的简单修改使其能够在本地编译器运行起来,这样可以打印输出一些中间信息,对于理解源码的逻辑,程序实现的过程能够起到事半功倍的效果。
954 0
Linux基础命令---mysqladmin数据库管理工具
mysqladmin mysqladmin是mysql数据库的管理工具,可以控制、查看、修改数据库服务器的配置和状态。 此命令的适用范围:RedHat、RHEL、Ubuntu、CentOS、Fedora。
919 0
IPerf——网络测试工具介绍与源码解析(1)
IPerf是一个开源的测试网络宽带并能统计并报告延迟抖动、数据包丢失率信息的控制台命令程序,通过参数选项可以方便地看出,通过设置不同的选项值对网络带宽的影响,对于学习网络编程还是有一定的借鉴意义,至少可以玩上一段时间。
1027 0
IPerf——网络测试工具介绍与源码解析(3)
【线程的生成】   生成线程时需要传入一个thread_Settings类型的变量,thread_Settings包含所有线程运行时需要的信息,命令行选项参数解析后所有得到的属性都存储到该类型的变量中,作为线程生成的传入值能够决定当前线程扮演的角色。
753 0
+关注
boxti
12535
10037
文章
1327
问答
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载