分类: CentOS2014-10-27 13:54 5789人阅读 评论(3) 收藏 举报
 

目录(?)[+]

 

Nethogs 是一个终端下的网络流量监控工具,它的特别之处在于可以显示每个进程的带宽占用情况,这样可以更直观获取网络使用情况。它支持 IPv4 和 IPv6 协议、支持本地网卡及 PPP 链接。

下载:

从SourceForge上下载nethogs-0.8.0.tar.gz

使用wget下载:

wget http://sourceforge.net/projects/nethogs/files/nethogs/0.8/nethogs-0.8.0.tar.gz/download

安装:

个人补充:

首先,需要g++编译器,因为nethogs是使用c++编写,即.cpp结尾的文件,必须使用g++进行编译,如果是.c,使用gcc编译器即可。

# rpm -ivh libstdc++-devel-4.1.2-51.el5.x86_64.rpm

# rpm -ivh gcc-c++-4.1.2-51.el5.x86_64.rpm

# ls /mnt/Server/ |grep ncur
ncurses-5.5-24.20060715.i386.rpm
ncurses-5.5-24.20060715.x86_64.rpm
ncurses-devel-5.5-24.20060715.i386.rpm
ncurses-devel-5.5-24.20060715.x86_64.rpm
php-ncurses-5.1.6-27.el5_5.3.x86_64.rpm

然后,需要先 yum install ncurses*,如果安装提示需要下载,可以直接使用rpm -ivh 安装即可,具体安装,如上所示。

  1. [root@localhost Desktop]# yum install ncurses*
  2. Loaded plugins: fastestmirror, refresh-packagekit, security
  3. Loading mirror speeds from cached hostfile
  4. * base: mirrors.skyshe.cn
  5. * extras: mirrors.skyshe.cn
  6. * updates: mirrors.skyshe.cn
  7. Setting up Install Process
  8. Package ncurses-5.7-3.20090208.el6.x86_64 already installed and latest version
  9. Package ncurses-libs-5.7-3.20090208.el6.x86_64 already installed and latest version
  10. Package ncurses-base-5.7-3.20090208.el6.x86_64 already installed and latest version
  11. Resolving Dependencies
  12. --> Running transaction check
  13. ---> Package ncurses-devel.x86_64 0:5.7-3.20090208.el6 will be installed
  14. ---> Package ncurses-static.x86_64 0:5.7-3.20090208.el6 will be installed
  15. ---> Package ncurses-term.x86_64 0:5.7-3.20090208.el6 will be installed
  16. --> Finished Dependency Resolution
  17. Dependencies Resolved
  18. ========================================================================================================================================================================
  19. Package                                    Arch                               Version                                           Repository                        Size
  20. ========================================================================================================================================================================
  21. Installing:
  22. ncurses-devel                              x86_64                             5.7-3.20090208.el6                                base                             642 k
  23. ncurses-static                             x86_64                             5.7-3.20090208.el6                                base                             546 k
  24. ncurses-term                               x86_64                             5.7-3.20090208.el6                                base                             547 k
  25. Transaction Summary
  26. ========================================================================================================================================================================
  27. Install       3 Package(s)
  28. Total download size: 1.7 M
  29. Installed size: 6.8 M
  30. Is this ok [y/N]: y
  31. Downloading Packages:
  32. (1/3): ncurses-devel-5.7-3.20090208.el6.x86_64.rpm                                                                                               | 642 kB     00:01
  33. (2/3): ncurses-static-5.7-3.20090208.el6.x86_64.rpm                                                                                              | 546 kB     00:00
  34. (3/3): ncurses-term-5.7-3.20090208.el6.x86_64.rpm                                                                                                | 547 kB     00:02
  35. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  36. Total                                                                                                                                   284 kB/s | 1.7 MB     00:06
  37. Running rpm_check_debug
  38. Running Transaction Test
  39. Transaction Test Succeeded
  40. Running Transaction
  41. Installing : ncurses-devel-5.7-3.20090208.el6.x86_64                                                                                                              1/3
  42. Installing : ncurses-static-5.7-3.20090208.el6.x86_64                                                                                                             2/3
  43. Installing : ncurses-term-5.7-3.20090208.el6.x86_64                                                                                                               3/3
  44. Verifying  : ncurses-term-5.7-3.20090208.el6.x86_64                                                                                                               1/3
  45. Verifying  : ncurses-static-5.7-3.20090208.el6.x86_64                                                                                                             2/3
  46. Verifying  : ncurses-devel-5.7-3.20090208.el6.x86_64                                                                                                              3/3
  47. Installed:
  48. ncurses-devel.x86_64 0:5.7-3.20090208.el6              ncurses-static.x86_64 0:5.7-3.20090208.el6              ncurses-term.x86_64 0:5.7-3.20090208.el6
  49. Complete!

解压文件:

tar -zxvf nethogs-0.8.0.tar.gz

切换目录:

cd nethogs

编译安装:

make && make install

make出错了:

  1. [root@localhost nethogs]# make && make install
  2. cc -g -Wall -Wextra -c decpcap.c
  3. decpcap.c:7:18: error: pcap.h: No such file or directory
  4. In file included from decpcap.c:8:
  5. decpcap.h:34: error: expected specifier-qualifier-list before ‘pcap_t’
  6. decpcap.c:14: error: expected ‘)’ before ‘*’ token
  7. decpcap.c: In function ‘dp_open_offline’:
  8. decpcap.c:48: error: ‘pcap_t’ undeclared (first use in this function)
  9. decpcap.c:48: error: (Each undeclared identifier is reported only once
  10. decpcap.c:48: error: for each function it appears in.)
  11. decpcap.c:48: error: ‘temp’ undeclared (first use in this function)
  12. decpcap.c:48: warning: implicit declaration of function ‘pcap_open_offline’
  13. decpcap.c:55: warning: implicit declaration of function ‘dp_fillhandle’
  14. decpcap.c: In function ‘dp_open_live’:
  15. decpcap.c:60: error: ‘pcap_t’ undeclared (first use in this function)
  16. decpcap.c:60: error: ‘temp’ undeclared (first use in this function)
  17. decpcap.c:60: warning: implicit declaration of function ‘pcap_open_live’
  18. decpcap.c: In function ‘dp_addcb’:
  19. decpcap.c:74: error: ‘struct dp_handle’ has no member named ‘callback’
  20. decpcap.c: In function ‘dp_parse_tcp’:
  21. decpcap.c:84: error: ‘struct dp_handle’ has no member named ‘callback’
  22. decpcap.c:86: error: ‘struct dp_handle’ has no member named ‘callback’
  23. decpcap.c:87: error: ‘struct dp_handle’ has no member named ‘userdata’
  24. decpcap.c: In function ‘dp_parse_ip’:
  25. decpcap.c:99: error: dereferencing pointer to incomplete type
  26. decpcap.c:103: error: ‘struct dp_handle’ has no member named ‘callback’
  27. decpcap.c:105: error: ‘struct dp_handle’ has no member named ‘callback’
  28. decpcap.c:106: error: ‘struct dp_handle’ has no member named ‘userdata’
  29. decpcap.c: In function ‘dp_parse_ip6’:
  30. decpcap.c:126: error: ‘struct dp_handle’ has no member named ‘callback’
  31. decpcap.c:128: error: ‘struct dp_handle’ has no member named ‘callback’
  32. decpcap.c:129: error: ‘struct dp_handle’ has no member named ‘userdata’
  33. decpcap.c: In function ‘dp_parse_ethernet’:
  34. decpcap.c:150: error: ‘struct dp_handle’ has no member named ‘callback’
  35. decpcap.c:152: error: ‘struct dp_handle’ has no member named ‘callback’
  36. decpcap.c:153: error: ‘struct dp_handle’ has no member named ‘userdata’
  37. decpcap.c: In function ‘dp_parse_ppp’:
  38. decpcap.c:196: error: ‘struct dp_handle’ has no member named ‘callback’
  39. decpcap.c:198: error: ‘struct dp_handle’ has no member named ‘callback’
  40. decpcap.c:199: error: ‘struct dp_handle’ has no member named ‘userdata’
  41. decpcap.c: In function ‘dp_parse_linux_cooked’:
  42. decpcap.c:238: error: ‘struct dp_handle’ has no member named ‘callback’
  43. decpcap.c:240: error: ‘struct dp_handle’ has no member named ‘callback’
  44. decpcap.c:241: error: ‘struct dp_handle’ has no member named ‘userdata’
  45. decpcap.c: In function ‘dp_pcap_callback’:
  46. decpcap.c:270: error: ‘struct dp_handle’ has no member named ‘userdata_size’
  47. decpcap.c:271: error: ‘struct dp_handle’ has no member named ‘userdata’
  48. decpcap.c:271: error: ‘struct dp_handle’ has no member named ‘userdata_size’
  49. decpcap.c:273: error: ‘struct dp_handle’ has no member named ‘linktype’
  50. decpcap.c:274: error: ‘DLT_EN10MB’ undeclared (first use in this function)
  51. decpcap.c:277: error: ‘DLT_PPP’ undeclared (first use in this function)
  52. decpcap.c:280: error: ‘DLT_LINUX_SLL’ undeclared (first use in this function)
  53. decpcap.c:283: error: ‘DLT_RAW’ undeclared (first use in this function)
  54. decpcap.c:284: error: ‘DLT_NULL’ undeclared (first use in this function)
  55. decpcap.c:289: error: ‘struct dp_handle’ has no member named ‘linktype’
  56. decpcap.c: In function ‘dp_dispatch’:
  57. decpcap.c:296: error: ‘struct dp_handle’ has no member named ‘userdata’
  58. decpcap.c:297: error: ‘struct dp_handle’ has no member named ‘userdata_size’
  59. decpcap.c:298: warning: implicit declaration of function ‘pcap_dispatch’
  60. decpcap.c:298: error: ‘struct dp_handle’ has no member named ‘pcap_handle’
  61. decpcap.c: In function ‘dp_setnonblock’:
  62. decpcap.c:302: warning: implicit declaration of function ‘pcap_setnonblock’
  63. decpcap.c:302: error: ‘struct dp_handle’ has no member named ‘pcap_handle’
  64. decpcap.c: In function ‘dp_geterr’:
  65. decpcap.c:307: warning: implicit declaration of function ‘pcap_geterr’
  66. decpcap.c:307: error: ‘struct dp_handle’ has no member named ‘pcap_handle’
  67. make: *** [decpcap.o] Error 1

还是缺少依赖的东西,执行以下命令安装:

yum install libpcap-dev libncurses5-dev

  1. [root@localhost nethogs]# yum install libpcap-dev libncurses5-dev
  2. Loaded plugins: fastestmirror, refresh-packagekit, security
  3. Loading mirror speeds from cached hostfile
  4. * base: mirrors.skyshe.cn
  5. * extras: mirrors.skyshe.cn
  6. * updates: mirrors.skyshe.cn
  7. Setting up Install Process
  8. No package libpcap-dev available.
  9. No package libncurses5-dev available.
  10. Error: Nothing to do
  11. [root@localhost nethogs]# yum  -y install libpcap-devel  ncurses-devel  注意,此处安装时,如果用rpm -qa|grep libpcap-devel 可以查到,但是到光盘的目录查找不一定有, ls /mnt/Server |grep ncurses-devel,故使用rpm -ivh分别取安装 libpcap-devel  ncurses-devel  不一定成功,所以直接使用yum  -y install libpcap-devel  ncurses-devel 即可。
  12. Loaded plugins: fastestmirror, refresh-packagekit, security
  13. Loading mirror speeds from cached hostfile
  14. * base: mirrors.skyshe.cn
  15. * extras: mirrors.skyshe.cn
  16. * updates: mirrors.skyshe.cn
  17. Setting up Install Process
  18. Package ncurses-devel-5.7-3.20090208.el6.x86_64 already installed and latest version
  19. Resolving Dependencies
  20. --> Running transaction check
  21. ---> Package libpcap-devel.x86_64 14:1.4.0-1.20130826git2dbcaa1.el6 will be installed
  22. --> Finished Dependency Resolution
  23. Dependencies Resolved
  24. ===============================================================================================================================================================================================
  25. Package                                      Arch                                  Version                                                          Repository                           Size
  26. ===============================================================================================================================================================================================
  27. Installing:
  28. libpcap-devel                                x86_64                                14:1.4.0-1.20130826git2dbcaa1.el6                                base                                114 k
  29. Transaction Summary
  30. ===============================================================================================================================================================================================
  31. Install       1 Package(s)
  32. Total download size: 114 k
  33. Installed size: 160 k
  34. Downloading Packages:
  35. libpcap-devel-1.4.0-1.20130826git2dbcaa1.el6.x86_64.rpm                                                                                                                 | 114 kB     00:00
  36. Running rpm_check_debug
  37. Running Transaction Test
  38. Transaction Test Succeeded
  39. Running Transaction
  40. Installing : 14:libpcap-devel-1.4.0-1.20130826git2dbcaa1.el6.x86_64                                                                                                                      1/1
  41. Verifying  : 14:libpcap-devel-1.4.0-1.20130826git2dbcaa1.el6.x86_64                                                                                                                      1/1
  42. Installed:
  43. libpcap-devel.x86_64 14:1.4.0-1.20130826git2dbcaa1.el6
  44. Complete!

再执行:make && make install

  1. [root@localhost nethogs]# make && make install
  2. cc -g -Wall -Wextra -c decpcap.c
  3. decpcap.c: In function ‘dp_open_live’:
  4. decpcap.c:60: warning: passing argument 5 of ‘pcap_open_live’ discards qualifiers from pointer target type
  5. /usr/include/pcap/pcap.h:349: note: expected ‘char *’ but argument is of type ‘const char *’
  6. g++ -g -Wall -Wextra -c cui.cpp -DVERSION=\"0\" -DSUBVERSION=\"8\" -DMINORVERSION=\"0\"
  7. g++ -g -Wall -Wextra -c inode2prog.cpp
  8. g++ -g -Wall -Wextra -c conninode.cpp
  9. g++    -c -o devices.o devices.cpp
  10. g++ -g -Wall -Wextra nethogs.cpp packet.o connection.o process.o refresh.o decpcap.o cui.o inode2prog.o conninode.o devices.o -o nethogs -lpcap -lm -lncurses -DVERSION=\"0\" -DSUBVERSION=\"8\" -DMINORVERSION=\"0\"
  11. g++ -g -Wall -Wextra decpcap_test.cpp decpcap.o -o decpcap_test -lpcap -lm
  12. install -d -m 755 /usr/local/sbin
  13. install -m 755 nethogs /usr/local/sbin
  14. install -d -m 755 /usr/local/share/man/man8/
  15. install -m 644 nethogs.8 /usr/local/share/man/man8/

安装成功了!

执行:nethogs

  1. [root@localhost nethogs]# nethogs
  2. Waiting for first packet to arrive (see sourceforge.net bug 1019381)
  3. NetHogs version 0.8.0
  4. PID USER     PROGRAM                                                                                                                                     DEV        SENT      RECEIVED
  5. 3227  root     sshd: root@pts/2                                                                                                                            eth0       0.666   0.059 KB/sec
  6. ?     root     unknown TCP                                                                                                                                            0.000   0.000 KB/sec
  7. TOTAL                                                                                                                                                               0.666       0.059 KB/sec

下图显示各进程当前网络使用情况:


按“m”键可以切换到统计视图,显示各进程总的网络使用情况


按“Ctrl+C”或“q”退出监控

使用帮助:

  1. [root@localhost ~]# nethogs --help
  2. nethogs: invalid option -- '-'
  3. usage: nethogs [-V] [-b] [-d seconds] [-t] [-p] [device [device [device ...]]]
  4. -V : 显示版本信息,注意是大写字母V.
  5. -d : 延迟更新刷新速率,以秒为单位。默认值为 1.
  6. -t : 跟踪模式.
  7. -b : bug 狩猎模式 — — 意味着跟踪模式.
  8. -p : 混合模式(不推荐).
  9. 设备 : 要监视的设备名称. 默认为 eth0
  10. 当 nethogs 运行时, 按:
  11. q: 退出

NetHogs下载和监控的更多相关文章

  1. 使用Typescript重构axios(二十五)——文件上传下载进度监控

    0. 系列文章 1.使用Typescript重构axios(一)--写在最前面 2.使用Typescript重构axios(二)--项目起手,跑通流程 3.使用Typescript重构axios(三) ...

  2. centos8平台使用nethogs基于进程监控网络流量

    一,nethogs的作用: 按进程或程序实时统计网络带宽使用率 我们查看流量的占用时,知道来源的ip.访问的端口,还不足以帮我们确认到进程, 而nethogs则可以让我们查看每个进程所占用的流量带宽 ...

  3. linux 下监控进程流量情况命令 NetHogs

    摘自: http://www.cnblogs.com/kerrycode/p/4748970.html NetHogs介绍 NetHogs是一款开源.免费的,终端下的网络流量监控工具,它可监控Linu ...

  4. Linux NetHogs监控工具介绍

    NetHogs介绍 NetHogs是一款开源.免费的,终端下的网络流量监控工具,它可监控Linux的进程或应用程序的网络流量.NetHogs只能实时监控进程的网络带宽占用情况.NetHogs支持IPv ...

  5. Linux NetHogs监控工具介绍(转)

    NetHogs介绍 NetHogs是一款开源.免费的,终端下的网络流量监控工具,它可监控Linux的进程或应用程序的网络流量.NetHogs只能实时监控进程的网络带宽占用情况.NetHogs支持IPv ...

  6. NetHogs 实时检测网络流量 转

    有很多适用于Linux系统的开源网络监视工具.比如说,你可以用命令iftop来检查带宽使用情况. netstat用来查看接口统计报告,还有top监控系统当前运行进程.但是如果你想要找一个能够按进程实时 ...

  7. NetHogs——Linux下按进程实时统计网络带宽利用率

    Debian/Ubuntu下安装很简单,执行:apt-get install nethogs 就可以安装. CentOS/RHEL下建议先安装上EPEL,再执行:yum install libpcap ...

  8. linux 网络数据收发网络流量监控

    网卡流量 1.iftop命令 iftop可以用来监控网卡的实时流量(可以指定网段).反向解析IP.显示端口信息.TCP/IP连接等官网:http://www.ex-parrot.com/~pdw/if ...

  9. Spark的Straggler深入学习(1):如何在本地图形监控远程Spark的GC情况——使用java自带的jvisualvm

    一.本文的目的       Straggler是目前研究的热点,Spark中也存在Straggler的问题.GC问题是总所周知的导致Straggler的重要因素之一,为了了解GC导致的Straggle ...

随机推荐

  1. 【Android】去除应用启动时黑屏现象

    http://www.eoeandroid.com/blog-1169143-47979.html 在AndroidManifest里面定义的时候,在启动的Activity,添加android:the ...

  2. 极客DIY:廉价电视棒玩转GNSS-SDR,实现GPS实时定位

    0×00 前言 GNSS是Global Navigation Satellite System的缩写.中文称作:全球卫星导航系统.全球导航卫星系统. GNSS泛指所有的卫星导航系统,包括全球的.区域的 ...

  3. js中的apply调用

    今天看了阮一锋老师的一篇文章,感觉很明了对闭包的理解,尤其是文章中的apply的介绍 apply()是函数对象的一个方法,它的作用是改变函数的调用对象,它的第一个参数就表示改变后的调用这个函数的对象. ...

  4. C# 线程问题

    一:概述和概念 C#支持通过多线程并行地执行代码,一个线程有它独立的执行路径,能够与其它的线程同时地运行.一个C#程序开始于一个单线程,这个单线程是被CLR和操作系统(也称为"主线程&quo ...

  5. ios即时通讯客户端开发之-mac上搭建openfire服务器

    一.下载并安装openfire 1.到http://www.igniterealtime.org/downloads/index.jsp下载最新openfire for mac版 比如:Openfir ...

  6. [动态规划]状态压缩DP小结

     1.小技巧 枚举集合S的子集:for(int i = S; i > 0; i=(i-1)&S) 枚举包含S的集合:for(int i = S; i < (1<<n); ...

  7. 第一个demo

    1.首先这是最初的概念模型. 2.最后设计成这样. 3.运行

  8. 部分android手机CCEditBox输入之后键盘输入框不消失得问题

    用小米2s做登录界面时,用到CCEditBOx,输入完之后,键盘可以移下去,但是屏幕上还是显示得键盘自己得输入框,这时点击屏幕任何位置都无法把输入框干掉. 为什么ios上就没有这些android得琐碎 ...

  9. Ubuntu 改变workspace布局

    今天花了点时间找ubuntu的workspace布局.发现一个软件,tweak, 非常好用,可以随意调整布局. Ref: http://ubuntuhandbook.org/index.php/201 ...

  10. 使用BitTorrent-Sync实现双机文件双向同步

    BitTorrent-Sync是一款基于P2P的分布式文件同步工具,简称btsync,非开源软件但免费使用.本文使用btsync实现两台服务器上的软件双向同步. 安装 直接从官网下载相应的安装包,为了 ...