網卡流量統計工具

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

 

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

  按功能劃分的命令名稱。linux

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

 

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

nload

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

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

 

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下的頭文件dom

 

 

 

nethogs

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

[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來報告網絡使用/帶寬。

相關文章
相關標籤/搜索