centos8平台使用nethogs基于进程监控网络流量

一,nethogs的作用:

     按进程或程序实时统计网络带宽使用率

     我们查看流量的占用时,知道来源的ip、访问的端口,还不足以帮我们确认到进程,

     而nethogs则可以让我们查看每个进程所占用的流量带宽

 

说明:刘宏缔的架构森林是一个专注架构的博客,

网站:https://blog.imgtouch.com
本文: https://blog.imgtouch.com/index.php/2023/05/21/centos8linux-yong-nethogs-ji-yu-jin-cheng-jian-kong-wang-luo-liu-liang/

         对应的源码可以访问这里获取: https://github.com/liuhongdi/

 说明:作者:刘宏缔 邮箱: 371125307@qq.com

 

二,安装nethogs:

[root@yjweb ~]# yum install nethogs 

 

说明:如果yum报错没有任何匹配,则先安装epel源

[root@localhost liuhongdi]# yum install epel-release

 

三,查看nethogs的版本

[root@yjweb ~]# nethogs -V
 version 0.8.5

 

四,查看帮助

[root@yjweb ~]# nethogs -help
usage: nethogs [-V] [-h] [-b] [-d seconds] [-v mode] [-c count] [-t] [-p] [-s] [device [device [device ...]]]
                -V : prints version.
                -h : prints this help.
                -b : bughunt mode - implies tracemode.
                -d : delay for update refresh rate in seconds. default is 1.
                -v : view mode (0 = KB/s, 1 = total KB, 2 = total B, 3 = total MB). default is 0.
                -c : number of updates. default is 0 (unlimited).
                -t : tracemode.
                -p : sniff in promiscious mode (not recommended).
                -s : sort output by sent column.
                -a : monitor all devices, even loopback/stopped ones.
                device : device(s) to monitor. default is all interfaces up and running excluding loopback

When nethogs is running, press:
 q: quit
 s: sort by SENT traffic
 r: sort by RECEIVE traffic
 m: switch between total (KB, B, MB) and KB/s mode

 

五,nethogs 的常用命令

1,每隔5秒刷新一次输出结果

[root@yjweb ~]# nethogs -d 5

 

说明:默认间隔是1秒

 

2,按发送的数据量倒排

[root@yjweb ~]# nethogs -s

 

说明:默认是按RECEIVE的数据量倒排

3,监控所有的网卡

[root@yjweb ~]# nethogs -a

 

4,监控指定的一个或多个网卡

[root@yjweb ~]# nethogs eth0 eth1

 

5,监测指定的次数

[root@yjweb ~]# nethogs eth0 -c 3

 

说明:次数更新完即退出

 

六,nethogs的交互指令

m : Cycle between display modes (kb/s, kb, b, mb) 切换网速显示单位
r : Sort by received. 按接收流量排序
s : Sort by sent. 按发送流量排序
q : Quit and return to the shell prompt. 退出NetHogs命令工具

 

七,查看当前的centos版本

[root@yjweb ~]# cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)

 

posted @ 2020-03-21 10:35  刘宏缔的架构森林  阅读(881)  评论(0编辑  收藏  举报