Monitor Monthly Bandwidth Usage in Linux

As a server owner, it's important to keep track of your network usage over time. Many hosting providers will charge for bandwidth, so you'll want to keep on monitoring your month-to-month usage.

There are plenty of bandwidth monitoring tools out there---most real-time monitoring tools like

htop

and

glances

will show Rx (received) and Tx (transmitted) out. However, it's much more useful to look at daily and monthly averages and to do that, you'll need a tool that can keep logs over time.

Install vnstat

As for a generic Linux solution, though, you'll want to install vnstat.

The vnstat monitors all network interfaces and keeps logs on how much traffic your servers are handling, which can be used to present monthly, daily, and hourly averages of traffic. It also has the option of outputting to a PNG for a better-looking graph.

The vnstat is available from most main package managers. For Debian-based systems like Ubuntu, that would be:

sudo apt install vnstat

You'll also want to install vnstati for image output:

sudo apt install vnstati

If it isn't available on your package manager, you can download it from source https://humdi.net/vnstat/, and use make to build it for your system.

The vnstat will immediately start collecting data, but it will take a while for enough data to be collected actually to present anything. Come back to it in a few hours once it's collected some data, and run vnstat to view its output:

vnstat

This shows received GiB (RX), and transmitted GiB (TX), as well as a total and an estimate based on prior usage if the logs are incomplete. Keep in mind that this is in Gibibytes, not Gigabytes, though the difference isn't as much as the much smaller Gigabits.

If you want more detailed output, you can output hourly:

vnstat -h

To output an image summary, you can use the following command (-s for summary), replacing eth0 with whatever network device you want to view:

vnstati -s -i eth0 -o ~/network-log.png

You can also view hourly output in the same fashion.

vnstati -h -i eth0 -o ~/network-log.png

If you'd like to do a more in-depth analysis or send these logs off somewhere else, you can output all of vnstat's logs with the --json flag.

 

 

  • How to Monitor Monthly Bandwidth Usage in Linux, Monitor Monthly Bandwidth Usage in Linux, Monthly Bandwidth Usage in Linux, Monthly Bandwidth Usage
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Access your Folders(Linux/Centos) using WinSCP

Guide on how to access the folders in your vps linux! This is the easiest way, First make sure...

How to traceroute your VPS IP?

How to Use the Traceroute Command Traceroute is a command which can show you the path a...

Command line bandwidth monitors for Linux

If you are a Sysadmin, monitoring bandwidth usage on your server is an important task. We agree...

Check the RAM Usage in Linux

1. Login to your VPS using Putty. 2. Type: free -m

How to do “mysqladmin flush-hosts” on VPS server?

How to fix this error "MySQL Database Error: Host '127.0.0.1' blocked because of many...