本文由 極客範 -
LQ 翻譯自
Ravi Saive。歡迎加入極客翻譯小組,同我們一道翻譯與分享。轉載請參見文章末尾處的要求。網上有很多適用於Linux操作系統的開源網絡監視工具.比如說,你可以用命令iftop來檢查帶寬使用情況. netstat用來查看接口統計報告,還有top監控系統當前運行進程.但是如果你想要找一個能夠按進程實時統計網絡帶寬利用率,那麼NetHogs就是你所需要的唯一工具.
NetHogs – 網絡帶寬監控
什麼是NetHogs?
NetHogs 是一個開源的命令行工具(類似於Linux的top命令),用來按進程或程序實時統計網絡帶寬使用率.
來自NetHogs項目網站:
NetHogs是一個小型的’net top’工具,不像大多數工具那樣拖慢每個協議或者是每個子網的速度而是按照進程進行帶寬分組.NetHogs NetHogs不需要依賴載入某個特殊的內核模塊. 如果發生了網絡阻塞你可以啓動NetHogs立即看到哪個PID造成的這種狀況.這樣就很容易找出哪個程序跑飛了然後突然佔用你的帶寬.
這篇文章爲你講解了如何在Unix/Linux操作系統下如何安裝和使用NetHogs按進程監控網絡帶寬使用率。
在RHEL,CentOS和Fedora下安裝NetHogs:
要安裝NetHogs,你必須要啓用你所用Linux下的EPEL源.然後運行下面的yum命令下載安裝NetHogs包.
樣例輸出
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
[root@tecmint
~]# yum -y install nethogs
Loaded
plugins:
fastestmirror,
refresh-packagekit
Loading mirror speeds
from cached hostfile
*
base:
mirrors.hns.net.in
*
epel:
mirror.nus.edu.sg
*
extras:
mirrors.hns.net.in
*
rpmfusion-free-updates:
mirrors.ustc.edu.cn
*
rpmfusion-nonfree-updates:
mirror.de.leaseweb.net
* updates:
mirrors.hns.net.in
Setting
up Install Process
Resolving Dependencies
-->
Running transaction
check
--->
Package nethogs.i686
0:0.8.0-1.el6
will be installed
-->
Finished Dependency
Resolution
Dependencies
Resolved
===========================================================================================================
Package Arch Version Repository Size
===========================================================================================================
Installing:
nethogs i686 0.8.0-1.el6 epel 28
k
Transaction
Summary
===========================================================================================================
Install
1 Package(s)
Total
download size:
28 k
Installed size:
50 k
Downloading
Packages:
nethogs-0.8.0-1.el6.i686.rpm | 28
kB 00:00
Running
rpm_check_debug
Running Transaction Test
Transaction
Test Succeeded
Running Transaction
Installing
: nethogs-0.8.0-1.el6.i686 1/1
Verifying :
nethogs-0.8.0-1.el6.i686 1/1
Installed:
nethogs.i686
0:0.8.0-1.el6
Complete!
|
在Ubuntu, Linux mint和Debian下安裝NetHogs:
鍵入apt-get命令安裝NetHogs包
|
$
sudo apt-get
install nethogs
|
樣例輸出
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
tecmint@tecmint:~$
sudo apt-get
install nethogs
[sudo]
password for
tecmint:
Reading package
lists...
Done
Building
dependency tree
Reading state information...
Done
The
following NEW
packages will
be installed:
nethogs
0
upgraded,
1 newly
installed,
0 to
remove and
318 not
upgraded.
Need to
get 27.1
kB of archives.
After
this operation,
100 kB
of additional
disk space will
be used.
Get:1
http://in.archive.ubuntu.com/ubuntu/ quantal/universe nethogs i386 0.8.0-1 [27.1 kB]
Fetched
27.1 kB
in 1s
(19.8
kB/s)
Selecting previously
unselected package
nethogs.
(Reading
database ...
216058 files
and directories
currently installed.)
Unpacking nethogs
(from
.../nethogs_0.8.0-1_i386.deb)
...
Processing
triggers for
man-db
...
Setting up nethogs
(0.8.0-1)
...
|
NetHogs用法
在基於RedHat系統下鍵入如下命令啓動NetHogs工具.
要執行NetHogs你必須擁有root權限,即如圖所示用sudo命令
樣例預覽:
CentOS 6.3 下的NetHogs預覽
Ubuntu 12.10 下的NetHogs預覽
正如上圖所示, send列和received列顯示的是按照每個進程的流量統計.總的收發數據帶寬在最下方,而且可以用交互命令控制排序,下面將要討論這些交互命令:
NetHogs 命令行參數
以下就是NetHogs命令行的參數,用’-d’來添加刷新頻率參數,’device name’ 用來檢測給定的某個或者某些設備的帶寬(默認是eth0).例如:設置5秒鐘的刷新頻率,鍵入如下命令即可:
如果只用來監視設備(eth0)的網絡帶寬可以使用如下命令:
如果要同時監視eth0和eth1接口,使用以下命令即可:
其他參數和用法
|
-d
: delay
for refresh
rate.
-h
: display
available commands
usage.
-p
: sniff
in promiscious
mode (not
recommended).
-t
: tracemode.
-V
: prints
Version info.
|
NetHogs 交互控制
以下是NetHogs的一些很有用的交互控制(鍵盤快捷鍵)
|
-m
: Change
the units displayed
for the
bandwidth in
units like KB/sec
-> KB
-> B->
MB.
-r
: Sort
by magnitude of
respectively traffic.
-s
: Sort
by magnitude of
sent traffic.
-q
: Hit
quit to
the shell prompt.
|
想要NetHogs命令行工具的完整參數列表請參考NetHogs的手冊,使用方法是在終端裏輸入‘man nethogs‘ 或者 ‘sudo man nethogs‘,更多信息請參考NetHogs項目主頁.
原文鏈接:
Ravi Saive 翻譯:
極客範 -
LQ
譯文鏈接:
http://www.geekfan.net/8019/
[
轉載請保留原文出處、譯者和譯文鏈接。]