Welcome To mkmrtg.sh

Hi! If your here it must mean your familiar with MRTG. The basis of this page is to help you with a front-end for MRTG. A quick over-view can be found to the right in the Who, What, Why, Where, How section.

Currently, mkmrtg.sh is up to Version 0.9
Remember to check out the stuff on the right.
Then click here to jump to the code. :)

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

Wednesday, September 10, 2008

Add-On: Timer (Updated)

I was thinking. Does my machine take to long to run through all the mrtg config files? (I graph 20+ at home and 100+ at work) I learned from a friend a while back that in shell scripting, you can improve over-all performance by making your tasks run one-after-the-other. So, if you have a LOT of stuff that runs at 1:00AM, instead of a lot crontab entries, you put all those entries into a script and let the crontab run the script you created.

If your not doing that, I suggest you do. Now, I wanted to make sure that this script is not running for more than 5 minutes. So, I created a little add-on to let me know everything is ok. :)



mrtg.sh


#! /bin/bash
ds=`date +%s`
cfg="/usr/bin/env LANG=C /etc/mrtg/bin/mrtg /etc/mrtg/monitor"
for c in `ls /etc/mrtg/monitor | grep cfg | cut -d"." -f1 | sort -u`
do
$cfg/$c.cfg
done

loc="/srv/www/htdocs/mrtg"
gl=`cat $loc/nav.html | wc -l`
cl=`expr $gl - 2`
gf=`tail -n$cl $loc/nav.html`
de=`date +%s`
dt=`expr $de - $ds`
dm=`expr $dt / 60`
echo "<html><head><title>Navigation</title><meta http-equiv=refresh content=60></head><body>" > $loc/nav.html
echo "<h4>MRTG Nodes</h4><font size=0>`date`<br>Run: $dt sec ($dm min)</font><p><table border=0>" >> $loc/nav.html
echo "$gf" >> $loc/nav.html



There you have it. Note, this assumes the location of the mkmrtg.sh output. Change the 'loc' variable (green above) if needed.

This got me to thinking... You could utilize curl to get the time it took and graph that too! Isn't MRTG GREAT!!!!

UPDATE: I changed the way it gets is config files. Now all you have to do is drop the .cfg file into the directory and it will automatically pick it up.

1 comment:

Anonymous said...
This comment has been removed by a blog administrator.