zoukankan      html  css  js  c++  java
  • 利用nethogs查看哪些进程占用网络带宽

    一、安装nethogs

    centos6版本安装:

    1、安装依赖包

    [root@hlsms-fensheng-3 ~]# yum install ncurses*
    已加载插件:fastestmirror, security
    设置安装进程
    Loading mirror speeds from cached hostfile
     * base: mirrors.tuna.tsinghua.edu.cn
     * extras: mirror.bit.edu.cn
     * updates: mirror.bit.edu.cn
    base                                                                                                                         | 3.7 kB     00:00     
    dell-system-update_dependent                                                                                                 | 2.3 kB     00:00     
    dell-system-update_independent                                                                                               | 2.3 kB     00:00     
    extras                                                                                                                       | 3.4 kB     00:00     
    mysql-connectors-community                                                                                                   | 2.5 kB     00:00     
    mysql-tools-community                                                                                                        | 2.5 kB     00:00     
    mysql57-community                                                                                                            | 2.5 kB     00:00     
    updates                                                                                                                      | 3.4 kB     00:00     
    包 ncurses-devel-5.7-4.20090207.el6.x86_64 已安装并且是最新版本
    包 ncurses-5.7-4.20090207.el6.x86_64 已安装并且是最新版本
    包 ncurses-libs-5.7-4.20090207.el6.x86_64 已安装并且是最新版本
    包 ncurses-base-5.7-4.20090207.el6.x86_64 已安装并且是最新版本
    解决依赖关系
    --> 执行事务检查
    ---> Package ncurses-static.x86_64 0:5.7-4.20090207.el6 will be 安装
    ---> Package ncurses-term.x86_64 0:5.7-4.20090207.el6 will be 安装
    --> 完成依赖关系计算
    
    依赖关系解决
    
    ====================================================================================================================================================
     软件包                                架构                          版本                                         仓库                         大小
    ====================================================================================================================================================
    正在安装:
     ncurses-static                        x86_64                        5.7-4.20090207.el6                           base                        543 k
     ncurses-term                          x86_64                        5.7-4.20090207.el6                           base                        546 k
    
    事务概要
    ====================================================================================================================================================
    Install       2 Package(s)
    
    总下载量:1.1 M
    Installed size: 5.1 M
    确定吗?[y/N]:y
    下载软件包:
    (1/2): ncurses-static-5.7-4.20090207.el6.x86_64.rpm                                                                          | 543 kB     00:00     
    (2/2): ncurses-term-5.7-4.20090207.el6.x86_64.rpm                                                                            | 546 kB     00:00     
    ----------------------------------------------------------------------------------------------------------------------------------------------------
    总计                                                                                                                 83 kB/s | 1.1 MB     00:13     
    运行 rpm_check_debug 
    执行事务测试
    事务测试成功
    执行事务
      正在安装   : ncurses-term-5.7-4.20090207.el6.x86_64                                                                                           1/2 
      正在安装   : ncurses-static-5.7-4.20090207.el6.x86_64                                                                                         2/2 
      Verifying  : ncurses-static-5.7-4.20090207.el6.x86_64                                                                                         1/2 
      Verifying  : ncurses-term-5.7-4.20090207.el6.x86_64                                                                                           2/2 
    
    已安装:
      ncurses-static.x86_64 0:5.7-4.20090207.el6                                ncurses-term.x86_64 0:5.7-4.20090207.el6                               
    
    完毕!
    [root@hlsms-fensheng-3 ~]# yum install libpcap*
    已加载插件:fastestmirror, security
    设置安装进程
    Loading mirror speeds from cached hostfile
     * base: mirrors.tuna.tsinghua.edu.cn
     * extras: mirror.bit.edu.cn
     * updates: mirror.bit.edu.cn
    包 14:libpcap-devel-1.4.0-4.20130826git2dbcaa1.el6.x86_64 已安装并且是最新版本
    包 14:libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64 已安装并且是最新版本
    无须任何处理

    2、下载源码包

    [root@hlsms-fensheng-3 ~]# cd /usr/local/src/
    [root@hlsms-fensheng-3 src]# wget https://github.com/raboof/nethogs/archive/v0.8.1.tar.gz
    --2019-09-16 16:34:20--  https://github.com/raboof/nethogs/archive/v0.8.1.tar.gz
    正在解析主机 github.com... 52.74.223.119
    正在连接 github.com|52.74.223.119|:443... 已连接。
    已发出 HTTP 请求,正在等待回应... 302 Found
    位置:https://codeload.github.com/raboof/nethogs/tar.gz/v0.8.1 [跟随至新的 URL]
    --2019-09-16 16:34:26--  https://codeload.github.com/raboof/nethogs/tar.gz/v0.8.1
    正在解析主机 codeload.github.com... 13.250.162.133
    正在连接 codeload.github.com|13.250.162.133|:443... 已连接。
    已发出 HTTP 请求,正在等待回应... 200 OK
    长度:未指定 [application/x-gzip]
    正在保存至: “v0.8.1.tar.gz”
    
        [ <=>                                                                                                       ] 35,986      --.-K/s   in 0.1s    
    
    2019-09-16 16:34:32 (289 KB/s) - “v0.8.1.tar.gz” 已保存 [35986]

    3、编译

    [root@hlsms-fensheng-3 src]# tar -zxvf v0.8.1.tar.gz 
    nethogs-0.8.1/
    nethogs-0.8.1/.cproject
    nethogs-0.8.1/.cvsignore
    nethogs-0.8.1/.gitignore
    nethogs-0.8.1/.project
    nethogs-0.8.1/.travis.yml
    nethogs-0.8.1/COPYING
    nethogs-0.8.1/Changelog
    nethogs-0.8.1/DESIGN
    nethogs-0.8.1/INSTALL
    nethogs-0.8.1/Makefile
    nethogs-0.8.1/README.decpcap.txt
    nethogs-0.8.1/README.md
    nethogs-0.8.1/connection.cpp
    nethogs-0.8.1/connection.h
    nethogs-0.8.1/conninode.cpp
    nethogs-0.8.1/conninode.h
    nethogs-0.8.1/cui.cpp
    nethogs-0.8.1/cui.h
    nethogs-0.8.1/decpcap.c
    nethogs-0.8.1/decpcap.h
    nethogs-0.8.1/decpcap_test.cpp
    nethogs-0.8.1/devices.cpp
    nethogs-0.8.1/devices.h
    nethogs-0.8.1/inode2prog.cpp
    nethogs-0.8.1/inode2prog.h
    nethogs-0.8.1/main.cpp
    nethogs-0.8.1/nethogs.8
    nethogs-0.8.1/nethogs.cpp
    nethogs-0.8.1/nethogs.h
    nethogs-0.8.1/packet.cpp
    nethogs-0.8.1/packet.h
    nethogs-0.8.1/process.cpp
    nethogs-0.8.1/process.h
    nethogs-0.8.1/refresh.cpp
    nethogs-0.8.1/refresh.h
    [root@hlsms-fensheng-3 src]# cd nethogs-0.8.1/
    [root@hlsms-fensheng-3 nethogs-0.8.1]# make && make install
    g++ -Wall -Wextra -c packet.cpp
    g++ -Wall -Wextra -c connection.cpp
    g++ -Wall -Wextra -c process.cpp
    g++ -Wall -Wextra -c refresh.cpp
    cc -Wall -Wextra -c decpcap.c
    g++ -Wall -Wextra -c cui.cpp -DVERSION="0" -DSUBVERSION="8" -DMINORVERSION="1"
    g++ -Wall -Wextra -c inode2prog.cpp
    g++ -Wall -Wextra -c conninode.cpp
    g++ -Wall -Wextra   -c -o devices.o devices.cpp
    g++ -Wall -Wextra  main.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="1"
    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/
    [root@hlsms-fensheng-3 nethogs-0.8.1]# 

    4、运行

    [root@hlsms-fensheng-4 nethogs-0.8.1]# nethogs em1
    Waiting for first packet to arrive (see sourceforge.net bug 1019381)
    NetHogs version 0.8.1
    
        PID USER     PROGRAM                                                               DEV        SENT      RECEIVED       
      11647 mysql    /usr/sbin/mysqld                                                      em1       11.513       0.756 KB/sec
          ? root     172.28.5.152:8101-172.28.5.151:39721                                             0.000       0.012 KB/sec
          ? root     172.28.5.152:46878-172.28.5.148:80                                               0.000       0.000 KB/sec
          ? root     172.28.5.152:46877-172.28.5.148:80                                               0.000       0.000 KB/sec
          ? root     172.28.5.152:46876-172.28.5.148:80                                               0.000       0.000 KB/se

    可以看到哪个进程占用带宽

    centos7版本安装:

    [root@bogon ~]# yum install nethogs
    已加载插件:fastestmirror
    Determining fastest mirrors
     * base: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.aliyun.com
    base                                                                                                                  | 3.6 kB  00:00:00     
    epel                                                                                                                  | 5.3 kB  00:00:00     
    extras                                                                                                                | 3.4 kB  00:00:00     
    updates                                                                                                               | 3.4 kB  00:00:00     
    (1/2): epel/x86_64/updateinfo                                                                                         | 1.0 MB  00:00:05     
    (2/2): epel/x86_64/primary_db                                                                                         | 6.8 MB  00:00:06     
    正在解决依赖关系
    --> 正在检查事务
    ---> 软件包 nethogs.x86_64.0.0.8.5-1.el7 将被 安装
    --> 解决依赖关系完成
    
    依赖关系解决
    
    =============================================================================================================================================
     Package                          架构                            版本                                   源                             大小
    =============================================================================================================================================
    正在安装:
     nethogs                          x86_64                          0.8.5-1.el7                            epel                           38 k
    
    事务概要
    =============================================================================================================================================
    安装  1 软件包
    
    总下载量:38 k
    安装大小:71 k
    Is this ok [y/d/N]: y
    Downloading packages:
    nethogs-0.8.5-1.el7.x86_64.rpm                                                                                        |  38 kB  00:00:05     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      正在安装    : nethogs-0.8.5-1.el7.x86_64                                                                                               1/1 
      验证中      : nethogs-0.8.5-1.el7.x86_64                                                                                               1/1 
    
    已安装:
      nethogs.x86_64 0:0.8.5-1.el7                                                                                                               
    
    完毕!
  • 相关阅读:
    .net http大文件断点续传上传
    asp.net http大文件断点续传上传
    VUE http大文件断点续传上传
    JavaScript http大文件断点续传上传
    ceph之查看osd上pg的分布
    linux 文件系统
    Ceph对象存储网关中的索引工作原理<转>
    ceph 参数说明<转>
    iptables 配置
    c++ 回调类成员函数实现
  • 原文地址:https://www.cnblogs.com/sky-cheng/p/11528162.html
Copyright © 2011-2022 走看看