MRTG

From Edgar BV Wiki
Revision as of 20:07, 18 January 2017 by Red (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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/xxx/index.html --addhead="Bandwidth Monitoring for Internal NW Servers" --title="MRTG Servers" /etc/mrtg/xxx.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="Bandwidth Monitoring" --title="MRTG" /etc/mrtg/euhost.cfg /etc/mrtg/xxx.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:        xxx.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.xxx.com.eth0]: \eth0:euhostrw@euhost.xxx.com:
#-#Total[euhost.xxx.com.eth0]: Total traffic for internet link on EUHost
SetEnv[euhost.xxx.com.eth0]: MRTG_INT_IP="212.61.33.42" MRTG_INT_DESCR="eth0"
MaxBytes[euhost.xxx.com.eth0]: 12500000
Title[euhost.xxx.com.eth0]: Traffic Analysis for internet link on EUHost
PageTop[euhost.xxx.com.eth0]: <H1>Traffic Analysis for internet link on EUHost</H1>
WithPeak[euhost.xxx.com.eth0]: wmy
PageFoot[euhost.xxx.com.eth0]: <H1><a href="euhost.xxx.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="Bandwidth Monitoring" --title="MRTG" /etc/mrtg/euhost.cfg /etc/mrtg/xxx.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="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.ws/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. In one of the interace descriptions it looks like:

PageFoot[monitor.ops.edgarnet.int.eth1]: <H1><a href="monitor.ops.edgarnet.int.eth1.total.2013.html">Total Traffic Stats for 2013</a></H1>

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 Ops"
        /usr/bin/mrtg --group=mrtggrp --pid-file=/var/run/mrtg/mrtgxxxops.pid /etc/mrtg/xxx.ops.cfg 2>> /var/log/mrtg/mrtg.log
        echo "."
#       echo -n "Starting MRTG Traffic router for Internal"
#       /usr/bin/mrtg --group=mrtggrp --pid-file=/var/run/mrtg/mrtgxxx.pid /etc/mrtg/xxx.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/mrtgxxx.pid
        start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/mrtg/mrtgxxxops.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