NetHogs下载和监控

article/2025/10/14 6:39:38

转自:http://blog.csdn.net/testcs_dn/article/details/40506225

CentOS6.5下使用NetHogs监控进程网络使用情况

分类: CentOS

目录(?)[+]

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 安装即可,具体安装,如上所示。

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  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.   
  18. Dependencies Resolved  
  19.   
  20. ========================================================================================================================================================================  
  21.  Package                                    Arch                               Version                                           Repository                        Size  
  22. ========================================================================================================================================================================  
  23. Installing:  
  24.  ncurses-devel                              x86_64                             5.7-3.20090208.el6                                base                             642 k  
  25.  ncurses-static                             x86_64                             5.7-3.20090208.el6                                base                             546 k  
  26.  ncurses-term                               x86_64                             5.7-3.20090208.el6                                base                             547 k  
  27.   
  28. Transaction Summary  
  29. ========================================================================================================================================================================  
  30. Install       3 Package(s)  
  31.   
  32. Total download size: 1.7 M  
  33. Installed size: 6.8 M  
  34. Is this ok [y/N]: y  
  35. Downloading Packages:  
  36. (1/3): ncurses-devel-5.7-3.20090208.el6.x86_64.rpm                                                                                               | 642 kB     00:01       
  37. (2/3): ncurses-static-5.7-3.20090208.el6.x86_64.rpm                                                                                              | 546 kB     00:00       
  38. (3/3): ncurses-term-5.7-3.20090208.el6.x86_64.rpm                                                                                                | 547 kB     00:02       
  39. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------  
  40. Total                                                                                                                                   284 kB/s | 1.7 MB     00:06       
  41. Running rpm_check_debug  
  42. Running Transaction Test  
  43. Transaction Test Succeeded  
  44. Running Transaction  
  45.   Installing : ncurses-devel-5.7-3.20090208.el6.x86_64                                                                                                              1/3   
  46.   Installing : ncurses-static-5.7-3.20090208.el6.x86_64                                                                                                             2/3   
  47.   Installing : ncurses-term-5.7-3.20090208.el6.x86_64                                                                                                               3/3   
  48.   Verifying  : ncurses-term-5.7-3.20090208.el6.x86_64                                                                                                               1/3   
  49.   Verifying  : ncurses-static-5.7-3.20090208.el6.x86_64                                                                                                             2/3   
  50.   Verifying  : ncurses-devel-5.7-3.20090208.el6.x86_64                                                                                                              3/3   
  51.   
  52. Installed:  
  53.   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               
  54.   
  55. Complete!  
解压文件:

tar -zxvf nethogs-0.8.0.tar.gz

切换目录:

cd nethogs

编译安装:

 

make && make install

make出错了:

 

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  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

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  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.   
  24. Dependencies Resolved  
  25.   
  26. ===============================================================================================================================================================================================  
  27.  Package                                      Arch                                  Version                                                          Repository                           Size  
  28. ===============================================================================================================================================================================================  
  29. Installing:  
  30.  libpcap-devel                                x86_64                                14:1.4.0-1.20130826git2dbcaa1.el6                                base                                114 k  
  31.   
  32. Transaction Summary  
  33. ===============================================================================================================================================================================================  
  34. Install       1 Package(s)  
  35.   
  36. Total download size: 114 k  
  37. Installed size: 160 k  
  38. Downloading Packages:  
  39. libpcap-devel-1.4.0-1.20130826git2dbcaa1.el6.x86_64.rpm                                                                                                                 | 114 kB     00:00       
  40. Running rpm_check_debug  
  41. Running Transaction Test  
  42. Transaction Test Succeeded  
  43. Running Transaction  
  44.   Installing : 14:libpcap-devel-1.4.0-1.20130826git2dbcaa1.el6.x86_64                                                                                                                      1/1   
  45.   Verifying  : 14:libpcap-devel-1.4.0-1.20130826git2dbcaa1.el6.x86_64                                                                                                                      1/1   
  46.   
  47. Installed:  
  48.   libpcap-devel.x86_64 14:1.4.0-1.20130826git2dbcaa1.el6                                                                                                                         
  49. Complete!  
再执行:make && make install
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  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

 

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@localhost nethogs]# nethogs  
  2. Waiting for first packet to arrive (see sourceforge.net bug 1019381)  
  3.   
  4. NetHogs version 0.8.0  
  5.   
  6.   PID USER     PROGRAM                                                                                                                                     DEV        SENT      RECEIVED         
  7. 3227  root     sshd: root@pts/2                                                                                                                            eth0       0.666   0.059 KB/sec  
  8. ?     root     unknown TCP                                                                                                                                            0.000   0.000 KB/sec  
  9.   
  10.   TOTAL                                                                                                                                                               0.666       0.059 KB/sec   

 

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


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


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

使用帮助:

 

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  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.   
  11. 当 nethogs 运行时, 按:  
  12.  q: 退出  

转载于:https://www.cnblogs.com/anruy/p/4891913.html


http://chatgpt.dhexx.cn/article/c2XrTeRo.shtml

相关文章

Centos7 部署 Nethogs

可用来按进程或程序实时统计网络带宽使用率 安装依赖包 yum install libpcap libpcap-devel epel-release -y 安装epel源 yum install epel-release -y 安装Nethogs yum install nethogs -y 运行测试 查看版本 nethogs -V version 0.8.5 直接执行nethogs界面如下 监控…

linux 查看使用网络的程序,linux下nethogs查看各程序的网络占用量

一、概述 inux下的流量查看工具很多,如:iptraf、nload、ifstat、sar等。当然每个工具都有各自的优势。不过以上所有工具有没一款都针对服务进程所占用的流量的具体情况给出结果。(我是不知道,如果有以上工具有这方面的功能,麻烦一…

nethogs-iftop等网络监控软件---Linux

一、Linux系统 1、nethogs 1)centos7.1下nethogs安装方法 (1)先安装epel,使用的命令是:rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm (2)yum install net…

CentOS下使用NetHogs监控进程网络使用情况

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

nethogs命令

性能监测与优化 《Linux就该这么学》是一本基于最新Linux系统编写的入门必读书籍,内容面向零基础读者,由浅入深渐进式教学,销量保持国内第一,年销售量预期超过10万本。点此免费在线阅读。 有很多适用于Linux系统的开源网络监视工…

Linux学习准备,nethogs,htop,nmon,dstat用法

Nethogs用法: 在基于RedHat系统下键入如下命令启动NetHogs工具. # nethogs 要执行NetHogs你必须拥有root权限,即如图所示用sudo命令 $ sudo nethogs 以下就是NetHogs命令行的参数,用’-d’来添加刷新频率参数,device name 用来检测给定的某个或者某些设备的带宽(默认…

nethogs和nload流量监控工具

nethogs和nload流量监控工具 nethogs流量监控工具NetHogs安装NetHogs命令参数 nload流量监控工具nload安装内容解释:参数:实例: nethogs流量监控工具 工具存在部分局限性,如果网卡存在大量网络连接会导致nethogs卡死 NetHogs安装 …

redhad安装nethogs

工作需要监控linux下的进程宽带占有量,从网上找了资料,很多不能成功,现在整理一下 安装 Debian/Ubuntu下安装很简单,执行:apt-get install nethogs 就可以安装。 CentOS/RHEL下建议先安装EPEL,再执行&…

nethogs安装部署

Ubuntu安装部署 apt-get -y install ncurses* apt-get -y install libpcap-dev libncurses5-dev wget -c https://github.com/raboof/nethogs/archive/v0.8.1.tar.gz tar xvf v0.8.1.tar.gz cd nethogs-0.8.1 make && make install centos安装部署 wget https://gi…

nethogs

下载地址:https://github.com/raboof/nethogs/releases 安装基础包 Debian/Ubuntu apt-get install build-essential libncurses5-dev libpcap-devYum-based distros yum install gcc-c libpcap-devel.x86_64 libpcap.x86_64 "ncurses*"Getting the so…

Linux系统调优详解(七)——网络状态查看命令nethogs

今天继续给大家介绍Linux运维相关知识,本文主要内容是网络状态查看命令nethogs。 一、nethogs命令安装 nethogs工具可以帮助我们很方便的查看当前系统中的进程使用网络的情况,这有助于我们找到当前系统中的网络瓶颈。nethogs命令需要首先安装&#xff…

【超详细】Linux系统之nethogs命令

1.简介 NetHogs是一个小型的net top工具,不像大多数工具那样拖慢每个协议或者是每个子网的速度而是依照进程进行带宽分组。 NetHogs不需要依赖载入某个特殊的内核模块。 假如发生了网络堵塞你能够使用NetHogs立即看到哪个PID形成的这种情况。 这样就很容易找出哪…

Linux工具之nethogs命令

一、nethogs命令简介 NetHogs是一个小型的net top工具,不像大多数工具那样拖慢每个协议或者是每个子网的速度而是按照进程进行带宽分组。NetHogs不需要依赖载入某个特殊的内核模块。如果发生了网络阻塞你可以启动NetHogs立即看到哪个PID造成的这种状况。这样就很容易…

(嵌入式系统开发)stm32串口通信与RS-232

本篇主要叙述串口协议和RS-232标准,以及RS232电平与TTL电平的区别;了解"USB/TTL转232"模块(以CH340芯片模块为例)的工作原理。 目录 一、串口协议与RS-232标准 1.串口通信协议 2. RS-232标准 1. RS232电平与TTL电平…

STM32与K210串口通信

目录 1.前言 2.接线部分 3.代码部分 1.k210部分 1.调用自带的库文件 2.将I/O18设置为UART1_TX功能并设置串口 3.数据发送函数 4.主函数 4.程序现象 2.STM32部分 1主函数 2.串口接收程序 3.程序现象 4.完整代码 5.总结 1.前言 这篇文章是为了填上一篇k210的简单PID…

八、STM32串口通信

目录 一、串口通信 1.1串口通信物理层 1.2USB转串口模块 1.3串口通信的其他应用 1.4串口数据包的基本组成 二、串口的结构体与函数讲解 2.1串口讲解 2.2结构体讲解 2.3串口初始化函数讲解 三、串口发送字符 3.1如何配置串口的发送 3.2项目实战 四、串口的中断接收 …

基于是stm32的串口通信

文章目录 一、串口协议和RS-232标准(一)、TTL电平标准(二)、RS232标准二、搭建STM32开发环境1.安装jdk2.安装STM32CubeMX三、实现LED的点亮3.1分析相应的原理图3.2使用CubeMX生成相关代码3.3实验结果四、STM32的USART串口通讯程序…

STM32串口通信详解(嵌入式学习)

STM32串口通信 1.通信基础知识1.1 时钟信号区分同步通信异步通信波特率总线协议(电气协议) 1.2 通信方式划分串行通信并行通信 1.3 通信方向划分单工通信半双工通信全双工通信常见通信总结 2. USARTUSART 介绍 3. 串口通信协议4. 相关寄存器串口控制寄存器波特率寄存器中断和状…

第七篇,STM32串口通信编程

1.通信的基本概念 (1)串行通信和并行通信 (2)单工,半双工和全双工 (3)通信速率 单位时间内传输的比特数表示传输速度,叫做波特率(bps) (4)通信协议(串口) 通…

STM32串口通信配置(USART/UART)

在配置USART和UART之前,得先明白什么是USART和UART以及它们之间有什么区别,其实两者是同步和异步的区别。 UART:universal asynchronous receiver and transmitter通用异步收发器; USART:universal synchronous asynch…