Cover V07, I05
Article
Figure 1
Figure 2
Listing 1
Listing 2
Listing 3
Listing 4
Listing 5

may98.tar


Listing 1: Parser for named log file

#!/usr/local/bin/perl -w

#
#  named_log_to_stats.pl  -  Parse the XSTATS entries logged by named into
#                            columns suitable for plotting by gnuplot.
#
#     Usage:  named_log_to_stats.pl <logfile>
#
#     Example:
#
#        % named_log_to_stats.pl named.messages > named.dat
#
#     Input file:
#
#        Typical output from named daemon.  See split() comments below.
#
#     Output file:
#
#        ctime       UpDay   RQ/min  Subtl   Total
#        -----       -----   ------  -----   -----
#        883640700   0.05      14     1004   818685
#        883644300   0.09      14      888   819573
#        883647900   0.13      14      892   820465
#        883651502   0.17      14      883   821348


$rq = 0;
$rq_prev = 0;
$time_prev = 0;

# Header
#printf "ctime\t\tUpDay\tRQ/min\tSubtl\tTotal\n";
#printf "-----\t\t-----\t------\t-----\t-----\n";

while (<>) {

if (/XSTATS/) {
# Incoming lines look like this:
#   Jan  1 00:34:55 atlas named[109]: XSTATS 883636495 879717455
#   RR=54913 RNXD=29652 RFwdR=46344 RDupR=42 RFail=1431 RFErr=0
#   RErr=2 RAXFR=3 RLame=1718 ROpts=0 SSysQ=4321 SAns=769772
#   SFwdQ=48042 SDupQ=37735 SErr=0 RQ=817681 RIQ=0 RFwdQ=48042
#   RDupQ=302 RTCP=3 SFwdR=46344 SFail=6768 SFErr=597 SNaAns=9084

($month, $day, $time, $host, $pid, $xstats, $statdate, $startdate,
$rr, $rnxd, $rfwdr, $rdupr, $rfail, $rferr, $rerr, $raxfr, $rlame,
$ropts, $ssysq, $sans, $sfwdq, $sdupq, $serr, $rq, $riq, $rfwdq,
$rdupq, $rtcp, $sfwdr, $sfail, $sferr, $snaans, $snxd) = split();

# Only set $FirstStatDate once, so that you can string multiple
# invocations of named together (restarting named, which resets
# the request count to zero, will be handled properly).
if (!(defined $FirstStatDate)) { $FirstStatDate = $statdate; }

$rq =~ s/RQ=//g;  # Chop out the "RQ=" from $rq

if (($rq < $rq_prev) || ($statdate == $FirstStatDate)) {

# Then named was restarted, and this entry represents a gap
# between the old named instance and the new instance.
# Instead of printing this entry, output a blank line.
# Go ahead and set the prev variables so that the subsequent
# statistics will be relative to the skipped entry.

print "\n";

} else {

# This is the usual case
$rq_this_entry = $rq - $rq_prev;
$seconds_this_entry = $statdate - $time_prev;
$minutes_this_entry = ($seconds_this_entry / 60);
$rq_per_minute_this_entry = $rq_this_entry / $minutes_this_entry;
# convert seconds --> days
$statday = (($statdate - $FirstStatDate)/60/60/24);

printf "%d\t%.2f\t%d\t%d\t%d\n", $statdate, $statday,
$rq_per_minute_this_entry,
$rq_this_entry, $rq;
}

$rq_prev = $rq;
$time_prev = $statdate;
}
}

# End of File