Vnstat: Difference between revisions

From Leo's Notes
This page was last edited on 14 November 2015, at 08:13.
No edit summary
reorganized information
Line 1: Line 1:
Vnstat is a command line based network usage monitoring tool. It is capable of showing the current network utilization as well as providing historical data.
== Installation ==
== Installation ==
Vnstat should be available through the yum package manager via the EPEL repository.
On Redhat/Fedora based systems, vnstat should be available from the main repository. For older versions of Redhat such as CentOS 6, it is available from the EPEL repository.


=== Installing from Source ===
=== Installing from Source ===
The following instructions will set up vnstat from source and should work for CentOS/ScientificLinux/RHEL linux distributions.  
The following instructions will set up vnstat from source and should work for CentOS/ScientificLinux/RHEL linux distributions.  


<syntaxhighlight lang="bash" line start="1" enclose="div">
{{highlight|lang=bash|code=
wget http://humdi.net/vnstat/vnstat-1.11.tar.gz
wget http://humdi.net/vnstat/vnstat-1.11.tar.gz
tar -xzf vnstat-1.11.tar.gz
tar -xzf vnstat-1.11.tar.gz
Line 16: Line 18:
vnstat -u -i eth0
vnstat -u -i eth0
/etc/init.d/vnstat start
/etc/init.d/vnstat start
</syntaxhighlight>
}}


== Usage ==
== Configuration ==
You do not need to interface with vnstat directly since vnstat will create a cronjob in <code>/etc/cron.d/vnstat</code> which will run <code>/usr/sbin/vnstat.cron</code> as nobody every 5 minutes.
Vnstat makes use of a daemon to record network traffic into databases stored in {{code|/var/lib/vnstat}} as well as a cronjob running at 5 minute intervals defined at {{code|/etc/cron.d/vnstat}}.


Depending on how your network interfaces are named and the number of interfaces you have, you may need to fix or initialize the vnstat database.
By default, vnstat will only monitor eth0. You will need to adjust the {{code|/etc/sysconfig/vnstat}} and {{code|/etc/vnstat.conf}} configuration files accordingly.


=== Initializing Database ===
You will also need to initialize the interface database by running {{code|vnstat -u -i $InterfaceName}}, otherwise the daemon and cronjob will not record any data.
To initialize a database for a specific device:
vnstat -u -i $NetInterface


=== Force Update ===
=== Force Update ===
sudo -u /usr/sbin/vnstat.cron --force
If the cronjob fails for some reason, you may force an update by running:
{{highlight|lang=bash|code=
sudo -u /usr/sbin/vnstat.cron --force
}}
 
== Usage ==
Here are some example uses with vnstat.
 
=== Show Usage by Month ===
{{highlight|lang=bash|code=
vnstat -d
}}
 
== Issues ==
=== Not Enough Data ===
You may get the following error if your interface is not being recorded:
{{highlight|lang=text|code=
enp3s0: Not enough data available yet.
}}


Ensure that the cronjob and daemon is active and running. Check by running {{code|ps -eaf|grep vnstat}}. There should be at least noe vnstat daemon running.





Revision as of 08:13, 14 November 2015

Vnstat is a command line based network usage monitoring tool. It is capable of showing the current network utilization as well as providing historical data.

Installation

On Redhat/Fedora based systems, vnstat should be available from the main repository. For older versions of Redhat such as CentOS 6, it is available from the EPEL repository.

Installing from Source

The following instructions will set up vnstat from source and should work for CentOS/ScientificLinux/RHEL linux distributions.

wget http://humdi.net/vnstat/vnstat-1.11.tar.gz
tar -xzf vnstat-1.11.tar.gz
cd vnstat-1.11
make
make install
vnstat --testkernel
/bin/cp examples/init.d/centos/vnstat /etc/init.d/vnstat
chkconfig --levels 234 --add vnstat
vnstat -u -i eth0
/etc/init.d/vnstat start

Configuration

Vnstat makes use of a daemon to record network traffic into databases stored in /var/lib/vnstat as well as a cronjob running at 5 minute intervals defined at /etc/cron.d/vnstat.

By default, vnstat will only monitor eth0. You will need to adjust the /etc/sysconfig/vnstat and /etc/vnstat.conf configuration files accordingly.

You will also need to initialize the interface database by running vnstat -u -i $InterfaceName, otherwise the daemon and cronjob will not record any data.

Force Update

If the cronjob fails for some reason, you may force an update by running:

sudo -u /usr/sbin/vnstat.cron --force

Usage

Here are some example uses with vnstat.

Show Usage by Month

vnstat -d

Issues

Not Enough Data

You may get the following error if your interface is not being recorded:

enp3s0: Not enough data available yet.

Ensure that the cronjob and daemon is active and running. Check by running ps -eaf. There should be at least noe vnstat daemon running.