PHP script for BIND 9.x statistics

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
robadawb

PHP script for BIND 9.x statistics

Post by robadawb »

Hello. I wrote this script in PHP. It will give you the success, nxrrset, recusion, referral, nxdomain, and failure queries for any BIND 9.x server.

Code: Select all

<?php

// script to display BIND 9.x statistics

shell_exec('rndc stats');
$data = shell_exec('tail -n 8 /var/named/named.stats');
$dataArray = explode(chr(10), $data);
foreach($dataArray as $value) {
        $temp = explode(' ', $value);
        $outputArray[$temp[0]] = $temp[1];
}

echo 'success:'.$outputArray['success'].chr(32);
echo 'referral:'.$outputArray['referral'].chr(32);
echo 'nxrrset:'.$outputArray['nxrrset'].chr(32);
echo 'nxdomain:'.$outputArray['nxdomain'].chr(32);
echo 'recursion:'.$outputArray['recursion'].chr(32);
echo 'failure:'.$outputArray['failure'].chr(32);

?>
It uses associative arrays, so the key is the name of the value you want. If you don't want a value simply comment it out. Make sure your /etc/rndc.conf file is readable by the user that executes the script (i.e. apache). Below are definitions for the data dumped taken from the BIND 9 Administrator Reference Manual.
All statistics are global for the entire server

success – the number of successful queries made to the server
referral – the number of queries which resulted in referral responses
nxrrset – the number of queries which resulted in NOERROR responses with no data
nxdomain – the number of queries which resulted in NXDOMAIN responses
recursion – the number of queries which caused the server to perform recursion
failure – the number of queries which resulted in a failure response (or anything that did not fit into the above)
Hope this script helps someone out there :D

- robadawb
Guest

Post by Guest »

just wanted to say i just tested the script ... looks like i'll be implementing this at my work place, heh.

Thanks!
steve

more info??

Post by steve »

Does this mean cacti needs to be running on the bind server?
Is there a way to gather these stats remotley?
robadawb
Posts: 4
Joined: Fri Nov 14, 2003 3:56 am
Location: Denver, Colorado

Post by robadawb »

Yes, the cacti script needs to be running on the same server as BIND. There are ways around this, but it depends on how much work you want to put into it.
If it wasn't for reality, everything would be fine.
anthony.warren
Posts: 31
Joined: Fri Nov 22, 2002 10:50 am
Location: Rochester, UK

Post by anthony.warren »

robadawb,
Please could you describe how this could work for collecting BIND stats from different servers.
I have 2 DNS servers that are located in 1 DMZ and my Cacti machine is on my internal network.

Regards,
Anthony
robadawb
Posts: 4
Joined: Fri Nov 14, 2003 3:56 am
Location: Denver, Colorado

Post by robadawb »

Probably the best methodology would be to setup apache on the server running bind and post the data from the script to a URL. You could then use PHP to read in the data from the URL and output the data to cacti. Of couse, this might generate a few security issues. The other way would be to use some sort of file sharing protocol like SMB or NFS.
If it wasn't for reality, everything would be fine.
allta
Posts: 3
Joined: Fri Oct 24, 2008 12:41 am

Post by allta »

Can someone please post a snapshot, so we can see the unique identity of this script which makes it different from others. I love the idea of php though. Cheers for your work mate. Allta
gagadget
Cacti User
Posts: 71
Joined: Tue Feb 21, 2006 9:40 am

Re: more info??

Post by gagadget »

steve wrote:Does this mean cacti needs to be running on the bind server?
Is there a way to gather these stats remotley?
Full SSH method :

http://forums.cacti.net/about27889.html
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests