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. [2018 ACL Short and System] 对话系统

    Short Paper(s) 1.  Task-oriented Dialogue System for Automatic Diagnosis. (Cited by 0) Zhongyu Wei, ...

  2. HDU 1007 Quoit Design(计算几何の最近点对)

    Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...

  3. 关于set和get机制的整理

    首先这是es5新增的:定义是设置和获取对象属性时候出发的方法,属于修饰器: 犀牛书例子: function test(n){ return { get count(){ return n }, set ...

  4. [git]基本用法1

    一.实验说明 本节实验为 Git 入门第一个实验,可以帮助大家熟悉如何创建和使用 git 仓库. 二.git的初始化 在使用git进行代码管理之前,我们首先要对git进行初始化. 1.Git 配置 使 ...

  5. iOS-UILabel加线

    NSAttributedString *attrStr =[[NSAttributedString alloc]initWithString:[NSString stringWithFormat:], ...

  6. hadoop下安装mysql

    http://www.cnblogs.com/zhuyp1015/p/3561470.html       第一步:先把这个文件放入到linux环境下桌面. 接着编写脚本:sudo apt-get u ...

  7. mysql通过binlog恢复数据

    如果mysql不小心操作失误导致数据错误或者丢失这时候binlog起到了很大的作用 恢复有几种方式 1.按时间恢复--start-datetime   如果确定了时间点,那么按时间恢复是一个再好不过的 ...

  8. 【Asp.Net Core】ASP.NET Core 2.0 + EF6 + Linux +MySql混搭

    好消息!特好消息!同时使用ASP.NET Core 2.0和.NET Framework类库还能运行在linux上的方法来啦! 是的,你没有看错!ASP.NET Core 2.0,.NET Frame ...

  9. BZOJ 1076 奖励关(状压期望DP)

    当前得分期望=(上一轮得分期望+这一轮得分)/m dp[i,j]:第i轮拿的物品方案为j的最优得分期望 如果我们正着去做,会出现从不合法状态(比如前i个根本无法达到j这种方案),所以从后向前推 如果当 ...

  10. C# 代码操作XML(增、删、改)

    目录:  1.创建XML 1)创建普通XML 2)创建带属性的XML 2.追加XML 3.读取XML 1)读取普通XML 2)读取带属性的XML 4.修改属性的值 5.删除XML节点 作为一个小型的数 ...