Bobcares

WeSupport

Call Us! 1-800-383-5193
Call Us! 1-800-383-5193
Call Us! 1-800-383-5193

Need Help?

Emergency Response Time custom

Our experts have had an average response time of 12.24 minutes in February 2021 to fix urgent issues.

We will keep your servers stable, secure and fast at all times for one fixed price.

How to install vnStat in Linux to monitor network traffic

by | Mar 5, 2021

Are you looking for steps to install vnStat in Linux? We can help you with it.

Recently, we received a request from one of the customers to install vnStat as he wished to monitor the network traffic.

vnStat is a console-based network traffic monitoring tool design for Linux and BSD. It will keep a log of the network traffic for selected network interfaces.

Here at Bobcares, we have seen several such Linux-related installations as part of our Server Management Services for web hosts and online service providers.

Today we’ll see how to install vnStat on Linux.

 

How to install vnStat in Linux

Now let’s take a look at how our Support Engineers install the vnStat in Linux.

1. First, we download the vnStat latest version from its official GitHub release page.

https://github.com/vergoh/vnstat/releases

2. After downloading it, we extract the archive and navigate to the location where we have extracted the archive and compile it using the following commands.

Install VnStat in CentOS/RHEL and Fedora

# yum group install “Development Tools”
# yum install gd gd-devel sqlite-devel
# tar -xvf vnstat-2.6.tar.gz
# cd vnstat-2.6/
# ./configure –prefix=/usr –sysconfdir=/etc
# make
# make install

Install VnStat in Debian and Ubuntu

$ sudo apt-get install build-essential gd gd-devel libsqlite3-dev
$ tar -xvf vnstat-2.6.tar.gz
$ cd vnstat-2.6/
$ sudo ./configure –prefix=/usr –sysconfdir=/etc
$ sudo make
$ sudo make install

3. Once the installation completes, we copy the vnStat service file.

VnStat Systemd

# cp -v examples/systemd/vnstat.service /etc/systemd/system/
# systemctl enable vnstat
# systemctl start vnstat

Vnstat Init.d

# cp -v examples/init.d/redhat/vnstat /etc/init.d/
# chkconfig vnstat on
# service vnstat start

4. Now, we verify that the binaries got installed to a suitable location and are of the correct version.

# vnstat

5. If we wish to customize vnStat configuration, open its configuration file located at:

# vi /etc/vnstat.conf

6. Then we allow some time for the stats to upload to the database. After having enough information written in the database, we can see the network stats by running the below command.

# vnstat

7. Also, we can check the hourly stats by using the -h option:

# vnstat -h

8. For daily stats, we can use the -d option:

# vnstat -d

9. For more available options, we can use the –help:

# vnstat –help

 

Some common errors relating to vnStat

Now let’s take a look at some of the common errors our Support Engineers resolved for our customers.

 

1. No such file or directory

error: linux/errno.h: No such file or directory
make[1]: *** [vnstat.o] Error 1
make[1]: Leaving directory `/home/vnstat-1.10/src’
make: *** [vnstat] Error 2

Cause:

Kernel headers package is missing

Solution:

Install kernel-headers package

To install kernel-headers in Ubuntu/Debian:

First, we check the kernel version as well as kernel header package that matches the kernel version using following commands.

$ uname -r
$ apt search linux-headers-$(uname -r)

On Debian/Ubuntu and their derivatives, all kernel header files can be found under /usr/src directory. By running the below command, we can check if the matching kernel headers for kernel version are already installed on the system.

$ ls -l /usr/src/linux-headers-$(uname -r)

We update the packages before installing the appropriate kernel headers. We do this to grab information about the latest package releases, using the following command.

$ sudo apt update

Then we run the below command to install the Linux Kernel headers package for our kernel version.

$ sudo apt install linux-headers-$(uname -r)

After that, we check if the matching kernel headers have been installed on the system.

To install kernel-headers in CentOS 7:

First, we confirm that the matching kernel headers are already installed under /usr/src/kernels/ location on the system using the following commands.

# cd /usr/src/kernels/
# ls -l

If no matching kernel headers are located in the /usr/src/kernels/ directory, we install kernel headers. For that, we run the below commands.

# yum install kernel-devel [On CentOS/RHEL 7]
# dnf install kernel-devel [On Fedora 22+]

After the installation, we can find all the kernel headers files in /usr/src/kernels directory using following command.

# ls -l /usr/src/kernels/$(uname -r)

In VPS, a kernel may have a customized version name, in such scenario, we have to identify the kernel version manually and check the installed kernel header files using following commands.

# uname -r
# ls -l /usr/src/kernels/3.10.0-862.2.3.el7.x86_64

Additionally, if we need header files for the Linux kernel for use by glibc, install the kernel-header package using following command.

# yum install kernel-headers [On CentOS/RHEL 7]
# dnf install kernel-headers [On Fedora 22+]

 

2. vnStat not updating

After installing vnStat, the database never updates.

Causes

* /var/lib/vnstat having wrong ownership
* Database not created

Solution

* To fix the improper ownership of /var/lib/vnstat, we run:

$ sudo chown -R vnstat:vnstat /var/lib/vnstat

Then we make sure that the following files are present in that folder and have proper ownership.

bob@server:/var/lib/vnstat$ ls -la
total 16
drwxr-xrwx 2 vnstat vnstat 4096 May 16 01:50 .
drwxr-xr-x 78 root root 4096 Jul 22 15:14 ..
-rw-r–rwx 1 vnstat vnstat 2792 Jul 26 00:26 eth0
-rw-rw-r– 1 vnstat vnstat 2792 Jul 26 00:26 .eth0

.eth0 is temp file, that may disappear sometimes.

After installing vnStat, we need to create a database. To create the database, we can use the update switch, which creates a new database in the base of no database.

$ sudo vnstat -i eth0 -u

where eth0 is the name of the network interface.

Then we can view the details vnstat -i eth0 or simply vnstat.

In case, if the vnStat is not running then we start the daemon by running the following command and check for the result after 5 minutes.

$ sudo /etc/init.d/vnstat start

Once database have been initialised, its ready to monitor bandwidth usage. We can view the report using the command vnStat.

[Still, not able to install vnStat in Linux? – We are here to help you]

 

Conclusion

Today, we saw how our Support Engineers install and configure vnStat in Linux. Also, we saw some common errors relating to it.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

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

Categories:

Tags: