Server bandwidth network traffic: How to check usage and estimate billing?

Using the command line - vnStat, you can monitor the total server bandwidth and network traffic usage for any Linux or BSD web server. It also provides the estimate for the month and usage history till date.

Earlier I used to struggle a lot to understand and monitor the server bandwidth and network traffic usage for my DigitalOcean server. Now they have added the feature to view the bandwidth usage in their billing section.

But this was when the bandwidth usage was not available anywhere in their console, and I wanted to know what is my exact usage and whether I am surpassing the network usage. However, I feel sharing this Ubuntu command still make sense in case if you’ve any other cloud hosting server apart from DigitalOcean who does not share the network traffic and bandwidth usage.

I did research and a lot of trial runs to find out the best Ubuntu service app that will help in not only share the real-time stats but provide an estimate of my usage, and also maintain the historical usage info. Then I stumbled upon the vnstat command.

What is VNSTAT?

According to their developer source

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 an information source. This means that vnStat won’t actually be sniffing any traffic and also ensures light use of system resources.

Like it says, the vnstat actually source the information from the kernel and doesn’t actually track the inbound or outgoing traffic at the network level. This makes it lighter app service that doesn’t consume any background core or processing. Cool, isn’t it?

How to install vnStat via terminal?

vnStat is supported by Linux and BSD based open source operating system. You can easily install it on Ubuntu, CentOS, Debian, and various other operating systems. For Ubuntu, you can follow below command lines:

sudo apt-get install vnstat

The above command will automatically download and install latest available vnstat utility on your Ubuntu server. Continue next command

vnstat

After installation, the above command will verify if the vnstat is correctly installed or not. If you are watching any error like command ‘vnstat’ not found, then try rebooting your server and install again with previous installation command.

sudo service vnstat start

Once you verify the valid installation for utility, then start vnstat service with above command as it needs to be manually started.

In some case, the utility program is autostarted with running the above command. But, there is no harm in hitting the command again and again.

Monitor server bandwidth usage with the command line

The vnStat utility starts monitoring network traffic from the day or time it’s installed in the system. In order to begin with basics, simply type and hit the below command for initialization.

vnstat -l

OR

vnstat -live

The command will start displaying the live traffic on your network interface with inbound and outbound traffic details in real-time. In order to stop, hit CTRL+C on your machine and it will show the summary of live traffic.  vnstat live traffic summary stats

If you look at the above screengrab for 1.60 minutes my network interface eth0 has used:

  1. 846 Kilobytes of the inbound traffic request with 12 kbit/s min and 192 kbit/s max
  2. 16.59 Megabytes of outbound traffic response with 1.45 Mbit/s average

After a day or two, you should hit the below command in terminal to get the daily, monthly and total server bandwidth usage along with the estimate for day and month.

vnstat

The output will be something like:

plain vnstat command in terminal output

The vnstat supports a few other command options discussed further in next heading, but I guess these two commands will suffice most of the needs.

List of command options in the vnStat monitor

If you hit the command vnstat --help in the Ubuntu terminal, you will have the complete supported option list along with descriptor for each option.

Here is the list of command options supported for vnstat:

-q, –query query database
-h, –hours show hours
-d, –days show days
-m, –months show months
-w, –weeks show weeks
-t, –top10 show top 10 days
-s, –short use short output
-u, –update update database
-i, –iface select interface (default: eth0)
-?, –help short help
-v, –version show version
-tr, –traffic calculate traffic
-ru, –rateunit swap configured rate unit
-l, –live show transfer rate in real time

vnstat command for server bandwidth and traffic monitor

If you’re interested in exploring other long options, type vnstat --longhelp command for additional help.

Why I like vnStat compared to other services?

Short answer — it is light but robust, and fully satisfies my needs for being network traffic monitor. It like an on-the-go service that helps in providing real-time traffic usage on your network node. I especially like the hour command: vnstat -h the help in plotting the network traffic over the period of a day. It looks like below screenshot:

vnstat hourgraph plotting using -hour command option

Conclusion

I’d recommend using the vnStat program for your Linux or Ubuntu based online server to monitor the server bandwidth and network traffic usage without worries.

You can actually cross-validate the usage billing from your cloud host or VPS provider with vnStat data. No sudden shocks!

If you've any thoughts on Server bandwidth network traffic: How to check usage and estimate billing?, then feel free to drop in below comment box. Also, please subscribe to our restoreBin YouTube channel for amazing videos tips. Cheers!

Share

Leave a Reply

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