Linux systems use iftop see bandwidth consumption

If the Linux system server bandwidth to run full view with which ip communication bandwidth more, you can query, use the following command by iftop:

1 software installation method [official website address: http://www.ex-parrot.com/~pdw/iftop/ ]

CentOS system running: yum install iftop
Debian system running: apt-get install iftop

During installation steps need to continue our input y, during the installation process will remind us. After installation, you can use iftop command to activate the monitor.

After 2 installed on the server to perform iftop -i eth1 public can view the server network card bandwidth usage (if only performs iftop default detect the first network card usage, this investigation will be the network card eth0.

 

[root@iZ23kick03xZ ~]# iftop -i eth0 -P
  • 1

Note :-P port parameters will be displayed requesting service, that is by connecting to the server which port the established network traffic to see the implementation of iftop -i eth0 -P command.

1.jpg

 

iftop interface have the following meanings

The first line: the display bandwidth of 

the intermediate portion: external connection list, i.e. ip is recorded which network the machine and connecting 

the intermediate right part: access the real-time parameters are connected to the machine ip 2 seconds, 10 seconds, and 40 seconds on average flow rate => represents the transmitted data, <= receiving data representative of 

the bottom three rows: represents transmission, and all traffic received 

the bottom three lines of the second column: you run iftop current flow to 

the bottom of the third column three lines: the peak value of 

the bottom three row fourth column: the average of

It is easy to find which ip interface occupied by iftop of network traffic, this is ifstat not. However, the flow rate of the display units are iftop Mb, b is the bit, the bit is not byte, and the ifstat KB, B is the byte of this, byte is 8-bit times.

 

进入iftop画面后的一些操作命令(注意大小写)

按h切换是否显示帮助;

按n切换显示本机的IP或主机名;

按s切换是否显示本机的host信息;

按d切换是否显示远端目标主机的host信息;

按t切换显示格式为2行/1行/只显示发送流量/只显示接收流量;

按N切换显示端口号或端口服务名称;

按S切换是否显示本机的端口信息;

按D切换是否显示远端目标主机的端口信息;

按p切换是否显示端口信息;

按P切换暂停/继续显示;

按b切换是否显示平均流量图形条;

按B切换计算2秒或10秒或40秒内的平均流量;

按T切换是否显示每个连接的总流量;

按l打开屏幕过滤功能,输入要过滤的字符,比如ip,按回车后,屏幕就只显示这个IP相关的流量信息;

按L切换显示画面上边的刻度;刻度不同,流量图形条会有变化;

按j或按k可以向上或向下滚动屏幕显示的连接记录;

按1或2或3可以根据右侧显示的三列流量数据进行排序;

按<根据左边的本机名或IP排序;

按>根据远端目标主机的主机名或IP排序;

按o切换是否固定只显示当前的连接;

按f可以编辑过滤代码;

按!可以使用shell命令;

按q退出监控。

 

$ sudo apt-get installiftop

阿里云的ECS服务器上,外网网卡默认是eth1,因此执行如下命令:

$ iftop -i eth1(外网网卡)

可以看看是哪些连接长时间占用了带宽,然后去 Apache2 的访问日志中对应看看 IP 地址在访问哪些文件就知道具体情况了。

 

nginx访问日志的默认路径

/var/log/nginx

下面是原文照抄

利用iftop找出是谁占用了带宽

有时候我们的网络缓慢并不是由远程服务器或路由器所引起,而只是因为系统中的某些进程占用了太多可用带宽。虽然从直观角度我们很难确定哪些进程正在使用带宽,但也有一些工具能帮大家把这些捣蛋的家伙揪出来。

top 就是这样一款出色的故障排查工具,它的出现还带来一系列思路相似的衍生品,例如 iotop –能够确定到底是哪些进程占用了大部分磁盘I/O性能。最终名为 iftop 的工具横空出世,能够在网络连接领域提供同等功能。与top不同,iftop不会亲自关注进程情况,而是列出用户服务器与远程IP之间占用带宽最多的连接对象。举例来说,我们可以在iftop中快速查看备份服务器IP地址在输出结果中的位置来判断备份工作有没有大量占用网络带宽。

 

iftop 输出图示

 

 

 

 

红帽与 Debian 的各个发行版都能使用 iftop 这一名称的软件包,但在红帽发行版方面大家可能需要从第三方资源库才能获取。一旦安装过程完成,我们在命令行中运行 iftop 命令即可启用(需要 root 权限)。和 top 命令一样,我们可以点Q键退出。

 

在不添加额外参数的情况下, iftop 命令通常能够满足我们故障排查的全部需求;但有的时候,我们可能也希望利用一些选项实现特殊功能。 iftop 命令在默认情况下会显示查找到的第一个端口的统计信息,但在某些服务器中大家可能会使用多个端口,所以如果我们希望让 iftop 打理第二个以太网端口(即实例中的 eth1 ),那么请输入 iftop – i eth1 。

 

默认情况下, iftop 会试图将所有IP地址通过解析转换为主机名称。这样做的缺点在于一旦远程 DNS 服务器速度缓慢,报告的生成速度也将随之惨不忍睹。另外,所有DNS解析活动都会增加额外的网络流量,而这些都会显示在 iftop 的报告界面当中。因此要禁用网络解析功能,别忘了在 iftop 命令后面加 – n 哦。

 

一般说来, iftop 显示的是主机之间所使用的全局带宽;但为了帮助大家缩小排查范围,我们可能希望每台主机具体使用哪个端口进行通信。毕竟只要找到了主机中占用最大带宽的网络端口,我们就可以在判断是否接入 FTP 端口之外进行其它排查手段。启动 iftop 之后,按P键可以切换端口的显示与隐藏状态。不过大家可能会注意到,有时候显示所有端口状态可能导致我们正在关注的主机被挤出当前显示屏幕。如果出现这种情况,我们还可以按 S 或 D 键来仅显示来自特定源或特定目标的端口。由于服务项目众多,目标主机可能随机使用多个端口并发生带宽占用峰值,这将导致工具无法识别出正在使用的服务,因此仅显示源端口还是相当有用的。不过服务器上的端口也可能与当前设备上的服务相对应。在这种情况下,我们可以使用前面提到的 netstat – lnp 来找出服务所侦听的端口。

 

与大多数 Linux 命令相似, iftop 也拥有多种高级选项。我们在文章中提到的这些已经足以涵盖大多数故障排查需求,但为了满足大家进一步了解 iftop 功能的愿望,我教各位一个小技巧:只要输入 man iftop ,就可以阅读包含在软件包当中的使用手册、获得更多与之相关的知识。

转自:https://blog.csdn.net/qq_34642668/article/details/80974876

Guess you like

Origin www.cnblogs.com/wx170119/p/12069536.html