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 makes 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 a 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 the latest available vnstat utility on your Ubuntu server. Continue next command
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 the previous installation command.
sudo service vnstat start
Once you verify the valid installation for utility, then start vnstat service with the above command as it needs to be manually started.
In some cases, 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.
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.
If you look at the above screengrab for 1.60 minutes my network interface eth0 has used:
- 846 Kilobytes of the inbound traffic request with 12 kbit/s min and 192 kbit/s max
- 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.
The output will be something like:
The vnstat supports a few other command options discussed further in the 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 the descriptor for each option.
Here is the list of command options supported for vnstat:
|-t,||–top10||show top 10 days|
|-s,||–short||use short output|
|-i,||–iface||select interface (default: eth0)|
|-ru,||–rateunit||swap configured rate unit|
|-l,||–live||show transfer rate in real-time|
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:
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: Check usage and estimate bill, then feel free to drop in below comment box. Also, please subscribe to our restoreBin YouTube channel for amazing videos tips. Cheers!