[Linux]流量统计工具vnstat介绍和使用

2021-04-12 2999点热度 0人点赞 1条评论

前言

vnstat是一款很出色的网络流量统计工具,可以方便的统计按小时、天、周、月来统计和预估服务器流量,示例如下:

[root@ubuntu opt]# vnstat
Database updated: 2021-04-12 01:20:00

   eth0 since 2021-04-08

          rx:  9.66 GiB      tx:  8.93 GiB      total:  18.59 GiB

   monthly
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
       2021-04      9.66 GiB |    8.93 GiB |   18.59 GiB |  167.16 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated     26.20 GiB |   24.23 GiB |   50.44 GiB |

   daily
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     yesterday      2.75 GiB |    2.56 GiB |    5.31 GiB |  528.07 kbit/s
         today    594.76 MiB |  569.20 MiB |    1.14 GiB |    2.03 Mbit/s
     ------------------------+-------------+-------------+---------------
     estimated     10.45 GiB |   10.01 GiB |   20.46 GiB |

安装

vnstat的安装比较简单

Ubuntu等系统使用 sudo apt install vnstat来安装

CentOS等系统:

# 如果没有安装过epel-release,需要安装先安装
yum install -y epel-release
# 安装vnstat
yum install -y vnstat

安装好后,设置为开机启动,并使用vnstat查看

# 开机启动
systemctl enable vnstat
# 启动vnstat服务
systemctl start vnstat

# 查看vnstat服务是否正常启动
systemctl status vnstat

# 使用vnstat查看流量统计情况,首次安装后立即执行,可能还没有统计到数据,此时可以等待2分钟后再来查看
vnstat

#查看哪些网卡可以监控
vnstat --iflist

CentOS踩坑避免

在CentOS上发现systemctl status vnstat服务没有起来,具体解决详见我的博客:https://blog.terrynow.com/2021/05/14/centos-vnstat-service-can-not-start-solved/

详细使用参数

vnstat  # 最简单的直接vnstat查看流量统计情况
vnstat --iface eth0 # 如果你有多张网卡,默认vnstat会显示全部接口的统计,想要查看特定接口的,使用--iface
vnstat -l  # 或者 `--live` 实时流量,如果要退出按Control+C
vnstat -h  # 显示小时流量
vnstat -d  # 显示日流量信息
vnstat -w  # 显示周流量信息
vnstat -m  # 显示月流量信息
vnstat -t  # 显示流量最高top10天

 

admin

这个人很懒,什么都没留下

文章评论

  • Auctiob

    Cialis Per Erezione - Cialis Propecia Sirve Si Mwynjh Discount Doryx Drugs Mail Order Slguow - Cialis Buy Propecia Online In Canada

    2022-03-29
  • 您需要 登录 之后才可以评论