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. Visual Stdio Code编辑Mark Down

    Visual Studio Code可以一边写Markdown一边预览了,而且不需要任何插件. 方法如下: 新建一个文件,以 .md 为后缀: Visual Studio Code 原生就支持高亮Ma ...

  2. Linux内核设计笔记14——块I/O层

    块I/O层 基本概念 系统中可以随机访问固定大小数据片的硬件设备称做块设备,这些固定大小的数据片称之为块.还有一种基本的设备称之为字符设备,其需要按照顺序访问,比如键盘. 扇区:块设备中最小的寻址单元 ...

  3. 三:QJM HDFS高可用

    本文介绍的是HDFS的一种HA方案.虽然有checkpoint node \backup node等,但是不能实现自动的failover. http://hadoop.apache.org/docs/ ...

  4. jquery中的$(document).ready()、JavaScript中的window.onload()以及body中的onload()、DomContentLoaded()区别

    $().ready().$(handler).$(document).ready(handler)均不是原生JS中的,都是jQuery中封装的方法.这些事件在当页面的dom节点加载完毕后就执行,无需等 ...

  5. Python—列表(一个“打了激素”的数组)

    我们在C语言中会使用数组来将一大堆数据类型一样的数据挨个摆在一起,但是数组有一个基本的要求,就是数据类型必须是一致的,我们知道Python的变量由于没有数据类型,也就是说Python没有数组这一概念, ...

  6. LintCode-381.螺旋矩阵 II

    螺旋矩阵 II 给你一个数n生成一个包含1-n^2的螺旋形矩阵 样例 n = 3 矩阵为 [     [ 1, 2, 3 ],     [ 8, 9, 4 ],     [ 7, 6, 5 ] ] 标 ...

  7. 转 【.NET平台下使用MongoDB入门教程】

    目录 一.了解MongoDB 二.MongoDB特点 三.安装及常用命令 3.1 下载安装 3.2 启动服务器 3.3 常用操作 3.4 其他命令 3.5 做成windows服务 四.批处理程序开启M ...

  8. 修改QQ各版本的默认保存位置(聊天记录)

    这几天没少折腾windows,都有点烦了,我是那种有强迫症的,只要知道的自己没有做到的会感觉到浑身不爽的因为系统重装了好几次,QQ也没少安装几次,我使用的是TM的QQ(没有 那么多烦人的广告,娱乐组件 ...

  9. PHP实现大文件分割上传与分片上传

    转载:http://www.zixuephp.com/phpstudy/phpshilie/20170829_43029.html 服务端为什么不能直接传大文件?跟php.ini里面的几个配置有关 u ...

  10. python2 对URL编码进行编译

    在请求页面时有时会返回类似: %E8%AF%A5985%E5%A4%A7%E5%AD%A6%E5%B8%B8%E5%B9%B4%E4%BD%8D%E5%B1%85%E5%9B%BD%E5%86%85% ...