MRTG: Difference between revisions

From Edgar BV Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
<pre>MRTG Configuration
= Testing and editing =


First edit the configuration file and make sure the configuration file has:
<pre>
RunAsDaemon:    Yes
</pre>
commented out.
Then stop all mrtg daemons.
Run the configfile once with something like the following from /etc/init.d/mrtg
<pre>
/usr/bin/perl -w /usr/bin/mrtg --group=mrtggrp /etc/mrtg/euhost.cfg
</pre>
(NB not using --user=mrtguser because it fucks up randomly on this - might be a write permissions problem, but can't find out where then)
Set the RunAsDaemon: No
It'll run through everything and give a few errors. Run it a few times and check the MRTG page by hand. If none of the errors are snmp / target related, you can then run the command for the specific config file in indexmaker.cmd, eg
<pre>
indexmaker --output=/space/sites/mrtg/tripany/index.html --addhead="Tripany Bandwidth Monitoring for Internal NW Servers" --title="Tripany MRTG Servers" /etc/mrtg/tripany.ops.cfg
</pre>
Check the specific mrtg page to see if all the interfaces are on it.
If so then you can run the indexmaker.cmd command for all the configs:
<pre>
indexmaker --output=/space/sites/mrtg/index.html --addhead="Tripany Bandwidth Monitoring" --title="Tripany MRTG" /etc/mrtg/euhost.cfg /etc/mrtg/tripany.ops.cfg /etc/mrtg/USN.cfg --autoprefix
</pre>
start up /etc/init.d/mrtg and see if it all works.
In order to make sure you're refreshing / rebuilding the images delete everything from the directory in
Imagedir:
Then
The images will rebuild and you can look in the browser if it's working. Once it does work well, remember to make RunAsDaemon work again and then start it up.
= Basic MRTG Configuration =
in /etc/mrtg
in /etc/mrtg
First build a conf file which includes all the conf files you want mrtg to run. Each directive in this file will be used in all the sub-conf files. Each sub conf file will spawn a seperate mrtg process (if run as daemon)
First build a conf file which includes all the conf files you want mrtg to run. Each directive in this file will be used in all the sub-conf files. Each sub conf file will spawn a seperate mrtg process (if run as daemon)


/etc/mrtg.conf
== /etc/mrtg.conf ==
-------------------------------------------------------------------------
<pre>
 
######################################################################
######################################################################
# Multi Router Traffic Grapher -- Sample Configuration File
# Multi Router Traffic Grapher -- Sample Configuration File
Line 35: Line 74:
Include:        euhost.cfg
Include:        euhost.cfg
Include:        USN.cfg
Include:        USN.cfg
 
</pre>
-------------------------------------------------------------------------


Doing this allows you to place the resultant HTML files in different subdirectories, ie. allow different sets of statistics to be seen by different people.
Doing this allows you to place the resultant HTML files in different subdirectories, ie. allow different sets of statistics to be seen by different people.


Then we set up the local files
Then we set up the local files
/etc/mrtg/euhost.cfg


-------------------------------------------------------------------------
== /etc/mrtg/euhost.cfg ==
<pre>


Htmldir:        /space/sites/mrtg/euhost
Htmldir:        /space/sites/mrtg/euhost
Line 67: Line 105:
WithPeak[euhost.tripany.com.eth0]: wmy
WithPeak[euhost.tripany.com.eth0]: wmy
PageFoot[euhost.tripany.com.eth0]: <H1><a href="euhost.tripany.com.eth0.total.2006.html">Total Traffic Stats for 2006</a></H1>
PageFoot[euhost.tripany.com.eth0]: <H1><a href="euhost.tripany.com.eth0.total.2006.html">Total Traffic Stats for 2006</a></H1>
</pre>


----------------------------------------------------------------------------


The traffic data is polled using SNMP, so in the Target is the ethernet card you are polling and the community name.
The traffic data is polled using SNMP, so in the Target is the ethernet card you are polling and the community name.


The PageFoot and #-#Total lines are links to an external totaliser which I'll explain later.
The PageFoot and #-#Total lines are links to an external totaliser which I'll explain later.


Then we set up the index page which shows the current traffic information for all the interfaces in the local configuration files. This is done by running the indexmaker utility, so this has to be run every time a change is made (eg. by adding new interfaces).
Then we set up the index page which shows the current traffic information for all the interfaces in the local configuration files. This is done by running the indexmaker utility, so this has to be run every time a change is made (eg. by adding new interfaces).


== creating index files ==
The command to create the index file for all the configurations onto one page is:
The command to create the index file for all the configurations onto one page is:
-----------------------------------------------------------------------------------
<pre>
indexmaker --output=/space/sites/mrtg/index.html --addhead="Tripany Bandwidth Monitoring" --title="Tripany MRTG" /etc/mrtg/euhost.cfg /etc/mrtg/tripany.internal.cfg /etc/mrtg/USN.cfg --autoprefix
indexmaker --output=/space/sites/mrtg/index.html --addhead="Tripany Bandwidth Monitoring" --title="Tripany MRTG" /etc/mrtg/euhost.cfg /etc/mrtg/tripany.internal.cfg /etc/mrtg/USN.cfg --autoprefix
-----------------------------------------------------------------------------------
 
</pre>
 
To do this for just one of the specific configurations is
To do this for just one of the specific configurations is
-----------------------------------------------------------------------------------
<pre>
indexmaker --output=/space/sites/mrtg/euhost/index.html --addhead="Tripany Bandwidth Monitoring for EUHost" --title="EUHost MRTG" /etc/mrtg/euhost.cfg
indexmaker --output=/space/sites/mrtg/euhost/index.html --addhead="Tripany Bandwidth Monitoring for EUHost" --title="EUHost MRTG" /etc/mrtg/euhost.cfg
-----------------------------------------------------------------------------------
</pre>
 
 
= Totaliser pages =
 


To create the totaliser pages, you need mrtg_total.pl from http://www.geocities.com/josef_wendel/mrtg_total.html
To create the totaliser pages, you need mrtg_total.pl from http://www.geocities.com/josef_wendel/mrtg_total.html
Line 92: Line 139:
This will generate the pages linked to in the page footer.
This will generate the pages linked to in the page footer.


----------------------------------------------------------------
 
To monitor Spam statistics:
= To monitor Spam statistics =
http://users.2z.net/rpuhek/scripts_public/spamd/
http://users.2z.net/rpuhek/scripts_public/spamd/


Line 99: Line 146:


Also make sure that mrtguser has permissions to run the .pl file :)
Also make sure that mrtguser has permissions to run the .pl file :)
</pre>


Testing
----


In order to test configurations make sure the configuration file has:
= /etc/init.d/mrtg =
<pre>
#! /bin/sh


RunAsDaemon:    Yes
# MRTG starter
# NB For some reason had to remove the --user=mrtguser from ops / euhost but not from USN


commented out.
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"


In order to make sure you're refreshing / rebuilding the images delete everything from the directory in
case "$1" in
  start)
        echo -n "Starting MRTG Traffic router for USN"
        /usr/bin/mrtg --group=mrtggrp --pid-file=/var/run/mrtg/mrtgUSN.pid /etc/mrtg/USN.cfg 2>> /var/log/mrtg/mrtg.log
        echo "."
        echo -n "Starting MRTG Traffic router for Tripany Ops"
        /usr/bin/mrtg --group=mrtggrp --pid-file=/var/run/mrtg/mrtgtripanyops.pid /etc/mrtg/tripany.ops.cfg 2>> /var/log/mrtg/mrtg.log
        echo "."
#      echo -n "Starting MRTG Traffic router for Tripany Internal"
#      /usr/bin/mrtg --group=mrtggrp --pid-file=/var/run/mrtg/mrtgtripany.pid /etc/mrtg/tripany.internal.cfg 2>> /var/log/mrtg/mrtg.log
        echo "."
        echo -n "Starting MRTG Traffic router for EUHost"
        /usr/bin/mrtg --group=mrtggrp --pid-file=/var/run/mrtg/mrtgeuhost.pid /etc/mrtg/euhost.cfg 2>> /var/log/mrtg/mrtg.log
        echo "."
        ;;
  stop)
        echo -n "Stopping MRTG Traffic router"
        start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/mrtg/mrtgUSN.pid
        start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/mrtg/mrtgtripany.pid
        start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/mrtg/mrtgtripanyops.pid
        start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/mrtg/mrtgeuhost.pid
        echo "."
        ;;


Imagedir:
  *)
        echo "Usage: /etc/init.d/mrtg {start|stop}"
        exit 1
esac


Then run the configfile once with something like the following from /etc/init.d/mrtg
exit 0
 
</pre>
/usr/bin/perl -w /usr/bin/mrtg --group=mrtggrp /etc/mrtg/euhost.cfg
 
(NB not using --user=mrtguser because it fucks up randomly on this - might be a write permissions problem, but can't find out where then)
 
The images will rebuild and you can look in the browser if it's working. Once it does work well, remember to make RunAsDaemon work again and then start it up.

Revision as of 10:31, 12 March 2013

Testing and editing

First edit the configuration file and make sure the configuration file has:

RunAsDaemon:    Yes

commented out.

Then stop all mrtg daemons.

Run the configfile once with something like the following from /etc/init.d/mrtg

/usr/bin/perl -w /usr/bin/mrtg --group=mrtggrp /etc/mrtg/euhost.cfg

(NB not using --user=mrtguser because it fucks up randomly on this - might be a write permissions problem, but can't find out where then)

Set the RunAsDaemon: No

It'll run through everything and give a few errors. Run it a few times and check the MRTG page by hand. If none of the errors are snmp / target related, you can then run the command for the specific config file in indexmaker.cmd, eg

indexmaker --output=/space/sites/mrtg/tripany/index.html --addhead="Tripany Bandwidth Monitoring for Internal NW Servers" --title="Tripany MRTG Servers" /etc/mrtg/tripany.ops.cfg

Check the specific mrtg page to see if all the interfaces are on it.

If so then you can run the indexmaker.cmd command for all the configs:

indexmaker --output=/space/sites/mrtg/index.html --addhead="Tripany Bandwidth Monitoring" --title="Tripany MRTG" /etc/mrtg/euhost.cfg /etc/mrtg/tripany.ops.cfg /etc/mrtg/USN.cfg --autoprefix

start up /etc/init.d/mrtg and see if it all works.

In order to make sure you're refreshing / rebuilding the images delete everything from the directory in

Imagedir:

Then

The images will rebuild and you can look in the browser if it's working. Once it does work well, remember to make RunAsDaemon work again and then start it up.

Basic MRTG Configuration

in /etc/mrtg

First build a conf file which includes all the conf files you want mrtg to run. Each directive in this file will be used in all the sub-conf files. Each sub conf file will spawn a seperate mrtg process (if run as daemon)

/etc/mrtg.conf

######################################################################
# Multi Router Traffic Grapher -- Sample Configuration File
######################################################################
# This file is for use with mrtg-2.5.4c

# Global configuration
# Put these into the templates
#Htmldir:       /space/sites/mrtg
#Imagedir:      /space/sites/mrtg/images
#IconDir:        /space/sites/mrtg/icons
#Logdir:        /var/log/mrtg

#Forks:                 4
#RunAsDaemon:   Yes
#Interval:      5
#WriteExpires:  Yes

#Options[_]:    growright

# Also add lines for each of the daemons to /etc/init.d/mrtg

######################################################################
# Included configuration files
######################################################################

Include:        tripany.internal.cfg
Include:        euhost.cfg
Include:        USN.cfg

Doing this allows you to place the resultant HTML files in different subdirectories, ie. allow different sets of statistics to be seen by different people.

Then we set up the local files

/etc/mrtg/euhost.cfg


Htmldir:        /space/sites/mrtg/euhost
Imagedir:       /space/sites/mrtg/euhost/images
IconDir:        /space/sites/mrtg/icons
LogDir:         /var/log/mrtg
Forks:          4
RunAsDaemon:    Yes
Interval:       5
WriteExpires:   Yes

Options[_]:     growright

#------------------ EUHost Interfaces ------------------------

# Link to internet
Target[euhost.tripany.com.eth0]: \eth0:euhostrw@euhost.tripany.com:
#-#Total[euhost.tripany.com.eth0]: Total traffic for internet link on EUHost
SetEnv[euhost.tripany.com.eth0]: MRTG_INT_IP="212.61.33.42" MRTG_INT_DESCR="eth0"
MaxBytes[euhost.tripany.com.eth0]: 12500000
Title[euhost.tripany.com.eth0]: Traffic Analysis for internet link on EUHost
PageTop[euhost.tripany.com.eth0]: <H1>Traffic Analysis for internet link on EUHost</H1>
WithPeak[euhost.tripany.com.eth0]: wmy
PageFoot[euhost.tripany.com.eth0]: <H1><a href="euhost.tripany.com.eth0.total.2006.html">Total Traffic Stats for 2006</a></H1>


The traffic data is polled using SNMP, so in the Target is the ethernet card you are polling and the community name.


The PageFoot and #-#Total lines are links to an external totaliser which I'll explain later.


Then we set up the index page which shows the current traffic information for all the interfaces in the local configuration files. This is done by running the indexmaker utility, so this has to be run every time a change is made (eg. by adding new interfaces).

creating index files

The command to create the index file for all the configurations onto one page is:

indexmaker --output=/space/sites/mrtg/index.html --addhead="Tripany Bandwidth Monitoring" --title="Tripany MRTG" /etc/mrtg/euhost.cfg /etc/mrtg/tripany.internal.cfg /etc/mrtg/USN.cfg --autoprefix

To do this for just one of the specific configurations is

indexmaker --output=/space/sites/mrtg/euhost/index.html --addhead="Tripany Bandwidth Monitoring for EUHost" --title="EUHost MRTG" /etc/mrtg/euhost.cfg


Totaliser pages

To create the totaliser pages, you need mrtg_total.pl from http://www.geocities.com/josef_wendel/mrtg_total.html

Then add a crontab entry for each conf file you have #-#Total tags in 5 1 * * * root /usr/local/bin/mrtg_total.pl /etc/mrtg/euhost.cfg

This will generate the pages linked to in the page footer.


To monitor Spam statistics

http://users.2z.net/rpuhek/scripts_public/spamd/

The only edit here is to change the spam-stats.pl on the spamassassin machine to reflect the spamd logfile (which is /var/log/mail/spamd.log on debian, instead of syslog)

Also make sure that mrtguser has permissions to run the .pl file :)


/etc/init.d/mrtg

#! /bin/sh

# MRTG starter
# NB For some reason had to remove the --user=mrtguser from ops / euhost but not from USN

export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"

case "$1" in
  start)
        echo -n "Starting MRTG Traffic router for USN"
        /usr/bin/mrtg --group=mrtggrp --pid-file=/var/run/mrtg/mrtgUSN.pid /etc/mrtg/USN.cfg 2>> /var/log/mrtg/mrtg.log
        echo "."
        echo -n "Starting MRTG Traffic router for Tripany Ops"
        /usr/bin/mrtg --group=mrtggrp --pid-file=/var/run/mrtg/mrtgtripanyops.pid /etc/mrtg/tripany.ops.cfg 2>> /var/log/mrtg/mrtg.log
        echo "."
#       echo -n "Starting MRTG Traffic router for Tripany Internal"
#       /usr/bin/mrtg --group=mrtggrp --pid-file=/var/run/mrtg/mrtgtripany.pid /etc/mrtg/tripany.internal.cfg 2>> /var/log/mrtg/mrtg.log
        echo "."
        echo -n "Starting MRTG Traffic router for EUHost"
        /usr/bin/mrtg --group=mrtggrp --pid-file=/var/run/mrtg/mrtgeuhost.pid /etc/mrtg/euhost.cfg 2>> /var/log/mrtg/mrtg.log
        echo "."
        ;;
  stop)
        echo -n "Stopping MRTG Traffic router"
        start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/mrtg/mrtgUSN.pid
        start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/mrtg/mrtgtripany.pid
        start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/mrtg/mrtgtripanyops.pid
        start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/mrtg/mrtgeuhost.pid
        echo "."
        ;;

  *)
        echo "Usage: /etc/init.d/mrtg {start|stop}"
        exit 1
esac

exit 0