温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Linux下如何按进程实时统计网络带宽利用率

发布时间:2021-10-27 11:03:26 来源:亿速云 阅读:459 作者:小新 栏目:系统运维

这篇文章主要为大家展示了“Linux下如何按进程实时统计网络带宽利用率”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Linux下如何按进程实时统计网络带宽利用率”这篇文章吧。

NetHogs – 网络带宽监控

什么是NetHogs?

NetHogs 是一个开源的命令行工具(类似于Linux的top命令),用来按进程或程序实时统计网络带宽使用率。

来自NetHogs项目网站:

NetHogs是一个小型的’net top’工具,不像大多数工具那样拖慢每个协议或者是每个子网的速度而是按照进程进行带宽分组.NetHogs NetHogs不需要依赖载入某个特殊的内核模块. 如果发生了网络阻塞你可以启动NetHogs立即看到哪个PID造成的这种状况.这样就很容易找出哪个程序跑飞了然后突然占用你的带宽.

这篇文章为你讲解了如何在Unix/Linux操作系统下如何安装和使用NetHogs按进程监控网络带宽使用率。

在RHEL,CentOS和Fedora下安装NetHogs:

要安装NetHogs,你必须要启用你所用Linux下的EPEL源.然后运行下面的yum命令下载安装NetHogs包。

# yum install nethogs

样例输出:

[root@tecmint~]# yum -y install nethogs Loaded plugins:fastest mirror,refresh-packagekit Loading mirror speeds from cached hostfile *base: mirrors.hns.net.in *epel: mirror.nus.edu.sg *extras: mirrors.hns.net.in *rpmfusion-free-updates: mirrors.ustc.edu.cn *rpmfusion-nonfree-updates: mirror.de.leaseweb.net *updates: mirrors.hns.net.in Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package nethogs.i6860:0.8.0-1.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved =========================================================================================================== Package                Arch                Version                    Repository                    Size =========================================================================================================== Installing: nethogs                i686                0.8.0-1.el6                epel                        28k   Transaction Summary =========================================================================================================== Install       1 Package(s) Total download size:28k Installed size:50k Downloading Packages: nethogs-0.8.0-1.el6.i686.rpm                                                        |  28kB     00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction   Installing :nethogs-0.8.0-1.el6.i686                                                          1/1   Verifying  :nethogs-0.8.0-1.el6.i686                                                          1/1 Installed:   nethogs.i6860:0.8.0-1.el6 Complete!

在Ubuntu, Linux mint和Debian下安装NetHogs:

键入apt-get命令安装NetHogs包:

$ sudo apt-get install nethogs

样例输出

tecmint@tecmint:~$ sudo apt-get install nethogs [sudo]password fortecmint: Reading package lists...Done Building dependency tree Reading state information...Done The following NEW packages will be installed:   nethogs 0 upgraded,1 newly installed,0 to remove and 318 not upgraded. Need to get 27.1kB of archives. After this operation,100kB of additional disk space will be used. Get: 1 http://in.archive.ubuntu.com/ubuntu/ quantal/universe nethogs i386 0.8.0-1 [27.1 kB] Fetched 27.1kB in 1s (19.8kB/s)  Selecting previously unselected package nethogs. (Reading database... 216058 files and directories currently installed.) Unpacking nethogs(from .../nethogs_0.8.0-1_i386.deb)... Processing triggers forman-db... Setting up nethogs(0.8.0-1)...

NetHogs用法

在基于RedHat系统下键入如下命令启动NetHogs工具。

# nethogs

要执行NetHogs你必须拥有root权限,即如图所示用sudo命令:

$ sudo nethogs

样例预览:

Linux下如何按进程实时统计网络带宽利用率

CentOS 6.3 下的NetHogs预览

Linux下如何按进程实时统计网络带宽利用率

Ubuntu 12.10 下的NetHogs预览

正如上图所示,send列和received列显示的是按照每个进程的流量统计。总的收发数据带宽在最下方,而且可以用交互命令控制排序,下面将要讨论这些交互命令。

NetHogs 命令行参数

以下就是NetHogs命令行的参数,用’-d’来添加刷新频率参数,`device name` 用来检测给定的某个或者某些设备的带宽(默认是eth0).例如:设置5秒钟的刷新频率,键入如下命令即可:

# nethogs -d 5

$ sudo nethogs -d 5

如果只用来监视设备(eth0)的网络带宽可以使用如下命令:

# nethogs eth0

 或

$ sudo nethogs eth0

如果要同时监视eth0和eth2接口,使用以下命令即可:

# nethogs eth0 eth2

$ sudo nethogs eth0 eth2

其他参数和用法:

-d: delay for refresh rate. -h: display available commands usage. -p: sniff in promiscious mode (not recommended). -t: trace mode. -V: prints Version info.

NetHogs 交互控制

以下是NetHogs的一些很有用的交互控制(键盘快捷键:

-m: Change the units displayed forthe bandwidth inunits like KB/sec->KB->B->MB. -r: Sort by magnitude of respectively traffic. -s: Sort by magnitude of sent traffic. -q: Hit quit tothe shell prompt.

以上是“Linux下如何按进程实时统计网络带宽利用率”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI