Linux网络监控工具nethogs

简介:

Nethogs 是一个终端下的网络流量监控工具,它的特别之处在于可以显示每个进程的带宽占用情况,这样可以更直观获取网络使用情况。它支持 IPv4 和 IPv6 协议、支持本地网卡及 PPP 链接。

有些时候服务器莫名其妙的向外发送大量的包,占用大量带宽,导致其他服务器受到影响。那么在流量异常的情况下,如何查看每个进程使用的带宽呢?可以使用nethogs工具来查看。

当然还有一些其他宽带分析工具,需要的同学可以多了解了解,有个帖子 http://os.51cto.com/art/201404/435279.htm 做了介绍。按应用分析还是比较常见,所以我一般使用nethogs,关于nethogs的安装下面做下说明:

1、下载
地址: http://sourceforge.net/projects/nethogs/files/nethogs/
下载安装包:nethogs-0.8.0.tar.gz (38.0 kB)

2、安装

yum install ncurses*
tar -zxvf nethogs-0.8.0.tar.gz
cd nethogs
make && make install

如果报错如下:

[root@localhost nethogs]# make && make install
g++ -g -Wall -Wextra -c packet.cpp
g++ -g -Wall -Wextra -c connection.cpp
g++ -g -Wall -Wextra -c process.cpp
g++ -g -Wall -Wextra -c refresh.cpp
refresh.cpp:9: warning: unused parameter ‘i’
cc -g -Wall -Wextra -c decpcap.c
decpcap.c:7:18: error: pcap.h: No such file or directory
In file included from decpcap.c:8:
decpcap.h:34: error: expected specifier-qualifier-list before ‘pcap_t’
decpcap.c:14: error: expected ‘)’ before ‘*’ token
decpcap.c: In function ‘dp_open_offline’:
decpcap.c:48: error: ‘pcap_t’ undeclared (first use in this function)
decpcap.c:48: error: (Each undeclared identifier is reported only once
decpcap.c:48: error: for each function it appears in.)
decpcap.c:48: error: ‘temp’ undeclared (first use in this function)
decpcap.c:48: warning: implicit declaration of function ‘pcap_open_offline’
decpcap.c:55: warning: implicit declaration of function ‘dp_fillhandle’
decpcap.c: In function ‘dp_open_live’:
decpcap.c:60: error: ‘pcap_t’ undeclared (first use in this function)
decpcap.c:60: error: ‘temp’ undeclared (first use in this function)
decpcap.c:60: warning: implicit declaration of function ‘pcap_open_live’
decpcap.c: In function ‘dp_addcb’:
decpcap.c:74: error: ‘struct dp_handle’ has no member named ‘callback’
decpcap.c: In function ‘dp_parse_tcp’:
decpcap.c:84: error: ‘struct dp_handle’ has no member named ‘callback’
decpcap.c:86: error: ‘struct dp_handle’ has no member named ‘callback’
decpcap.c:87: error: ‘struct dp_handle’ has no member named ‘userdata’
decpcap.c: In function ‘dp_parse_ip’:
decpcap.c:99: error: dereferencing pointer to incomplete type
decpcap.c:103: error: ‘struct dp_handle’ has no member named ‘callback’
decpcap.c:105: error: ‘struct dp_handle’ has no member named ‘callback’
decpcap.c:106: error: ‘struct dp_handle’ has no member named ‘userdata’
decpcap.c: In function ‘dp_parse_ip6’:
decpcap.c:126: error: ‘struct dp_handle’ has no member named ‘callback’
decpcap.c:128: error: ‘struct dp_handle’ has no member named ‘callback’
decpcap.c:129: error: ‘struct dp_handle’ has no member named ‘userdata’
decpcap.c: In function ‘dp_parse_ethernet’:
decpcap.c:150: error: ‘struct dp_handle’ has no member named ‘callback’
decpcap.c:152: error: ‘struct dp_handle’ has no member named ‘callback’
decpcap.c:153: error: ‘struct dp_handle’ has no member named ‘userdata’
decpcap.c: In function ‘dp_parse_ppp’:
decpcap.c:196: error: ‘struct dp_handle’ has no member named ‘callback’
decpcap.c:198: error: ‘struct dp_handle’ has no member named ‘callback’
decpcap.c:199: error: ‘struct dp_handle’ has no member named ‘userdata’
decpcap.c: In function ‘dp_parse_linux_cooked’:
decpcap.c:238: error: ‘struct dp_handle’ has no member named ‘callback’
decpcap.c:240: error: ‘struct dp_handle’ has no member named ‘callback’
decpcap.c:241: error: ‘struct dp_handle’ has no member named ‘userdata’
decpcap.c: In function ‘dp_pcap_callback’:
decpcap.c:270: error: ‘struct dp_handle’ has no member named ‘userdata_size’
decpcap.c:271: error: ‘struct dp_handle’ has no member named ‘userdata’
decpcap.c:271: error: ‘struct dp_handle’ has no member named ‘userdata_size’
decpcap.c:273: error: ‘struct dp_handle’ has no member named ‘linktype’
decpcap.c:274: error: ‘DLT_EN10MB’ undeclared (first use in this function)
decpcap.c:277: error: ‘DLT_PPP’ undeclared (first use in this function)
decpcap.c:280: error: ‘DLT_LINUX_SLL’ undeclared (first use in this function)
decpcap.c:283: error: ‘DLT_RAW’ undeclared (first use in this function)
decpcap.c:284: error: ‘DLT_NULL’ undeclared (first use in this function)
decpcap.c:289: error: ‘struct dp_handle’ has no member named ‘linktype’
decpcap.c: In function ‘dp_dispatch’:
decpcap.c:296: error: ‘struct dp_handle’ has no member named ‘userdata’
decpcap.c:297: error: ‘struct dp_handle’ has no member named ‘userdata_size’
decpcap.c:298: warning: implicit declaration of function ‘pcap_dispatch’
decpcap.c:298: error: ‘struct dp_handle’ has no member named ‘pcap_handle’
decpcap.c: In function ‘dp_setnonblock’:
decpcap.c:302: warning: implicit declaration of function ‘pcap_setnonblock’
decpcap.c:302: error: ‘struct dp_handle’ has no member named ‘pcap_handle’
decpcap.c: In function ‘dp_geterr’:
decpcap.c:307: warning: implicit declaration of function ‘pcap_geterr’
decpcap.c:307: error: ‘struct dp_handle’ has no member named ‘pcap_handle’
make: * [decpcap.o] Error 1

执行命令

yum install libpcap-dev* libncurses5-dev*

然后再重新编译安装,如下:

[root@localhost nethogs]# make && make install
cc -g -Wall -Wextra -c decpcap.c
decpcap.c: In function ‘dp_open_live’:
decpcap.c:60: warning: passing argument 5 of ‘pcap_open_live’ discards qualifiers from pointer
/usr/include/pcap/pcap.h:349: note: expected ‘char ’ but argument is of type ‘const char
g++ -g -Wall -Wextra -c cui.cpp -DVERSION=\”0\” -DSUBVERSION=\”8\” -DMINORVERSION=\”0\”
g++ -g -Wall -Wextra -c inode2prog.cpp
g++ -g -Wall -Wextra -c conninode.cpp
g++ -c -o devices.o devices.cpp
g++ -g -Wall -Wextra nethogs.cpp packet.o connection.o process.o refresh.o decpcap.o cui.o inodee.o devices.o -o nethogs -lpcap -lm -lncurses -DVERSION=\”0\” -DSUBVERSION=\”8\” -DMINORVERSION=
g++ -g -Wall -Wextra decpcap_test.cpp decpcap.o -o decpcap_test -lpcap -lm
install -d -m 755 /usr/local/sbin
install -m 755 nethogs /usr/local/sbin
install -d -m 755 /usr/local/share/man/man8/
install -m 644 nethogs.8 /usr/local/share/man/man8/

这样已经算是成功安装完成,输入命令 nethogs 即可查看应用的宽带占用情况。
下图是我开启了2个命令窗口做的测试:
图片

目录
相关文章
|
8天前
|
域名解析 网络协议 安全
|
14天前
|
运维 监控 网络协议
|
17天前
|
监控 Java Linux
Linux系统之安装Ward服务器监控工具
【10月更文挑战第17天】Linux系统之安装Ward服务器监控工具
39 5
Linux系统之安装Ward服务器监控工具
|
20天前
|
JSON JavaScript Linux
Linux系统之安装cook菜谱工具
【10月更文挑战第15天】Linux系统之安装cook菜谱工具
33 2
Linux系统之安装cook菜谱工具
|
8天前
|
缓存 监控 Linux
Linux性能分析利器:全面掌握perf工具
【10月更文挑战第18天】 在Linux系统中,性能分析是确保软件运行效率的关键步骤。`perf`工具,作为Linux内核自带的性能分析工具,为开发者提供了强大的性能监控和分析能力。本文将全面介绍`perf`工具的使用,帮助你成为性能优化的高手。
42 1
|
8天前
|
缓存 监控 Linux
掌握Linux性能分析:深入探索perf工具
【10月更文挑战第26天】
14 1
|
9天前
|
存储 Ubuntu Linux
2024全网最全面及最新且最为详细的网络安全技巧 (三) 之 linux提权各类技巧 上集
在本节实验中,我们学习了 Linux 系统登录认证的过程,文件的意义,并通过做实验的方式对 Linux 系统 passwd 文件提权方法有了深入的理解。祝你在接下来的技巧课程中学习愉快,学有所获~和文件是 Linux 系统登录认证的关键文件,如果系统运维人员对shadow或shadow文件的内容或权限配置有误,则可以被利用来进行系统提权。上一章中,我们已经学习了文件的提权方法, 在本章节中,我们将学习如何利用来完成系统提权。在本节实验中,我们学习了。
|
15天前
|
网络协议 安全 Linux
网络工具ping的使用方式
【10月更文挑战第19天】网络工具ping的使用方式
40 6
|
17天前
|
Ubuntu Linux 虚拟化
Linux虚拟机网络配置
【10月更文挑战第25天】在 Linux 虚拟机中,网络配置是实现虚拟机与外部网络通信的关键步骤。本文介绍了四种常见的网络配置方式:桥接模式、NAT 模式、仅主机模式和自定义网络模式,每种模式都详细说明了其原理和配置步骤。通过这些配置,用户可以根据实际需求选择合适的网络模式,确保虚拟机能够顺利地进行网络通信。
|
30天前
|
网络协议 安全 Ubuntu
Linux中网络连接问题
【10月更文挑战第3天】
28 1

热门文章

最新文章