#!/usr/bin/perl # MIBORDER: The order in which the statistics are returned to the # snmp daemon. It is specified in the CPWR DNS MIB. @MIBORDER = ("CPUu", "CPUs", "CHILDCPUu", "CHILDCPUs", "A", "NS", "CNAME", "SOA", "PTR", "HINFO", "MX", "TXT", "NSAP", "AXFR", "ANY", "RQ", "RR", "RIQ", "RNXD", "RFwdQ", "RFwdR", "RDupQ", "RDupR", "RFail", "RFErr", "RErr", "RTCP", "RAXFR", "RLame", "ROpts", "SSysQ", "SAns", "SFwdQ", "SFwdR", "SDupQ", "SFail", "SFErr", "SErr", "RNotNsQ", "SNaAns", "SNXD"); # Search for the last statistic lines, first in the previous logfile # and then in the current one. if (open(STATS, "/var/log/named/stats.log.0")) { while () { chop; # usage or nstats info might be rotated to the old # logfile and may not present in the current one. if (/USAGE/) { $usage = $_; } if (/NSTATS/) { $nstats = $_; } } close(STATS); } open(STATS, "/var/log/named/stats.log") || die "Can't open stats file"; while () { chop; if (/USAGE/) { $usage = $_; } if (/NSTATS/) { $nstats = $_; } if (/XSTATS/) { $xstats = $_; } } close(STATS); # Put all statistics into a hash where the keys is the name and the data # is the counter. @usage = split(/ /, $usage); @nstats = split(/ /, $nstats); @xstats = split(/ /, $xstats); # CPU and CHILDCPU return both user and system time on one line. Split # those in CPUu, CPUs, CHILDCPUu and CHILDCPUs. splice (@usage, 0, 3); foreach $spec (@usage) { if ($spec =~ /(.*)=(.*)u\/(.*)s/) { $stats{$1 . "u"} = $2 * 1000; $stats{$1 . "s"} = $3 * 1000; } } splice (@nstats, 0, 3); foreach $spec (@nstats, @xstats) { if ($spec =~ /(.*)=(.*)/) { $stats{$1} = $2; } } # Print values in the order specified by the MIB. Return 0 if a specific # stat is not in the list. foreach $statname (@MIBORDER) { if ($stats{$statname}) { print $stats{$statname}, "\n"; } else { print "0\n"; } }