Linux网络进程监控工具nethogs

 

Linux网络监控工具nethogs

标签: 监控工具linux

2015-12-17 22:06 448人阅读 评论(0) 收藏 举报

 分类:

linux(40) 

版权声明:本文为博主原创文章,未经博主允许不得转载。

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

时间: 2024-09-13 16:41:46

Linux网络进程监控工具nethogs的相关文章

linux 网络流量监控工具iftop

iftop 是类似于top的实时流量监控工具.主要用来显示本机网络流量情况及各相互通信的流量集合,如单独同那台机器间的流量大小,非常适合于代理服务器和iptables服务器使用 iftop可以用来监控网卡的实时流量(可以指定网段).反向解析IP.显示端口信息等,详细的将会在后面的使用参数中说明. iftop工具需要专门的下载和安装在服务器上,其下载链接地址为:http://pkgs.repoforge.org/iftop/ 因为我的是redhat 6.5的环境,所以下载这个包: 安装方法1.编译

一大波你可能不知道的 Linux 网络工具

一大波你可能不知道的 Linux 网络工具 如果要在你的系统上监控网络,那么使用命令行工具是非常实用的,并且对于 Linux 用户来说,有着许许多多现成的工具可以使用,如: nethogs, ntopng, nload, iftop, iptraf, bmon, slurm, tcptrack, cbm, netwatch, collectl, trafshow, cacti, etherape, ipband, jnettop, netspeed 以及 speedometer. 鉴于世上有着许

Linux网络监控工具nethogs

Nethogs 是一个终端下的网络流量监控工具,它的特别之处在于可以显示每个进程的带宽占用情况,这样可以更直观获取网络使用情况.它支持 IPv4 和 IPv6 协议.支持本地网卡及 PPP 链接. 有些时候服务器莫名其妙的向外发送大量的包,占用大量带宽,导致其他服务器受到影响.那么在流量异常的情况下,如何查看每个进程使用的带宽呢?可以使用nethogs工具来查看. 当然还有一些其他宽带分析工具,需要的同学可以多了解了解,有个帖子 http://os.51cto.com/art/201404/43

80 多个 Linux 必备的监控工具

第一章   新春巨献: 80 多个 Linux 系统管理员必备的监控工具  随着互联网行业的不断发展,各种监控工具多得不可胜数.这里列出网上最全的监控工具.让你可以拥有超过80种方式来管理你的机器.在本文中,我们主要包括以下方面: 命令行工具 网络相关内容 系统相关的监控工具 日志监控工具 基础设施监控工具 监控和调试性能问题是一个艰巨的任务,但用对了正确的工具有时也是很容易的.下面是一些你可能听说过的工具,也有可能没有听说过--何不赶快开始试试? 八大系统监控工具 1. top 这是一个被预装

【Linux网络】Linux Socket编程 TCP协议

话虽些许夸张,但是事实也是,现在的网络编程几乎都是用的socket. --有感于实际编程和开源项目研究. 我们深谙信息交流的价值,那网络中进程之间如何通信,如我们每天打开浏览器浏览网页时,浏览器的进程怎么与web服务器通信的?当你用QQ聊天时,QQ进程怎么与服务器或你好友所在的QQ进程通信?这些都得靠socket?那什么是socket?socket的类型有哪些?还有socket的基本函数,这些都是本文想介绍的.本文的主要内容如下: 1.网络中进程之间如何通信? 本地的进程间通信(IPC)有很多种

Linux网络文件系统的数据备份、恢复及同步机制

本文将详细介绍针对该网络文件系统的数据备份.恢复及同步机制在内核的具体实现,给广大系统管理员和研发人员提供技术参考.网络文件系统(NFS)协议是由 Sun MicroSystem 公司在 20 世纪 80 年代为了提供对共享文件的远程访问而设计和实现的,它采用了经典的客户机/服务器模式提供服务.为了达到如同 NFS 协议通过使用 Sun 公司开发的远在本机上使用本地文件系统一样便捷的效果,NFS 通过使用远程过程调用协议(RPC Protocol)来实现运行在一台计算机上的程序来调用在另一台远程

你必须了解的基础的Linux网络命令

摘要:有抱负的 Linux 系统管理员和 Linux 狂热者必须知道的.最重要的.而且基础的 Linux 网络命令合集. 在 It's FOSS 我们并非每天都谈论 Linux 的"命令行方面".基本上,我更专注于 Linux 的桌面端.但你们读者中的一些人在内部调查(仅面向 It's FOSS newsletter 订阅者)中指出,你们也想学些命令行技巧.速查表也受大部分读者所喜欢和支持. 为此,我编辑了一个 Linux 中基础网络命令的列表.它并不是一个教你如何使用这些命令的教程,

你必须了解的基础的 Linux 网络命令

23在 It's FOSS 我们并非每天都谈论 Linux 的"命令行方面".基本上,我更专注于 Linux 的桌面端.但你们读者中的一些人在内部调查(仅面向 It's FOSS newsletter 订阅者)中指出,你们也想学些命令行技巧.速查表也受大部分读者所喜欢和支持. 为此,我编辑了一个 Linux 中基础网络命令的列表.它并不是一个教你如何使用这些命令的教程,而是一个命令合集和他们的简短解释.所以,如果你已经使用过这些命令,你可以用它来快速记住命令. 你可以把这个网页添加为书

Linux网络编程入门

(一)Linux网络编程--网络知识介绍 Linux网络编程--网络知识介绍 客户端和服务端          网络程序和普通的程序有一个最大的区别是网络程序是由两个部分组成的--客户端和服务器端. 客户端         在网络程序中,如果一个程序主动和外面的程序通信,那么我们把这个程序称为客户端程序. 比如我们使用ftp程序从另外一         个地方获取文件的时候,是我们的ftp程序主动同外面进行通信(获取文件), 所以这个地方我们的ftp程序就是客户端程序.  服务端