Mac vnstat流量统计命令

 

1、安装

➜ brew install vnstat

Updating Homebrew...

^C
==> Downloading https://homebrew.bintray.com/bottles/gd-2.3.0.big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/57db02960b120179fcd18257989a043f6d6f82212dde034e6efeffd9ec75434a?response-content-disposition=attachment%3Bfilename%3D%22gd-2.3.0.b
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/vnstat-2.6.big_sur.bottle.tar.gz
######################################################################## 100.0%
==> Installing dependencies for vnstat: gd
==> Installing vnstat dependency: gd
==> Pouring gd-2.3.0.big_sur.bottle.tar.gz
🍺  /usr/local/Cellar/gd/2.3.0: 34 files, 1.4MB
==> Installing vnstat
==> Pouring vnstat-2.6.big_sur.bottle.tar.gz
==> Caveats
To monitor interfaces other than "en0" edit /usr/local/etc/vnstat.conf

To have launchd start vnstat now and restart at startup:
  sudo brew services start vnstat
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/vnstat/bin/vnstatd --nodaemon --config /usr/local/etc/vnstat.conf
==> Summary
🍺  /usr/local/Cellar/vnstat/2.6: 14 files, 489.6KB
==> Caveats
==> vnstat
To monitor interfaces other than "en0" edit /usr/local/etc/vnstat.conf

To have launchd start vnstat now and restart at startup:
  sudo brew services start vnstat
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/vnstat/bin/vnstatd --nodaemon --config /usr/local/etc/vnstat.conf

2、服务启动

➜  burp2.0 brew services start vnstat
Warning: vnstat must be run as root to start at system startup!
==> Successfully started `vnstat` (label: homebrew.mxcl.vnstat)

3、使用参数

➜  burp2.0 vnstat --longhelp
vnStat 2.6 by Teemu Toivola <tst at iki dot fi>

Query:
      -q,  --query                 query database
      -s,  --short                 use short output
      -5,  --fiveminutes [limit]   show 5 minutes
      -h,  --hours [limit]         show hours
      -hg, --hoursgraph            show hours graph
      -d,  --days [limit]          show days
      -m,  --months [limit]        show months
      -y,  --years [limit]         show years
      -t,  --top [limit]           show top days
      -b,  --begin <date>          set list begin date
      -e,  --end <date>            set list end date
      --oneline [mode]             show simple parsable format
      --json [mode] [limit]        show database in json format
      --xml [mode] [limit]         show database in xml format

Modify:
      --add                        add interface to database
      --remove                     remove interface from database
      --rename <name>              rename interface in database
      --setalias <alias>           set alias for interface

Misc:
      -i,  --iface <interface>     select interface
      -?,  --help                  show short help
      -D,  --debug                 show some additional debug information
      -v,  --version               show version
      -tr, --traffic [time]        calculate traffic
      -l,  --live [mode]           show transfer rate in real time
      -ru, --rateunit [mode]       swap configured rate unit
      --limit <limit>              set output entry limit
      --style <mode>               select output style (0-4)
      --iflist                     show list of available interfaces
      --dbdir <directory>          select database directory
      --locale <locale>            set locale
      --config <config file>       select config file
      --showconfig                 dump config file with current settings
      --longhelp                   show this help

See also "man vnstat" for longer descriptions of each option.

4、常用

5分钟内,如果时间不够5分钟,则没有办法输出结果。会提示“Not enough data available yet.”

➜  vnstat -5

 en0  /  5 minute

         time        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     2021-04-29
         14:45      8.25 MiB |    1.56 MiB |    9.81 MiB |  274.35 kbit/s
         14:50     34.49 MiB |    3.29 MiB |   37.79 MiB |    1.06 Mbit/s
     ------------------------+-------------+-------------+---------------

 

posted @ 2021-04-29 15:00  JeromePowell  阅读(403)  评论(0编辑  收藏  举报