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

Linux网络监控工具nethogs的更多相关文章

  1. 网络管理监视很重要!学编程的你知道哪些不错的网络监控工具?2020 最好的Linux网络监控工具分享给你

    以下文章来源于新钛云服 翻译:侯明明 前言 虽然这个清单包含开源的和闭源的产品,但它着重于介绍基于 Linux 的网络监控工具, 少数常用工具只能在 Windows,Pandora 或其他系统上运行, ...

  2. Linux 网络监控工具 ss

    ss命令用来显示处于活动状态的套接字信息.功能和netstat类似,但比netstat更快更高效. ss -h Usage: ss [ OPTIONS ] ss [ OPTIONS ] [ FILTE ...

  3. 你可能不知道的 Linux 命令行网络监控工具

    http://developer.51cto.com/art/201505/476651_2.htm 对任何规模的业务来说,网络监控工具都 是一个重要的功能.网络监控的目标可能千差万别.比如,监控活动 ...

  4. 【转】又一波你可能不知道的 Linux 命令行网络监控工具

      对任何规模的业务来说,网络监控工具都是一个重要的功能.网络监控的目标可能千差万别.比如,监控活动的目标可以是保证长期的网络服务.安全保护.对性能进行排查.网络使用统计等.由于它的目标不同,网络监控 ...

  5. linux网络流量实时监控工具之iptraf

    这个工具还是很强大 linux网络流量实时监控工具之iptraf [我的Linux,让Linux更易用]IPTraf是一个网络监控工具,功能比nload更强大,可以监控所有的流量,IP流量,按协议分的 ...

  6. Linux 上网络监控工具 ntopng 的安装

    当今世界,人们的计算机都相互连接,互联互通.小到你的家庭局域网(LAN),大到最大的一个被我们称为互联网.当你管理一台联网的计算机时,你就是在管理最关键的组件之一.由于大多数开发出的应用程序都基于网络 ...

  7. Linux 网络流量实时监控工具之ntopng详解

    大纲一.前言二.ntopng 简介三.ntopng 功能说明 四.ntopng 安装详解五.ntopng 配置详解 六.ntopng 使用详解注,操作系统 CentOS 5.5 X86_64,软件版本 ...

  8. linux网络流量实时监控工具之iptraf 【个人比较喜欢用的流量监控软件】

    linux网络流量实时监控工具之iptraf IPTraf是一个网络监控工具,功能比nload更强大,可以监控所有的流量,IP流量,按协议分的流量,还可以设置过滤器等,如下图 对监控网络来说,这个更适 ...

  9. 4个强大的Linux服务器监控工具[转]

    本文介绍了一些可以用来监控网络使用情况的Linux命令行工具.这些工具可以监控通过网络接口传输的数据,并测量目前哪些数据所传输的速度.入站流量和出站流量分开来显示. 一些命令可以显示单个进程所使用的带 ...

随机推荐

  1. LCD1602指令集解读

    LCD1602指令集(11个)     1.清屏指令(clear display)   RS=0 ,R/w=0, 01H 功能:清除液晶显示器,即将DDRAM中的内容全部填入20H(空白字符)     ...

  2. Eclipse 安装SVN、Maven插件

    1先安装subeclipse插件就是svn svn - http://subclipse.tigris.org/update_1.6.x 我这里是灰色的说明我安装过了这里只是截图说明下,我就不继续安装 ...

  3. return语句的用法

    1.return语句的作用:a.返回一个值,这个值可以是任意类型.b.使程序返回到操作系统(即终止程序)2.java中对于一个函数,不论有没有返回值类型,都可以带有return 语句.但是区别在于,r ...

  4. iOS- 优化与封装 APP音效的播放

    1.关于音效 音效又称短音频,是一个声音文件,在应用程序中起到点缀效果,用于提升应用程序的整体用户体验.   我们手机里常见的APP几乎都少不了音效的点缀.   显示实现音效并不复杂,但对我们App很 ...

  5. 【OSG】运行OSG示例出现的奶牛不完整问题

    发现一个很奇怪的问题:我用笔记本运行OSG里面的示例,出现的图案总是不完整显示的,以经典的奶牛图案为例,如图. 图一是我电脑上的情况,正常情况应该是图二.不知道这是什么原因,难道是我电脑显卡的原因吗? ...

  6. UVA 167 R-The Sultan's Successors

    https://vjudge.net/contest/68264#problem/R The Sultan of Nubia has no children, so she has decided t ...

  7. Redis 学习之主从复制

    该文使用centos6.5 64位    redis3.2.8 主从复制 Redis的复制功能是支持多个数据库之间的数据同步.一类是主数据库(master)一类是从数据库(slave),主数据库可以进 ...

  8. RT-thread 设备驱动组件之PIN设备

    在RT-thread 2.0.0正式版中引入了pin设备作为杂类设备,其设备驱动文件pin.c在rt-thread-2.0.1\components\drivers\misc中,主要用于操作芯片GPI ...

  9. hdu 1150 Machine Schedule (二分匹配)

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  10. [JSOI2007]重要的城市 floyd:最短路计数

    ---题面--- 题解: 其实感觉还是比较妙的,第一眼看题想到floyd统计最短路条数, 注意到对于任意两点x,y而言,floyd将会枚举其最短路所可能经过的所有中转点, 因此我们可以直接分别统计对于 ...