[mrtg] Re: MRTG log dump to MySQL?
Danny Brando
dannyb at dannyb.net
Thu Jul 12 22:08:28 MEST 2001
On Thu, 12 Jul 2001, Day Dreamer wrote:
> Has anyone tried to configure MRTG to directly dump
> the raw data into MySQL? Any idea where may find more
> info on this for both MySQL and MRTG sides?
I've done this by modifying the mrtg perl script to just write the current
numbers to the database along with the total in and out, date,time, and
target name. Now I am able to run 95th percentile reports for any given
period. I also wrote my own perl scripts using GD to graph any period of
time I specify.
Right after this:
##########################################################
print HTML
'<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
'.&$LOC('charset=iso-8859-1')."\">\n";
foreach $peri (qw(d w m y)) {
##########################################################
I insert the code to write the info to the database...
##########################################################
if ($peri eq "d"){
my $danin=$$cuin{$peri}{$router} * 8;
my $danout=$$cuout{$peri}{$router} * 8;
my $dantot=$danin + $danout;
$dbh->Query("INSERT INTO
$table_name(router,instats,outstats,totalstats,date,time)
VALUES(\"$router\",\"$danin\",\"$danout\",\"$dant
ot\",\"$day\",\"$time\")")or die $Mysql::db_errstr;
}
############################################################
Obviously you have to put other code in the beginning to define your
database, date and time....but this is the guts of it.
Probably not the best code in the world, but functional....
-dannyb
--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive http://www.ee.ethz.ch/~slist/mrtg
FAQ http://faq.mrtg.org Homepage http://www.mrtg.org
WebAdmin http://www.ee.ethz.ch/~slist/lsg2.cgi
More information about the mrtg
mailing list