Vnstat

From SME Server
Jump to navigation Jump to search
PythonIcon.png Skill level: Medium
The instructions on this page require a basic knowledge of linux.


Description

vnStat is a network traffic monitor for Linux that keeps a log of daily network traffic for the selected interface(s). For more information have a look here.

Based on How to install vnstat and the the PHP frontent.
[Original post http://forums.contribs.org/index.php?topic=42444]

Installation

To install vnStat you will need to have the Dag repository configured on your system. If you do not have the repository installed follow this instruction, otherwise skip to the next section:

Configuring Dag repository

The following command will configure the Dag repository on SME Server. EDIT NOT COMPLETE!


To create an entry in the database for the epel repository we open put the following commands in a terminal window or in a shell window:

/sbin/e-smith/db yum_repositories set epel repository \

Name 'SME Server - epel' \
BaseURL 'http://<http://download.fedoraproject.org/pub/epel/7/$basearch' \
EnableGroups yes \
GPGCheck yes \
Visible no \
status disabled

To enable the changes:

    signal-event yum-modify

Just to be sure, give yum a fresh start:

    yum clean all

After adding it to the database we have to update the changes to the configuration file:

signal-event yum-modify

Install vnStat

If you have configured the dag repository, installation is as simple as:

yum install vnstat --enablerepo=dag
signal-event post-upgrade
signal-event reboot

Add the monitored Interfaces

Add the interfaces you would like to monitor:

vnstat -u -i eth0
vnstat -u -i eth1

You should get an error about the database not existing but it will also say it created it. It is safe to ignore the error message.

you also need to edit /etc/sysconfig/vnstat to add your iface to the update job

vim /etc/sysconfig/vnstat
VNSTAT_OPTIONS="-i eth0 -i eth1"

Install vnStat PHP FrontEnd

"...Since vnStat is console mode only I created this script to make a 'nice' report of the data collected by vnStat...." (Read More)

There is no yum repo for this so you will need to go to: http://www.sqweek.com/sqweek/index.php?p=1 to find the latest. Determine the link to the latest release and replace the wget command (below) accordingly.

The below instructions put the file into the Primary ibay, you can also put it in a dedicated ibay or in /opt as suits your needs and security requirements.

Get the frontend and configure:

cd /home/e-smith/files/ibays/Primary/html/
wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.4.1.tar.gz
tar -xvzf vnstat_php_frontend-1.4.1.tar.gz
cd vnstat_php_frontend-1.4.1

nano config.php:
Edit the information about the interfaces you would like to graph:

$iface_list = array('eth0', 'eth1');

The optional names:

$iface_title['eth0'] = 'Internal';
$iface_title['eth1'] = 'Internet';

Finnaly set application path:

$vnstat_bin = 'vnstat';

Wait and you should see the application working at http://yourserverIP/vnstat_php_frontend-1.4.1

Troubleshooting

It is advisable to make the following change (as per user advice here http://forums.contribs.org/index.php/topic,45174.msg218884.html#msg218884)

Edit the vnstat cron file

nano /etc/cron.d/vnstat

Change the line

*/5 * * * * nobody /usr/sbin/vnstat.cron

to read

*/5 * * * * root /usr/sbin/vnstat.cron

Restart crond.

service crond restart

References

http://forums.contribs.org/index.php/topic,45174.0.html

http://forums.contribs.org/index.php/topic,48420.0.html

http://forums.contribs.org/index.php/topic,48422.0.html

http://humdi.net/vnstat/