时候会发现访问Linux服务器特别卡顿或者登录服务器SSH后台进一步发现大量带宽被占用,有什么简单办法能找出哪个进程占用了带宽呢?Linux 监控流量的小工具不少,如 iftop, iptraf等,大都是统计和监控网卡流量的,之前有介绍iftop工具,今天介绍的NetHogs 有点特别,Nethogs 也是Linux下开源的网络流量监控工具,它的特别之处在于可以监控每个进程的网络带宽占用情况,这样可以更直观获取网络使用情况
    nethogs - Net top tool grouping bandwidth per process
    NetHogs is a small ’net top’ tool. Instead of breaking the traffic down per protocol or per subnet, like most such tools do, it groups bandwidth by process - and does not rely on a special kernel module to be loaded. So if there’s suddenly a lot of network traffic, you can fire up NetHogs and immediately see which PID is causing this, and if it’s some kind of spinning process, kill it.
    一、nethogs的下载安装
    1、yum 的方式安装
    [root@YuanFan-Aliyun ~]# yum install nethogs
    Linux网络流量监控工具nethogs - 图1
    2、也可以去如下两个网站去搜索下载rpm包
    1)http://rpmfind.net/
    Linux网络流量监控工具nethogs - 图2
    Linux网络流量监控工具nethogs - 图3
    2)https://pkgs.org/download
    Linux网络流量监控工具nethogs - 图4
    下载好rpm包后,rz命令上传到服务器,rpm -ivh安装
    [root@Storage ~]# rpm -ivh nethogs-0.8.5-1.el6.x86_64.rpm
    Linux网络流量监控工具nethogs - 图5
    二、nethogs的使用

    [root@Storage ~]# nethogs
    默认eth0或者指定网卡,
    [root@Storage ~]# nethogs eth0
    Linux网络流量监控工具nethogs - 图6
    如上图所示,可以看到./ARS ./MTS进程实时占用的带宽较大
    nethogs的用法可以参考man nethogs 或者nethogs -h
    Linux网络流量监控工具nethogs - 图7
    其他参数和用法
    -d : 刷新间隔
    -h : 帮助
    -p : promiscious 模式
    -t : trace模式
    -v : 视图模式
    nethogs的交互命令(键盘快捷键)
    m : 修改单位
    r : 按流量排序
    s : 按发送流量排序
    q : 退出命令提示符