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. Python3中@的作用

    可能是自己理解能力差,网上看了一大堆教程,完全没搞懂. 自己敲几行代码,终于理解是怎么回事了. #python 3.6 #!/usr/bin/env python # -*- coding:utf-8 ...

  2. scatter注记词

    say illness thumb ginger brass atom twenty omit fine thought staff poverty

  3. Kali信息收集-DNS

    1.whois查询 直接在终端输入whois 域名 2.查找dns服务器 (1)host (2)dig (3)nslookup 3.域传输 4.域名枚举 (1)dnsdict6 kali没有集成这款工 ...

  4. js如何处理字符串中带有↵字符

    js或vue中如何处理字符串中带有↵字符 split('\n') 使用split('\n')将字符串分割成数组就行 如果我们在vue中,只需要在页面中绑定变量时操作split('\n')就可以了: & ...

  5. “Hello World!”团队第三周召开的第五次会议

    一.会议时间 二.会议地点 三.会议成员 四.会议内容 五.todo list 六.会议照片 七.燃尽图 八.代码地址 一.会议时间 2017年10月31日  11:45-12:17 二.会议地点: ...

  6. Python学习之路4 - 文件操作&编码转换

    文件操作 文件操作大概分三步: 把文件打开. 操作文件. 把文件关上. 打开文件 打开文件用open()函数,打开成功后返回一个资源,具体语法如下. open(要打开的文件,打开方式,打开文件的格式, ...

  7. Notes of the scrum meeting(12.11)

    meeting time:19:30~20:30p.m.,December 11th,2013 meeting place:3号公寓一层 attendees: 顾育豪                  ...

  8. XDA-University: Getting Started

    XDA-University: Getting Started A while back, we introduced XDA-University to the world, an ongoing ...

  9. servlet映射路径

    1 访问映射过程 问题:访问URL:http://localhost:8080/day10/first  ,服务器如何相应的? 前提: tomcat服务器启动时,首先加载webapps中的每个web应 ...

  10. HDU2376Average distance(树形dp|树上任意两点距离和的平均值)

    思路: 引:如果暴力枚举两点再求距离是显然会超时的.转换一下思路,我们可以对每条边,求所有可能的路径经过此边的次数:设这条边两端的点数分别为A和B,那 么这条边被经过的次数就是A*B,它对总的距离和的 ...