Special for hosting companies; MRTG-archive, Traffic usage graph, etc.
Perl: * gbgraph.pl This is the main program generating the datafiles for the PHP grapher. * calc.pl This is a part being called from gbgraph.pl, calculating the output from MRTGLOG. * archiver.pl This is the archiver program. PHP: * mrtg.php The page for layouting your MRTG, with tabs and the traffic graph. * img.php A PHP-script generating the tab's. * gb.php The PHP-script that draws the graph. PNG: * fun.png A 'very ugly' example of a possible baseimage, see extra's.
* Unix system (might work on Windoze as well) * A webserver (Apache) with PHP 4.0.x, compiled with GD * GD 1.6+ * Perl 5.0 or higher (pref. 5.6.x) * CRON, or anything that can call programs at a given time * MRTG 2.x (tested on 2.9.12), Compile MRTGLOG (in MRTG-contrib-dir)
1. Create a directory for the Perl-scripts, not web-accessable. Example: /home/httpd/gbgraph 2. Make sure the Perl-location in all scripts is correct (#!/full/path/to/perl). You can locate perl: 'whereis perl'. 3. Edit any variabeles in top of the scripts (perl and PHP) to match your system. Make sure the perl scripts are executable (chmod a+x *.pl). 4. Compile mrtglog (located in your mrtg/contrib directory): Example: gcc -o /home/httpd/gbgraph/mrtglog mrtglog.c (make sure the binary "mrtglog" will be in 'our' directory) 5. Copy the PHP script to your MRTG-workdir. Example: /home/httpd/html/mrtg 6. Edit gbgraph.pl: '#$new = "true";' --> '$new = "true";' (uncomment) Now we can generate this month until yesterday. 7. Run gbgraph.pl once. It now should generate [target].data files in your MRTG-workdir. Example: ./gbgraph.pl 8. Check your MRTG-workdir for the .data files; if they look oke, the program is working fine. Example line from .data file: 20010429 14643633463.234 9. If everything looks good; edit gbgraph.pl again and comment the '$new = "true";' to '#$new = "true";'. Now gbgraph.pl is ready for normal operation. 10.Edit your crontab: 'crontab -e' : 10 0 * * * /home/httpd/gbgraph/gbgraph.pl 15 0 1 * * /home/httpd/gbgraph/archiver.pl /mrtg.cfg Make sure paths are reflecting your situation. For archiver.pl you have to add the full path to your mrtg.cfg file. 11.Access your mrtg.php: Example: http://noc.trueserver.nl/Summit4/mrtg.php If you see a neat mrtg-page with tab's on top and a MB/GB/TB usage graph, everything is fine. Else you have to play around ;0) Btw, tab's will get active as soon as a archive exists (generated every first day of the month.). Enjoy!
* BaseImg: In (or else were from you call gb.php image) mrtg.php you can modify the look&feel of the graph, by adding a "base image". If you change: <img src=gb.php?host=ETC> to <img src=gb.php?baseimg=fun&host=ETC> you will see a 'very ugly' background (you have to copy the fun.png to your MRTG-workdir!). This comes from the 'fun.png' image. If you have the qualities to create neat images this can be a very nice option. I'm pleased to receive your wonderful creations!* Color: On the same way as the above option you can add "blue=xxx","red=xxx" and "green=xxx" options for coloring the graph. Example: <img src=gb.php?red=200&blue=200&green=0&host=ETC> gives a purple graph. You can use 1 to 235 as valid values.
* Details: It is also possible to show separated IN and OUT traffic usage. This extra is created by Roel van der Ouderaa. <img src=gb2.php?host=ETC> will show an other graph:
* Weekly backup: The 'archiver.pl'-script also has a week-backup option. If you call the script every first day of the week (monday) it'll generate a weekly backup (including tar-file), with the name: YYYY-WW; Example: for week 23, year 2001: directory 2001-23 and tarfile: 2001-23.tar.gz
0.1 - Basic GB/D graph with input from file
- Dotted blue Average-line
0.2 - Larger image
- Total this, Total last month, Average and Peak in text
- Calculate expected use on basis of average
0.3 - Variable graph-color
0.4 - DayInMonth variable; so no static 31 days
- GB/TB conversion for month-total/expected
0.9 - total code makeover
- overall debug mogelijkheid met &debug=1
- extra filecheck
- diverse for() lussen toegevoegd om code optimize
- functies als trim/sprintf gebruikt om strings netter (te formater)
- auto output format in bytes, k, m, g, t, en peta bytes.
- totaal berekening met array functie, max berekening omgeschreven,
avg nu over aantal dagen dat er waardes zijn ipv over aantal dagen maand
- grijs raster toegevoegd
- y-waarde met 1 decimaal, rechts uitgelijnt
- uitlijnen totaal overzicht op rechts incl. afrondenen formateren 0.1f.
1.0 - using new .data filetype, with date in it.
1.2 - added archiving function
1.3 - added tab's
1.4 - 2 color graph, baseimg option
1.9 - lot's of debugging and optimizing, perl and php.