Getting Started with vnStat on Debian 10

vnStat is a console-based network traffic monitor for Linux and BSD that keeps a log of network traffic for the selected interface(s). It uses the network interface statistics provided by the kernel as information source. This means that vnStat won’t actually be sniffing any traffic and also ensures light use of system resources regardless of network traffic rate.

vnStat is perfect for collecting persistent statistics through system reboots, and can provide a usage summary of 5 minute, hourly, daily, monthly, weekly, yearly intervals, as well as displaying the top days of usage in it’s history.

Prerequisites:

• Cloud Server running Debian 10

Step-by-Step:

1) Install the vnstat package:

# sudo apt install vnstat

2) For vnStat to begin capturing data, you need to start the service:

# sudo systemctl start vnstat.service

3) Now let’s make sure vnstat starts on boot automatically:

# sudo systemctl enable vnstat.service

VnStat will now begin capturing data and statistics for traffic on your server’s interfaces. Initially, you won’t be able to get any data reported as vnStat needs to build up some data before it can display it. To display the standard report for vnStat you simply run the following command:

# vnstat

                      rx      /      tx      /     total    /   estimated
 Internet (eth1):
       2020-01     31.90 GiB  /   28.05 GiB  /   59.95 GiB
       2020-02    281.04 MiB  /   99.45 MiB  /  380.49 MiB  /   12.05 GiB
     yesterday      1.23 GiB  /  473.23 MiB  /    1.69 GiB
         today    281.04 MiB  /   99.45 MiB  /  380.49 MiB  /     397 MiB

 Local (eth0):
       2020-01     25.13 GiB  /  116.94 GiB  /  142.07 GiB
       2020-02    234.75 MiB  /    5.03 GiB  /    5.26 GiB  /  170.76 GiB
     yesterday    520.55 MiB  /    2.21 GiB  /    2.72 GiB
         today    234.75 MiB  /    5.03 GiB  /    5.26 GiB  /    5.51 GiB

Additional flags can be appended to the vnstat command to get more specific output of the data. Here are some flags you can use and what they will provide:

      -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                  set list begin date
      -e, --end                    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

      -tr, --traffic [time]        calculate traffic
      -l,  --live [mode]           show transfer rate in real time
      -i,  --iface                 select interface (default: eth0)

Use "--longhelp" or "man vnstat" for complete list of options.

You now have a working installation of vnStat which you can use to monitor your server’s traffic over multiple interfaces.

Leave a Reply

Your email address will not be published. Required fields are marked *