參考    http://os.51cto.com/art/201404/435279.htm

 

   網卡流量監控工具可以監控通過網絡接口傳輸的數據,並測量目前哪些數據所傳輸的速度。入站流量和出站流量分開來顯示。一些命令可以顯示單個進程所使用的帶寬。這樣一來,用户很容易發現過度使用網絡帶寬的某個進程。這些工具使用不同的機制來製作流量報告。nload等一些工具可以讀取"proc/net/dev"文件,以獲得流量統計信息;而一些工具使用pcap庫來捕獲所有數據包,然後計算總數據量,從而估計流量負載。

  按功能劃分的命令名稱。

  • 監控總體帶寬使用――nload、bmon、slurm、bwm-ng、cbm、speedometer和netload
  • 監控總體帶寬使用(批量式輸出)――vnstat、ifstat、dstat和collectl
  • 每個套接字連接的帶寬使用――iftop、iptraf、tcptrack、pktstat、netwatch和trafshow
  • 每個進程的帶寬使用――nethogs

 

ntop和darkstat是面向Linux系統的其中兩個基本的基於Web的網絡監控工具。除此之外還有企業級監控工具,比如nagios,它們提供了一批功能特性,不僅僅可以監控服務器,還能監控整個基礎設施。

nload

      nload是一個命令行工具,讓用户可以分開來監控入站流量和出站流量。它還可以繪製圖表以顯示入站流量和出站流量,視圖比例可以調整。用起來很簡單,不支持許多選項。

適用:只需要快速查看總帶寬使用情況,無需每個進程的詳細情況。

 



nload version 0.7.4
Copyright (C) 2001 - 2012 by Roland Riegel <feedback@roland-riegel.de>
nload comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
welcome to redistribute it under certain conditions. For more details see the
GNU General Public License Version 2 (http://www.gnu.org/copyleft/gpl.html).

Command line syntax:
nload [options] [devices]
nload --help|-h

Options:
-a period       Sets the length in seconds of the time window for average
                calculation.
                Default is 300.
-i max_scaling  Specifies the 100% mark in kBit/s of the graph indicating the
                incoming bandwidth usage. Ignored if max_scaling is 0 or the
                switch -m is given.
                Default is 10240.
-m              Show multiple devices at a time; no traffic graphs.
-o max_scaling  Same as -i but for the graph indicating the outgoing bandwidth
                usage.
                Default is 10240.
-t interval     Determines the refresh interval of the display in milliseconds.
                Default is 500.
-u h|b|k|m|g    Sets the type of unit used for the display of traffic numbers.
   H|B|K|M|G    h: auto, b: Bit/s, k: kBit/s, m: MBit/s etc.
                H: auto, B: Byte/s, K: kByte/s, M: MByte/s etc.
                Default is h.
-U h|b|k|m|g    Same as -u, but for a total amount of data (without "/s").
   H|B|K|M|G    Default is H.
devices         Network devices to use.
                Default is to use all auto-detected devices.
--help
-h              Print this help.

example: nload -t 200 -i 1024 -o 128 -U M

The options above can also be changed at run time by pressing the 'F2' key.



 

iftop

     iftop可測量通過每一個套接字連接傳輸的數據;它採用的工作方式有別於nload。iftop使用pcap庫來捕獲進出網絡適配器的數據包,然後彙總數據包大小和數量,搞清楚總的帶寬使用情況。

雖然iftop報告每個連接所使用的帶寬,但它無法報告參與某個套按字連接的進程名稱/編號(ID)。不過由於基於pcap庫,iftop能夠過濾流量,並報告由過濾器指定的所選定主機連接的帶寬使用情況。

 



iftop: display bandwidth usage on an interface by host

Synopsis: iftop -h | [-npbBP] [-i interface] [-f filter code] [-N net/mask]

   -h                  display this message
   -n                  don't do hostname lookups
   -N                  don't convert port numbers to services
   -p                  run in promiscuous mode (show traffic between other
                       hosts on the same network segment)
   -b                  don't display a bar graph of traffic
   -B                  Display bandwidth in bytes
   -i interface        listen on named interface
   -f filter code      use filter code to select packets to count
                       (default: none, but only IP packets are counted)
   -F net/mask         show traffic flows in/out of network
   -P                  show ports as well as hosts
   -m limit            sets the upper limit for the bandwidth scale
   -c config file      specifies an alternative configuration file

iftop, version 0.17
copyright (c) 2002 Paul Warren <pdw@ex-parrot.com> and contributors



 

 

iptraf

iptraf是一款交互式、色彩鮮豔的IP局域網監控工具。它可以顯示每個連接以及主機之間傳輸的數據量。 iptraf的安裝需要預先安裝linux內核開發包,iptraf需要引用其中的net下的頭文件

 

 

 

nethogs

    nethogs是一款小巧的"net top"工具,可以顯示每個進程所使用的帶寬,並對列表排序,將耗用帶寬最多的進程排在最上面。萬一出現帶寬使用突然激增的情況,用户迅速打開nethogs,就可以找到導致帶寬使用激增的進程。nethogs可以報告程序的進程編號(PID)、用户和路徑。



[root@s3 nethogs]# nethogs -h
usage: nethogs [-V] [-b] [-d seconds] [-t] [-p] [device [device [device ...]]]
        -V : prints version.
        -d : delay for update refresh rate in seconds. default is 1.
        -t : tracemode.
        -b : bughunt mode - implies tracemode.
        -p : sniff in promiscious mode (not recommended).
        device : device(s) to monitor. default is eth0

When nethogs is running, press:
 q: quit
 m: switch between total and kb/s mode



 

bmon

    bmon(帶寬監控器)是一款類似nload的工具,它可以顯示系統上所有網絡接口的流量負載。輸出結果還含有圖表和剖面,附有數據包層面的詳細信息。bmon支持許多選項,能夠製作HTML格式的報告。欲知更多信息

詳見:http://lintut.com/bmon-real-time-bandwidth-monitoring-tool-for-linux/

slurm

    slurm是另一款網絡負載監控器,可以顯示設備的統計信息,還能顯示ASCII圖形。它支持三種不同類型的圖形,使用c鍵、s鍵和l鍵即可激活每種圖形。slurm功能簡單,無法顯示關於網絡負載的任何更進一步的詳細信息。

 

tcptrack

tcptrack類似iftop,使用pcap庫來捕獲數據包,並計算各種統計信息,比如每個連接所使用的帶寬。它還支持標準的pcap過濾器,這些過濾器可用來監控特定的連接。

 

 

vnstat

    vnstat更像是一款製作歷史報告的工具,顯示每天或過去一個月使用了多少帶寬。它並不是嚴格意義上的實時監控網絡的工具。vnstat與另外大多數工具有點不一樣。它實際上運行後台服務/守護進程,始終不停地記錄所傳輸數據的大小。之外,它可以用來製作顯示網絡使用歷史情況的報告。

    運行沒有任何選項的vnstat,只會顯示自守護進程運行以來所傳輸的數據總量。
    想實時監控帶寬使用情況,請使用"-l"選項(實時模式)。然後,它會顯示入站數據和出站數據所使用的總帶寬量,但非常精確地顯示,沒有關於主機連接或進程的任何內部詳細信息。

 

bwm-ng

bwm-ng(下一代帶寬監控器)是另一款非常簡單的實時網絡負載監控工具,可以報告摘要信息,顯示進出系統上所有可用網絡接口的不同數據的傳輸速度。如果控制枱足夠大,bwm-ng還能使用curses2輸出模式,為流量繪製條形圖。

 

speedometer

這是另一款小巧而簡單的工具,僅僅繪製外觀漂亮的圖形,顯示通過某個接口傳輸的入站流量和出站流量。

 

pktstat

pktstat可以實時顯示所有活動連接,並顯示哪些數據通過這些活動連接傳輸的速度。它還可以顯示連接類型,比如TCP連接或UDP連接;如果涉及HTTP連接,還會顯示關於HTTP請求的詳細信息。

 

netwatch

netwatch是netdiag工具庫的一部分,它也可以顯示本地主機與其他遠程主機之間的連接,並顯示哪些數據在每個連接上所傳輸的速度。

 

trafshow

與netwatch和pktstat一樣,trafshow也可以報告當前活動連接、它們使用的協議以及每條連接上的數據傳輸速度。它能使用pcap類型過濾器,對連接進行過濾。

 

netload

netload命令只顯示關於當前流量負載的一份簡短報告,並顯示自程序啓動以來所傳輸的總字節量。沒有更多的功能特性。它是netdiag的一部分。

 

ifstat

ifstat能夠以批處理式模式顯示網絡帶寬。輸出採用的一種格式便於用户使用其他程序或實用工具來記入日誌和分析。



[root@s3 bmon-3.9]# ifstat -h
Usage: ifstat [OPTION] [ PATTERN [ PATTERN ] ]
   -h, --help        this message
   -a, --ignore    ignore history
   -d, --scan=SECS    sample every statistics every SECS
   -e, --errors    show errors
   -n, --nooutput    do history only
   -r, --reset        reset history
   -s, --noupdate    don;t update history
   -t, --interval=SECS    report average over the last SECS
   -V, --version    output version information
   -z, --zeros        show entries with zero activity



 

dstat

dstat是一款用途廣泛的工具(用python語言編寫),它可以監控系統的不同統計信息,並使用批處理模式來報告,或者將相關數據記入到CSV或類似的文件。這個例子顯示瞭如何使用dstat來報告網絡帶寬。



[root@s3 bmon-3.9]# dstat -h
Usage: dstat [-afv] [options..] [delay [count]]
Versatile tool for generating system resource statistics

Dstat options:
  -c, --cpu              enable cpu stats
     -C 0,3,total           include cpu0, cpu3 and total
  -d, --disk             enable disk stats
     -D total,hda           include hda and total
  -g, --page             enable page stats
  -i, --int              enable interrupt stats
     -I 5,eth2              include int5 and interrupt used by eth2
  -l, --load             enable load stats
  -m, --mem              enable memory stats
  -n, --net              enable network stats
     -N eth1,total          include eth1 and total
  -p, --proc             enable process stats
  -r, --io               enable io stats (I/O requests completed)
  -s, --swap             enable swap stats
     -S swap1,total         include swap1 and total
  -t, --time             enable time/date output
  -T, --epoch            enable time counter (seconds since epoch)
  -y, --sys              enable system stats

  --aio                  enable aio stats
  --fs, --filesystem     enable fs stats
  --ipc                  enable ipc stats
  --lock                 enable lock stats
  --raw                  enable raw stats
  --socket               enable socket stats
  --tcp                  enable tcp stats
  --udp                  enable udp stats
  --unix                 enable unix stats
  --vm                   enable vm stats

  --plugin-name          enable plugins by plugin name (see manual)
  --list                 list all available plugins

  -a, --all              equals -cdngy (default)
  -f, --full             automatically expand -C, -D, -I, -N and -S lists
  -v, --vmstat           equals -pmgdsc -D total

  --bits                 force bits for values expressed in bytes
  --float                force float values on screen
  --integer              force integer values on screen

  --bw, --blackonwhite   change colors for white background terminal
  --nocolor              disable colors (implies --noupdate)
  --noheaders            disable repetitive headers
  --noupdate             disable intermediate updates
  --output file          write CSV output to file
  --profile              show profiling statistics when exiting dstat

delay is the delay in seconds between each update (default: 1)
count is the number of updates to display before exiting (default: unlimited)



 

collectl

collectl以一種類似dstat的格式報告系統的統計信息;與dstat一樣,它也收集關於系統不同資源(如處理器、內存和網絡等)的統計信息。這裏給出的一個簡單例子顯示瞭如何使用collectl來報告網絡使用/帶寬。