网卡流量统计工具

参考    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来报告网络使用/带宽。

转载于:https://www.cnblogs.com/blue-sea-sky/p/5707829.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值