[Pdns-users] a useful script to display pdns_recursor stats

J Knight jknight+pdns at spamshield.org
Sat Aug 25 01:50:05 UTC 2007


Within minutes of loading the pdns_recursor with real traffic, our fingers got tired
and sore of typing 'rec_control get FOO'.

Worse, there's no built-in help screen giving the available stats options:

With one eye permanently locked to a browser window displaying
http://doc.powerdns.com/recursor-stats.html page, the other dancing between
keyboard and shell window, we clearly needed some help.

See the results of our modest efforts below: our 'pstats' perl script.

We've given the item descriptions a serious makeover, too...

Thanks - Jamie

-------------

#!/usr/local/bin/perl5.8.8

if ($> != 0) {
        print "You must be root.\n";
        exit 1;
}

local $rec_control = "/usr/bin/rec_control";

@statvars = (
['all-outqueries' , "outgoing UDP queries"],
['answers0-1' , "queries answered within 1 ms"],
['answers1-10' , "queries answered within 10 ms"],
['answers10-100' , "queries answered within 100 ms"],
['answers100-1000' , "queries answered within 1000 ms"],
['answers-slow' , "queries answered after 1 second"],
['cache-entries' , "num of entries in the cache"],
['cache-hits' , "cache hits"],
['cache-misses' , "cache misses"],
['chain-resends' , "num of queries chained to existing outstanding query"],
['client-parse-errors' , "num of client packets that could not be parsed"],
['concurrent-queries' , "num of MThreads currently running"],
['dlg-only-drops' , "num of records dropped because of delegation only setting"],
['negcache-entries' , "num of entries in the Negative answer cache"],
['noerror-answers' , "num of times it answered NOERROR"],
['nsspeeds-entries' , "num of entries in the NS speeds map"],
['nsset-invalidations' , "num of times an nsset was dropped because it no longer worked"],
['nxdomain-answers' , "num of times it answered NXDOMAIN"],
['outgoing-timeouts' , "num of timeouts on outgoing UDP queries"],
['qa-latency' , "current latency average (microseconds)"],
['questions' , "enduser-initiated queries with the RD bit set"],
['resource-limits' , "queries dropped because of resource limits"],
['server-parse-errors' , "num of server replied packets that could not be parsed"],
['servfail-answers' , "num of times it answered SERVFAIL"],
['spoof-prevents' , "answers dropped due to spoofing: saw more than spoof-nearmiss-max answers"],
['tcp-client-overflow' , "TCP accesses denied for hosts exceeding max-tcp-per-client limit"],
['tcp-outqueries' , "outgoing TCP queries"],
['tcp-questions' , "incoming TCP queries"],
['throttled-out' , "throttled outgoing UDP queries"],
['throttle-entries' , "num of entries in the throttle map"],
['unauthorized-tcp' , "num of TCP questions denied because of allow-from restrictions"],
['unauthorized-udp' , "num of UDP questions denied because of allow-from restrictions"],
['unexpected-packets' , "unexpected answers from remote servers (might point to spoofing)"],
['uptime' , "seconds process has been running (since 3.1.5)"],
['user-msec' , "CPU milliseconds spent in 'user' mode"],
['sys-msec' , "CPU milliseconds spent in 'system' mode"],
);

local $var;
local $str;
local $n;
local $i = @statvars; #
local $v;

print "All counters since start of PDNS-Recursor:\n";

for ($n=0 ; $n<$i ;  $n++) {
        $var = $statvars[$n][0];
        $str = $statvars[$n][1];
        my $cmd = "$rec_control get $var";
        $v = `$cmd`;
        chomp $v;
        printf "%-20s: %8d (%s)\n", $var, $v, $str;
}

print "Top query sources ";
$v = `$rec_control top-remotes`;
print $v;





More information about the Pdns-users mailing list