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. ajax 和 mock 数据

    ajax ajax是一种技术方案,但并不是一种新技术.它依赖的是现有的CSS/HTML/Javascript,而其中最核心的依赖是浏览器提供的XMLHttpRequest对象,是这个对象使得浏览器可以 ...

  2. [leetcode-662-Maximum Width of Binary Tree]

    Given a binary tree, write a function to get the maximum width of the given tree. The width of a tre ...

  3. Python面向对象-访问限制

    在Class内部,可以有字段,方法和属性,而外部代码可以通过直接调用实例变量的方法来操作数据, (1)私有普通字段 比如对于下面的Student类,name字段可以在外面通过对象进行直接访问: cla ...

  4. Python3 数据类型-列表

    序列是Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推. 索引如下图: 列表命名(list): 组成:使用[]括起来,并且 ...

  5. Daily Scrum 9

    今天我们的开会内容有一下部分: Part 1:讨论当前遇到的困难 Part 2:明天的任务分工 ◆Part 1 当前的困难 由于之前我们得到的学长的文件并不完整,导致我们无法打开,在和老师进行积极沟通 ...

  6. HTML页面垂直滚动条不见

    <body style="overflow-y:scroll;"> </body>

  7. 最近面试js部分试题总结

    二,JavaScript面试题总结 1,首先是数组去重算法:给一个数组,去掉重复值 (function() { var arr = [1, 2, 3, 3, 4, ]; function unique ...

  8. FineCMS介绍

      产品简介 FineCMS(简称免费版.企业版.公益版)是一款基于PHP+MySql+CI框架开发的高效简洁的中小型内容管理系统,面向多终端包括Pc端网页和移动端网页,支持自定义内容模型和会员模型, ...

  9. 爬虫之手机APP抓包教程-亲测HTTP和HTTPS均可实现

    当下很多网站都有做自己的APP端产品,一个优秀的爬虫工程师,必须能够绕过难爬取点而取捷径,这是皆大欢喜的.但是在网上收罗和查阅了无数文档和资料,本人亲测无数次,均不能正常获取HTTPS数据,究其原因是 ...

  10. c++:error2019,无法解析的外部命令blabla~

    出现这个原因的问题汇总: 1,相应的附加库没有包含进去,注意附加库的目录是 / 2,函数没有与之对应的类,却在main中以某一类的对象调用了该方法. 其实,当错误中显示fun()成为无法解析的外部命令 ...