NetHogs——Linux下按進程即時統計網路頻寬利用率

來源:互聯網
上載者:User

網上有很多適用於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. # yum install nethogs

範例輸出

  1. [root@tecmint~]# yum -y install nethogs
  2. Loaded plugins:fastest mirror,refresh-packagekit
  3. Loading mirror speeds from cached hostfile
  4. *base: mirrors.hns.net.in
  5. *epel: mirror.nus.edu.sg
  6. *extras: mirrors.hns.net.in
  7. *rpmfusion-free-updates: mirrors.ustc.edu.cn
  8. *rpmfusion-nonfree-updates: mirror.de.leaseweb.net
  9. *updates: mirrors.hns.net.in
  10. Setting up InstallProcess
  11. ResolvingDependencies
  12. -->Running transaction check
  13. --->Package nethogs.i6860:0.8.0-1.el6 will be installed
  14. -->FinishedDependencyResolution
  15. DependenciesResolved
  16. ===========================================================================================================
  17. PackageArchVersionRepositorySize
  18. ===========================================================================================================
  19. Installing:
  20. nethogs i686 0.8.0-1.el6 epel 28k
  21. TransactionSummary
  22. ===========================================================================================================
  23. Install1Package(s)
  24. Total download size:28k
  25. Installed size:50k
  26. DownloadingPackages:
  27. nethogs-0.8.0-1.el6.i686.rpm|28kB00:00
  28. Running rpm_check_debug
  29. RunningTransactionTest
  30. TransactionTestSucceeded
  31. RunningTransaction
  32. Installing:nethogs-0.8.0-1.el6.i6861/1
  33. Verifying:nethogs-0.8.0-1.el6.i6861/1
  34. Installed:
  35. nethogs.i6860:0.8.0-1.el6
  36. Complete!
在Ubuntu, Linux mint和Debian下安裝NetHogs:

鍵入apt-get命令安裝NetHogs包

  1. $ sudo apt-get install nethogs
範例輸出
  1. tecmint@tecmint:~$ sudo apt-get install nethogs
  2. [sudo]password fortecmint:
  3. Readingpackage lists...Done
  4. Building dependency tree
  5. Reading state information...Done
  6. The following NEW packages will be installed:
  7. nethogs
  8. 0 upgraded,1 newly installed,0 to remove and318not upgraded.
  9. Need to get27.1kB of archives.
  10. Afterthis operation,100kB of additional disk space will be used.
  11. Get:1 http://in.archive.ubuntu.com/ubuntu/ quantal/universe nethogs i386 0.8.0-1 [27.1 kB]
  12. Fetched27.1kBin1s(19.8kB/s)
  13. Selecting previously unselected package nethogs.
  14. (Reading database...216058 files and directories currently installed.)
  15. Unpacking nethogs(from.../nethogs_0.8.0-1_i386.deb)...
  16. Processing triggers forman-db...
  17. Setting up nethogs(0.8.0-1)...
NetHogs用法

在基於RedHat系統下鍵入如下命令啟動NetHogs工具.

  1. # nethogs

要執行NetHogs你必須擁有root許可權,即用sudo命令

  1. $ sudo nethogs

範例預覽:

CentOS 6.3 下的NetHogs預覽

Ubuntu 12.10 下的NetHogs預覽

正如所示, send列和received列顯示的是按照每個進程的流量統計.總的收發資料頻寬在最下方,而且可以用互動命令控制排序,下面將要討論這些互動命令:

NetHogs 命令列參數

以下就是NetHogs命令列的參數,用’-d’來添加重新整理頻率參數,`device name` 用來檢測給定的某個或者某些裝置的頻寬(預設是eth0).例如:設定5秒鐘的重新整理頻率,鍵入如下命令即可:

  1. # nethogs -d 5

  1. $ sudo nethogs -d 5

如果只用來監視裝置(eth0)的網路頻寬可以使用如下命令:

  1. # nethogs eth0

  1. $ sudo nethogs eth0

如果要同時監視eth0和eth1介面,使用以下命令即可:

  1. # nethogs eth0 eth1

  1. $ sudo nethogs eth0 eth1

其他參數和用法

  1. -d: delay for refresh rate.
  2. -h: display available commands usage.
  3. -p: sniff in promiscious mode (not recommended).
  4. -t: trace mode.
  5. -V: prints Version info.
NetHogs 互動控制

以下是NetHogs的一些很有用的互動控制(鍵盤快速鍵)

  1. -m:Change the units displayed forthe bandwidth inunits like KB/sec->KB->B->MB.
  2. -r:Sortby magnitude of respectively traffic.
  3. -s:Sortby magnitude of sent traffic.
  4. -q:Hit quit tothe shell prompt.

想要NetHogs命令列工具的完整參數列表請參考NetHogs的手冊,使用方法是在終端裡輸入‘man nethogs‘ 或者 ‘sudo man nethogs‘,更多資訊請參考NetHogs項目首頁.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.