linux统计工具nethogs
Nethogs 是一个终端下的网络流量监控工具,可以显示每个进程的带宽占用情况,以便直观获取网络使用情况。
支持 IPv4 和 IPv6 协议、支持本地网卡及 PPP 链接。
nethogs命令工具的安装过程:
复制代码 代码示例:
##下载##
[root@i
python ~]# wget http://softlayer-dal.dl.sourceforge.net/project/nethogs/nethogs/0.8/nethogs-0.8.0.tar.gz
##依赖安装##
[root@ipython ~]#
yum install libpcap-devel ncurses-devel
##build iftop##
[root@ipython ~]# tar zxf nethogs-0.8.0.tar.gz
[root@ipython ~]# cd nethogs
[root@ipython nethogs]# make && make install
运行nethogs命令:
[root@ipython ~]# nethogs --help
nethogs: invalid option -- '-'
usage: nethogs [-V] [-b] [-d seconds] [-t] [-p] [device [device [device ...]]]
-V : 版本输出
-d : 延迟刷新,默认1秒
-t : 跟踪模式
-b : bughunt mode - implies tracemode.
-p : 指定接口
When nethogs is running, press:
q: quit
m: switch between total and kb/s mode
awk 处理nethogs日志:
复制代码 代码示例:
[root@ipython ~]# nethogs > awk_nethogs.txt
Waiting for first packet to arrive (see sourceforge.net bug 1019381)
[root@ipython ~]# cat -A awk_nethogs.txt |awk -F '[ ^]+' '/?/&&!/unknown/{sub(/^.*H/,"",$4);sub(/^.*G/,"",$5);print $3"t"$4"t"$5}'
[[1;23r [(B [[m
[[0;7m PID USER
[[0;7m PID USER
[[0;7m PID USER
107.170.243.66:80-27.115.124.32:38707 0.119 0.091
107.170.243.66:80-27.115.124.32:38707 0.119 0.091
107.170.243.66:80-27.115.124.32:38707 0.119 0.091
107.170.243.66:80-27.115.124.32:38707 0.119 0.091
107.170.243.66:80-27.115.124.32:38707 0.119 0.091