Home Microsoft How To Install vnstat on CentOS To View Bandwidth Traffic Statistics

How To Install vnstat on CentOS To View Bandwidth Traffic Statistics


Because many VPS or servers are limited to traffic, but many service providers do not provide detailed information on the total use of the bandwidth, such as daily flow tables, so some people are sure to wonder how much traffic their servers have run.

vnstat is a very useful server traffic statistics command.

Is it intuitive? Let’s take a look at how to use this command. estimated means the estimated usage. The last column avg. Rate is the average bandwidth used.

rx is the received traffic (inbound), tx is the sent traffic (outbound)

Official website:
vnStat- https : //humdi.net/vnstat/
GitHub- https : //github.com/vergoh/vnstat

Step 1: Install

CentOS need to install peel-release before it can be installed using yum
yum install epel-release -y && yum install -y vnstat
For ubuntu, it should be apt-get directly, I have not tried it.

Step 2: Create a monitoring database

vnstat -u -i eth0
Here eth0 can be changed to the network card you need

Step 3: Start the service and set the boot

service vnstat start
chkconfig vnstat on

Step 4: Traffic viewing command

After completing all the above operations, you can see the data with the command in about 10 minutes

Look at the daily traffic statistics command:
vnstat -d

Look at the monthly traffic statistics command:
vnstat -m

Known issues in CentOS: vnstat after installation does not display data, prompt eth0:. Not enough data available yet

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

Compile and install method (Do not perform this step again if you have already installed it with yum or apt-get)

Compile and install vnstat

Download the vnstat:

wget https://humdi.net/vnstat/vnstat-2.3.tar.gz


tar xvzf vnstat-2.3.tar.gz

into the directory:

cd vnstat-2.3 /

compile and install:

./configure- prefix = / usr --sysconfdir = / etc && make && make install

In this way, vnstat is installed. Next, you need to set vnstat (if it is yum or apt-get installed vnstat does not need the following settings).

CentOS / Fedora / RHEL executes the command:

cp examples/init.d/centos/vnstat /etc/init.d/ && chmod +x /etc/init.d/vnstat && chkconfig --add vnstat && chkconfig vnstat on

Debian / Ubuntu execute command:

cp examples/init.d/debian/vnstat /etc/init.d/ && chmod +x /etc/init.d/vnstat && update-rc.d vnstat enable

Start the vnstat daemon:

/etc/init.d/vnstat start

If you use the compile and install method, there will be a bug, which occasionally stops counting traffic, especially under CentOS. When the traffic database is large, there will often be bugs. Here we recommend using source installation.

Compile and install the settings of vnstat.
vnstat basically uses commands:
vnstat -i eth0 -l # Real-time traffic status
vnstat -i eth0 -h #Query traffic status by hour
vnstat -i eth0 -d #Query traffic status by day number
vnstat -i eth0 -m #Query by month number Traffic status
vnstat -i eth0 -w #Query traffic status by week number
vnstat -i eth0 -t #Query TOP10 traffic status

More command help information can be viewed with vnstat –help.

PS. Local test finds that there is an error

Warning: popen() has been disabled for security reasons in /home/wwwroot/default/vnstat/vnstat.php on line 111

Is it mainly php.inidisabled popenor enabled this function

Now it can be displayed normally

vnstat PHP

download the latest version of vnstat PHP frontend

Github address: https://github.com/bjd/vnstat-php-frontend

Address: http://soft.vpser.net/status/vnstat/vnstat_php_frontend-1.5.1.tar.gz

Unzip the file, rename it to vnstat, and then upload it to the root directory of a website, so that it can be accessed by http://en.wtf/vnstat, and the page comes out.

It is described in config.php in the vnstat_php_frontend-1.5.1.tar.gz package.

Finally, edit the file vnstat/config.php and change the data directory to /var/lib/vnstat/. If this directory does not exist, you need to create this directory using

mkdir -p /var/lib/vnstat/

That is:

$data_dir = '/var/lib/vnstat/';<code>

Specify the display title

$iface_title['eth0'] = 'Your-VPS-Name';

The image format displayed below can be svg or png. Generally, you can choose png. Svg needs to install a plug-in under IE, but Firefox does not. If you use png, it can be displayed directly in IE and Firefox.


Specify the installation directory of vnstat. If you are installing the above method, just fill in the following.

$vnstat_bin = '/usr/bin/vnstat';

Specify 1 network card to be monitored:

// list of network interfaces monitored by vnStat
//$iface_list = array('eth0', 'eth1', 'sixxs');
$iface_list = array('eth0',);

// will be displayed instead
$iface_title['eth0'] = 'Internal';
//$iface_title['eth1'] = 'Internet';
//$iface_title['sixxs'] = 'SixXS IPv6';

Change the language to English: $ language = ‘nl’; Replace nl with en to save.

At the same time modify the vnstat.php in the vnstat website directory to vnstat_dump_delete it.

After all this is done, now visit www.mydomain.com/vnstat/, you will find that there is traffic statistics, and the statistics data is updated every 5 minutes.


Please enter your comment!
Please enter your name here