Difference between revisions of "Vnstat"

From SME Server
Jump to navigationJump to search
(Add brief description of vnStat, section headings, and categories)
 
(16 intermediate revisions by 10 users not shown)
Line 1: Line 1:
"vnStat is a network traffic monitor for Linux that keeps a log of daily network traffic for the selected interface(s)." ([http://humdi.net/vnstat/ Read more...])
+
{{Level|Medium}}
 +
===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 [http://humdi.net/vnstat/ here].
  
How to install vnstat and the the PHP frontent.<br>
+
Based on How to install vnstat and the the PHP frontent.<br>
 
[Original post http://forums.contribs.org/index.php?topic=42444]<br>
 
[Original post http://forums.contribs.org/index.php?topic=42444]<br>
==Install vnstat==
 
Get vnstat and install:
 
wget http://dag.wieers.com/rpm/packages/vnstat/vnstat-1.4-3.2.el4.rf.i386.rpm
 
yum localinstall vnstat-1.4-3.2.el4.rf.i386.rpm
 
  
 +
===Installation for Koozali SME v10 ===
 +
 +
You need the EPEL repo
 +
yum install smeserver-extrarepositories-epel
 +
 +
Now install vnstat:
 +
yum --enablerepo=epel install vnstat
 +
 +
Next a configuration entry and unit file
 +
config set vnstat service status enabled access private
 +
mkdir -p /usr/lib/systemd/system/vnstat.service.d
 +
nano /usr/lib/systemd/system/vnstat.service.d/50koozali.conf
 +
 +
Paste this and save/exit:
 +
 +
[Unit]
 +
Description=Vnstat global service for Koozali SME Server
 +
 +
[Install]
 +
WantedBy=
 +
WantedBy=sme-server.target
 +
 +
Add service key:
 +
 +
config set vnstat service status enabled access private
 +
 +
And Upgrade/Reboot for good measure:
 +
signal-event post-upgrade
 +
signal-event reboot
 +
 +
Are we running:
 +
 +
systemctl status vnstat
 +
 +
Lets look at the data:
 +
 +
                      rx      /      tx      /    total    /  estimated
 +
eth0:
 +
      Mar '24      4.36 MiB  /  22.12 MiB  /  26.48 MiB  /  40.00 MiB
 +
        today      4.36 MiB  /  22.12 MiB  /  26.48 MiB  /      37 MiB
 +
 +
vnstat --iflist
 +
vnstat -i eth0
 +
 +
By hour/week/month
 +
 +
vnstat -h/w/m -i eth0
 +
 +
eg
 +
 +
vnstat -w -i eth0
 +
 +
Remove unwanted DBs and stop monitoring the interface
 +
vnstat -i dummy0 --delete --force
 +
 +
This could be templated:
 +
cat /etc/vnstat.conf
 +
 +
 +
===Installation for Koozali SME v9 ===
 +
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====
 +
You need to activate the [[Dag]] reposity before installing this contrib.<br />
 +
 +
see [[dag|dag repository]] <br />
 +
 +
====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:
 
Add the interfaces you would like to monitor:
 
  vnstat -u -i eth0
 
  vnstat -u -i eth0
 
  vnstat -u -i eth1
 
  vnstat -u -i eth1
  
(Ignore the error message you get)
+
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="-u"
 +
see http://forums.contribs.org/index.php/topic,45174.0.html
 +
 
 +
===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...." ([http://www.sqweek.com/sqweek/index.php?p=1 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.
  
==Install vnStat PHP FrontEnd==
 
 
Get the frontend and configure:
 
Get the frontend and configure:
 
  cd /home/e-smith/files/ibays/Primary/html/
 
  cd /home/e-smith/files/ibays/Primary/html/
  wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.4.tar.gz
+
  wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.4.1.tar.gz
  tar -xvzf vnstat_php_frontend-1.4.tar.gz
+
  tar -xvzf vnstat_php_frontend-1.4.1.tar.gz
  cd vnstat_php_frontend-1.4
+
  cd vnstat_php_frontend-1.4.1
nano config:<br>
+
nano config.php:<br>
 
Edit the information about the interfaces you would like to graph:
 
Edit the information about the interfaces you would like to graph:
  $iface_list = array('eth0', 'ppp0');
+
  $iface_list = array('eth0', 'eth1');
 
The optional names:  
 
The optional names:  
 
  $iface_title['eth0'] = 'Internal';
 
  $iface_title['eth0'] = 'Internal';
  $iface_title['ppp0'] = 'Internet';
+
  $iface_title['eth1'] = 'Internet';
 
Finnaly set application path:
 
Finnaly set application path:
  $vnstat_bin = '/usr/bin/vnstat';
+
  $vnstat_bin = 'vnstat';
Then change permission on /var/lib/vnstat/* files
+
 
  chmod 666 /var/lib/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
  
Wait and you should see the application working at http://yourserverIP/vnstat_php_frontend-1.4
+
http://humdi.net/vnstat/
  
 
----
 
----
 
[[Category: Howto]]
 
[[Category: Howto]]
[[Category: Administration]]
+
[[Category: Administration:Monitoring]]

Latest revision as of 16:45, 20 March 2024

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 for Koozali SME v10

You need the EPEL repo

yum install smeserver-extrarepositories-epel

Now install vnstat:

yum --enablerepo=epel install vnstat

Next a configuration entry and unit file

config set vnstat service status enabled access private
mkdir -p /usr/lib/systemd/system/vnstat.service.d
nano /usr/lib/systemd/system/vnstat.service.d/50koozali.conf

Paste this and save/exit:

[Unit]
Description=Vnstat global service for Koozali SME Server

[Install]
WantedBy=
WantedBy=sme-server.target

Add service key:

config set vnstat service status enabled access private

And Upgrade/Reboot for good measure:

signal-event post-upgrade
signal-event reboot

Are we running:

systemctl status vnstat

Lets look at the data:

                     rx      /      tx      /     total    /   estimated
eth0:
      Mar '24      4.36 MiB  /   22.12 MiB  /   26.48 MiB  /   40.00 MiB
        today      4.36 MiB  /   22.12 MiB  /   26.48 MiB  /      37 MiB
vnstat --iflist
vnstat -i eth0

By hour/week/month

vnstat -h/w/m -i eth0

eg

vnstat -w -i eth0

Remove unwanted DBs and stop monitoring the interface

vnstat -i dummy0 --delete --force

This could be templated:

cat /etc/vnstat.conf


Installation for Koozali SME v9

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

You need to activate the Dag reposity before installing this contrib.

see dag repository

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="-u"

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

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/