[mrtg] Re: DNS stats collectors
Ilkka Kaakkola
ilkka.kaakkola at jippiigroup.com
Mon Feb 11 14:27:44 MET 2002
> I mean to grep from the log files generated by my DNS server. the Failed/
> success requests to know how my DNS server is responding to customers
> requests.
>
I'd go for a perl script using File::Tail to tail the logfile
continously and update a database or textfile with the statistics, and
write a shell-script to fetch the values from the database every 5
minutes.
I've been using File::Tail with _big_ maillog's without any problems, so
unless your dns log is over 2-3 gigs (yes, gigs), you wont have problems
with the tail module.
Something like this might do the trick..
(yes it's not in strict, yes it's just an example. It will most likely
not work, I take no responsibility of what you are able to break with
it.. )
---Clip, dns-stats.pl start---
#!/usr/bin/perl
use DB_File;
use File::Tail;
my $database = tie(%statistics, "DB_FILE", "/path/to/my/database",
O_CREAT|ORDWR, 0666, $DB_HASH) || die "Cannot create or open database";
my $logref=tie(*LOG, "File::Tail", (name=>/path/to/dnslog,
debug=>0,
interval=>1,
maxinterval=>5,));
while (my $line = <LOG> {
chomp $line;
# Do something with the current line from the log, I dont have
# a dns server with a logfile to view here so I dont know about
# the format..
if ($line =~ /regexp to get a success line/) {
&use_database("SUCCESS");
}
if ($line =~ /regexp to get failed line/) {
&use_database("FAILED");
}
}
sub use_database {
my ($type) = @_;
$statistics{"$type"} +=1;
$database->sync;
}
----dns-stats.pl end----
And you can use a simple perl script to fetch data from the database:
----dns-fetch.pl start----
#!/usr/bin/perl
use DB_File;
$|=1;
tie(%stats, "DB_File", "/path/to/stats/database", o_RDONLY, 0666,
$DB_HASH) || die "could not open database file";
foreach (sort keys %stats) {
print "$_ $stats{$_}\n";
}
untie %stats;
----dns-fetch.pl end----
You probably want to write a wrapper script to see that the log tailer
stays alive.
Cheers,
Ilkka
--
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