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个命令窗口做的测试:
图片

目录
相关文章
|
4月前
|
安全 网络协议 算法
Nmap网络扫描工具详细使用教程
Nmap 是一款强大的网络发现与安全审计工具,具备主机发现、端口扫描、服务识别、操作系统检测及脚本扩展等功能。它支持多种扫描技术,如 SYN 扫描、ARP 扫描和全端口扫描,并可通过内置脚本(NSE)进行漏洞检测与服务深度枚举。Nmap 还提供防火墙规避与流量伪装能力,适用于网络管理、渗透测试和安全研究。
728 1
|
4月前
|
安全 Linux 网络安全
Nipper 3.9.0 for Windows & Linux - 网络设备漏洞评估
Nipper 3.9.0 for Windows & Linux - 网络设备漏洞评估
143 0
Nipper 3.9.0 for Windows & Linux - 网络设备漏洞评估
|
5月前
|
Web App开发 API 虚拟化
Cisco Modeling Labs (CML) 2.9.0 - 网络仿真工具
Cisco Modeling Labs (CML) 2.9.0 - 网络仿真工具
407 15
Cisco Modeling Labs (CML) 2.9.0 - 网络仿真工具
|
5月前
|
运维 Linux 开发者
Linux系统中使用Python的ping3库进行网络连通性测试
以上步骤展示了如何利用 Python 的 `ping3` 库来检测网络连通性,并且提供了基本错误处理方法以确保程序能够优雅地处理各种意外情形。通过简洁明快、易读易懂、实操性强等特点使得该方法非常适合开发者或系统管理员快速集成至自动化工具链之内进行日常运维任务之需求满足。
346 18
|
5月前
|
网络协议 关系型数据库 Linux
【App Service Linux】在Linux App Service中安装 tcpdump 并抓取网络包
在App Service for Linux环境中,无法像Windows一样直接使用网络排查工具抓包。本文介绍了如何通过TCPDUMP在Linux环境下抓取网络包,包括SSH进入容器、安装tcpdump、执行抓包命令及下载分析文件的完整操作步骤。
275 5
|
6月前
|
Web App开发 网络协议 Linux
【Linux】网络基础
TCP/IP五层模型是网络通信的基础框架,将复杂的数据传输过程分为物理层、数据链路层、网络层、传输层和应用层,每层各司其职,协同完成远程通信。该模型确保了不同设备和网络之间的互联互通,是现代互联网运行的核心机制。
473 5
|
6月前
|
监控 安全 网络安全
网络安全工具及其使用方法:保护数字安全的第一道防线
在信息时代,网络攻击变得日益复杂且频繁,保护个人和企业数据安全的重要性日益凸显。幸运的是,各种网络安全工具为用户提供了有效的防护手段。从防火墙到密码管理器,这些工具覆盖了威胁检测、攻击防御和数据保护的方方面面。本文将介绍几款常用的网络安全工具,并提供其使用方法,以帮助您构建强大的网络安全防线。
240 1
|
6月前
|
监控 数据可视化 Java
VMware Aria Operations for Networks 6.14 - 网络和应用监控工具
VMware Aria Operations for Networks 6.14 - 网络和应用监控工具
143 0
VMware Aria Operations for Networks 6.14 - 网络和应用监控工具
|
7月前
|
运维 监控 Linux
网络延迟监测工具选择(第一篇)
**WGCLOUD**是一款开源免费的跨平台运维监控工具,支持Windows、Linux、MacOS等系统,具备网络延迟监测功能。其内置的**PING监测**模块可实时ping目标IP,图形化展示延迟趋势,并在目标IP不可达时发送告警通知。支持分组管理,操作简单便捷,适合运维人员高效监控网络状态。
|
6月前
|
网络协议 Linux 开发者
深入Linux中UDP网络通信机制编程探索
以上步骤概述了Linux中UDP网络通信的编程机制。在实现时,因关注细节和上下文环境可能有所调整,但大致流程是一致的。这些知识片段旨在帮助开发者快速上手Linux下的UDP编程,并提供可靠的信息作为编程的基础。在编程实践中,应结合实际业务需求,设计合适的数据传输协议,确保数据的正确性和实时性。
174 0