网络状态监控、及性能测试
在进行生产环境网络状态检测、测试网络质量、网络传输能力极限的时候就经常会用到下面的 Linux 工具,每一种工具都有其侧重点,我们可以根据具体的关注点来有选择性的使用这些工具。
一、nethogs(进程级别)
NetHogs is a simple open-source utility that runs in the terminal. Instead of breaking the traffic down per protocol or per subnet, it groups bandwith by process. It is very helpful for finding the PID of a hanging program or just for seeing what is eating your bandwidth. It relies mostly on /proc, so most features are Linux-only.
NetHogs 是一个在终端中运行的简单开源实用程序。它不是按协议或每个子网分解流量,而是按进程对 bandwith 进行分组。这对于查找挂起程序的 PID 或仅查看正在消耗带宽的内容非常有帮助。它主要依赖于/proc,因此大多数功能仅适用于Linux。
To run it, simply use:
要运行它,只需使用:
sudo nethogs
Conveniently, you can specify devices after the command (such as sudo nethogs eth0). You also have additional parameters, such as choosing a delay for the refresh rate (-d), version info (-V), tracemode (-t) and a few others which you can check out in the man pages (man nethogs).
您可以方便地在命令指定设备 (例如: sudo nethogs eth0)。您还有其他参数,例如为刷新率 (-d) 、版本信息 (-V) 、tracemode (-t) 选择延迟还有一些您可以在手册页 (man nethogs) 中查看的其他内容。
二、nload(网卡级别)
nload is an open-source console application that allows you to monitor network traffic and bandwidth usage in real time. It visualizes incoming and outgoing traffic using graphs, while also providing additional information (total amount of transferred data, min/max network usage etc.). It’s a simple to use tool that can be really helpful at times.
nload 是一个开源控制台应用程序,可让您实时监控网络流量和带宽使用情况。它使用图表可视化传入和传出流量,同时还提供附加信息 (传输数据总量、最小/最大网络使用量等)。这是一个简单易用的工具,有时会非常有用。
三、cmb(网卡级别)
CBM(Color Bandwidth Meter) is a very simple tool that displays (in color) network traffic on all connected devices, in a very stripped-down manner.
CBM是一个非常简单的工具,以非常精简的方式在所有连接的设备上显示 (彩色) 网络流量。
Using CBM is just as easy as installing it. You run:
使用 CBM 和安装 CBM 一样简单。你运行:
cbm
The commands are displayed in the bottom of your terminal so that you can control them easily.
这些命令显示在终端的底部,以便您可以轻松控制它们。
四、iftop(主机级别)
iftop is a free open-source software command-line system monitor tool that produces a frequently updated list of network connections between pairs of hosts. The connections can be ordered by different parameters, but they ordered by default by bandwidth usage, with only the “top” bandwidth consumers shown.
iftop 是一个免费的开源软件命令行系统监控工具,可生成主机对之间网络连接的频繁更新列表。连接可以按不同的参数排序,但默认情况下,它们按带宽使用量排序,仅显示 “top” 带宽消费者。
五、iPerf(性能测试)
iPerf is tool used for network performance measurement and tuning and can produce standardized performance measurements for any network. It has client and server functionality, and can create data streams to measure bandwidth, loss and other parameters between the two ends in one or both directions. There are two implementations: the original iPerf (iPerf2) and a non-backwards compatible implementation iPerf3.
iPerf 是用于网络性能测量和调整的工具,可以为任何网络产生标准化的性能测量。它具有客户端和服务器功能,并且可以创建数据流来测量两端在一个方向或两个方向上的带宽、损耗和其他参数。有两种实现方式: 原始 iPerf (iPerf2) 和非向后兼容实现 iperf3。
Note: For all further examples, if you are using iPerf3 simply replace all instances of iperf with iperf3.
注意: 对于所有其他示例,如果您使用的是 iPerf3,只需将 iperf 的所有实例替换为iPerf3。
_
However, doing so will only display your options. To run iPerf, you need a minimum of 2 machines: one to act as a client and one to act as a server. For the server, you’ll use:
但是,这样做只会显示您的选项。要运行 iPerf,您至少需要两台机器: 一台充当客户端,一台充当服务器。对于服务器,您将使用:
iperf -s
This will open the machine for listening on port 5001. To connect to another machine and run a test, you’ll use:
这将打开监听端口 5001 的机器。要连接到另一台计算机并运行测试,您将使用:
iperf -c server_address
Where server_address is, of course, the address of the server you are trying to connect to. This can be either an IP address, or something like ping.online.net. The iPerf3 team has a list of servers to use for testing purposes.
其中 server_address 当然是您尝试连接的服务器的地址。这可以是一个 ip 地址,也可以是 ping.online.net 之类的地址。IPerf3 团队有一个用于测试目的的 服务器列表。
iPerf is a widely used tool that has a lot of specific uses and many options. I won’t go into those, since it is beyond the scope of this article. However, you can check out the manpage (man iperf / man iperf3) or the documentation.
IPerf 是一种广泛使用的工具,具有许多特定用途和许多选项。我不再赘述,因为这超出了本文的范围。但是,您可以查看手册页 (man iperf / man iperf3) 或文档。