Nethogs 是一個(gè)終端下的網(wǎng)絡(luò)流量監(jiān)控工具,它的特別之處在于可以顯示每個(gè)進(jìn)程的帶寬占用情況,這樣可以更直觀獲取網(wǎng)絡(luò)使用情況。它支持 IPv4 和 IPv6 協(xié)議、支持本地網(wǎng)卡及 PPP 鏈接。
安裝過(guò)程
##下載##
[root@ipython ~]# 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
直接運(yùn)行
[root@ipython ~]# nethogs --help
nethogs: invalid option -- '-'
usage: nethogs [-V] [-b] [-d seconds] [-t] [-p] [device [device [device ...]]]
-V : 版本輸出
-d : 延遲刷新,默認(rèn)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