v0.21 2003/10/31 Josef Wendel (for version history see source file)
Perl script to sum up the traffic of any MRTG monitored device. It generates html output with monthly (example) and daily (example) totals.
Disclaimer
Where to get and how to install it?
Download mrtg_total.pl.
Linux
Save it to /usr/local/bin.
Get the following Perl modules from CPAN:
GD-1.32 (or better)
GDGraph-1.33 (or better)
GDTextUtil-0.80 (or better)
GDGraph3d-0.55 (or better)
Install them according to their installation instructions.
Modify your crontab5 1 * * * /usr/local/bin/mrtg_total.pl
Maybe you have to adjust the location where your perl resides (first line of the script)
Windows
You need to have Perl (i.e. from ActiveState) installed and running. mrtg_total.pl has been checked with version 5.6 build 623 on a Windows 2000 system and with version 5.8.0 build 806 on a Windows XP system
Save mrtg_total.pl in your preferred local bin/ or exec/ directory.
For ActivePerl 5.6 use PPM to get the following, pre-compiled modules:
install GD
install GDGraph
install GDTextUtil
install GDGraph3d
For ActivePerl 5.8 use PPM to get the following, pre-compiled modules (located at University of Winnipeg):
install http://theoryx5.uwinnipeg.ca/ppms/GD.ppd
install http://theoryx5.uwinnipeg.ca/ppms/GDGraph.ppd
install http://theoryx5.uwinnipeg.ca/ppms/GD-Graph3d.ppd
install http://theoryx5.uwinnipeg.ca/ppms/GDTextUtil.ppd
Make sure to run
How to setup and run it?
Be sure to have MRTG up, run and collect data for the devices you want to have the totals. Allow MRTG one day or two to fill its database before you run mrtg_total.pl.
Edit your MRTG config file and add "pseudo comments". Add lines like the following for each device of interest:#-#Total[
When called mrtg_total.pl scans the MRTG config file for devices with this special tag, opens the appropriate data base file, calculates the amount of daily and monthly traffic and outputs some .html-files.
mrtg_total.pl understands and uses a lot of the MRTG config options like WorkDir, LogFormat et.al.
mrtg_total.pl is able to handle MRTG data base file in RRD format, at least at a Linux box (not checked with Windows).
mrtg_total.pl understands the following additional pseudo comments:#-#Total-Unit[]: KMGT table output in Kbyte, Mbyte, ...#-#Total-Ratio[]: yes additional in/out ratio#-#Total-Directory[]: path similar to the mrtg 'directory' switch#-#Total-Output[]: DWM to select which kind of output. Defaults to DM
mrtg_total.pl formats the numbers in the output table for better readeability with dots. If you are in an anglo environment you may want to change it to a comma. Open the script with an editor of your choice and find and change the definition of $TSEP.
Same for the date output format. Seek for $DATEFORMAT and change as described in mrtg_total.pl
Sometimes I forget to de-activate the debug-mode :-( Please help yourself in the script ($DEBUG)
An example:
Workdir: /usr/local/mrtg/web
Refresh: 300
Interval: 5
Forks: 10
Options[_]: unknaszero
Target[router.ser2]: 17:public@router.domain.org #-#Total[router.ser2]: Traffic Totals for ROUTER, 2 Mbit E1 to Internet #-#Total-Unit[router.ser2]: M
#-#Total-Ratio[router.ser2]:yes
MaxBytes[router.ser2]: 250000
WithPeak[router.ser2]: ymw
AbsMax[router.ser2]: 300000
Title[router.ser2]: ROUTER.ser2 (Cisco 4500): 2 Mbit E1 to Internet
PageTop[router.ser2]:
Traffic Analysis for ROUTER.ser2, 2 Mbit E1 to Internet
(...)
At last...
If you use PHP, you may be interested in this little tool to collect all mrtg_totalized files of a specific device and get a comprehensive look over the years.