Help - Search - Members - Calendar
Full Version: MRTG bind stats addon script
The Planet Forums > System Administration > HOWTOs
night-red
This script here will list your DNS stats for the server. You must have a working setup copy of mrtg.
There are two files you want to edit/create.

We start off by moving to your mrtg dir.
cd /etc/mrtg (or where it is installed)

We have to now make the file to get the stats.
pico -w bind.pl

Paste this in to it.

CODE
#!/usr/bin/perl



$hostname = "local";



$uptime = `uptime`;

$uptime =~ /up (.*?),/;

$uptime = $1;



$start =`/usr/sbin/rndc stats`;

$log   ="/var/named/named.stats";



@stat = `tail -n 15 $log`;



$last_success = $stat[0];

$last_success =~ tr/^[0-9] //cd;

$last_failure = $stat[5];

$last_failure =~ tr/^[0-9] //cd;



$latest_success = $stat[8];

$latest_success =~ tr/^[0-9] //cd;

$latest_failure = $stat[13];

$latest_failure =~ tr/^[0-9] //cd;



$success = $latest_success - $last_success;

unless ($success lt "0"){ $success ++; }



$failure = $latest_failure - $last_failure;

unless ($failure lt "0"){ $failure ++; }



print "$successn$failuren$uptimen$hostnamen";



exit;


Now to make this run properly.
chmod +x bind.pl

Now to edit your mrtg.cfg file to have the stats show, this is very editable to how you do your mrtg.
pico -w mrtg.cnf

Paste this at the bottom.

CODE
#----------------------------

# DNS

#----------------------------



Target[dns]: `/etc/mrtg/bind.pl`

Options[dns]: gauge,absolute,integer,nopercent,growright

MaxBytes[dns]: 100000

Title[dns]: DNS Queries

PageTop[dns]: <h3>DNS Queries</h3>

YLegend[dns]: DNS Queries

ShortLegend[dns]: q/m

LegendI[dns]:  # of successful queries:

LegendO[dns]:  # of failed queries:

Legend1[dns]: Successful queries

Legend2[dns]: Failed queries



Now this script for the stats has several problems it really does not like restarts. If you can make this better please do and then share it with us.
night-red
is anyone using this?
doug357
I just did it and it seems to work, i will post if i have any issues...
phatblink
I've been meaning to write my own script to pull those stats from bind, but seem to always end up doing something different when i try. Looks great and was easy to add. only thing you may want to add is that if they are using the easy mrtg howto is they will need to add some html to the cfg file too. add this to the html section called pagetop ^

add
- DNS Queries
just before the ending tag. so it looks like this.

.....(cut for space )
- DNS Queries 


then do service mrtg restart.

nice work.
doug357
I am using it and it seems to work great.
JamesC
Great how to night-red

It works great just one little catch tho where the pico -w mrtg.cnf It should read pico -w mrtg.cfg

Once I figured that out it worked great be sure to restart mrtg like phatblink said so it can create the logs for it. Also I added the html code that phatblink suggested not sure if it was needed but I did it just to make sure there was a link for it.
Wako
I have the following error after running mrtg :

Rateup WARNING: /usr/bin/rateup Can't remove dns.old updating log file

Any idea? icon_smile.gif
JamesC
QUOTE
Originally posted by Wako
I have the following error after running mrtg :

Rateup WARNING: /usr/bin/rateup Can't remove dns.old updating log file

Any idea?  :)


That happened to me the first time it updated the web stats page but after that it did not happen again that i noticed. But I think I will keep an eye on it and see.
CobaltConn
Trying to do some debugging...I think this is problem.

root@bigbird [/etc/mrtg]# /usr/sbin/rndc stats
rndc: connect failed: connection refused

any suggestions?

thanks in advance.
night-red
Sorry for the 2 or three mistakes in it, but it keeps you on your feet.
And yes you should restart after like they said. I left out adding a link to it since I do not know how everyone has there mrtg pages created so I wanted it to be universal but very good of you to add it. (I think I just forgot it)

As for this problem.
QUOTE
Rateup WARNING: /usr/bin/rateup Can't remove dns.old updating log file

That should happen restart 3 times and it will go away it is just a new log file that it is making and has no data to run on it.
night-red
QUOTE
Originally posted by CobaltConn
Trying to do some debugging...I think this is problem.

root@bigbird [/etc/mrtg]# /usr/sbin/rndc stats
rndc: connect failed: connection refused

any suggestions?

thanks in advance.

This is created to run with I belive it is Bind 9 (the latest ver) the old setup had a different stats read out and needed a completly different program to run.
In short this only works with bind 9 I belive.
(sorry for one or two blanks in the howto first one.)
Wako
QUOTE
Originally posted by JamesC
That happened to me the first time it updated the web stats page but after that it did not happen again that i noticed. But I think I will keep an eye on it and see.


Yes, in my situation it is the same, I only saw three errors, but afterward everything is fine.
phenx
wonder if we can get gpan to add this to his rpm
CobaltConn
I am running Bind9 --any other Ideas?
CobaltConn
my original error was:

root@bigbird [~]# rndc: connect failed: connection refused
tail: /var/named/named.stats: No such file or directory
phatblink
if your using an ensim box then rndc should already be setup and working correctly. if not then you may have to set it up your self.

Be warned messing with your named.conf can easily mess up your name server and you should probably make a back up of it first.

so are you using ensim or a plain RH box?.
CobaltConn
Using CPanel7/RedHat 7.3 ...
phatblink
while I could offer you assistance with keys and peices of configs. the issue of rndc not working has already been discussed in the forums for cpanel servers. ( -plus i dont have a cpanel box and would feel bad if i helped break yours)
I can tell you this though.

In the named.conf you need a section that looks like this

##################
key "rndc-key" {
algorithm hmac-md5;
secret "fu91wVAO2dam53RyGBqmvg==";
};
##################

and in your /etc/rndc.conf you need something like this

##################
key "rndc-key" {
algorithm hmac-md5;
secret "fu91wVAO2dam53RyGBqmvg==";
};

options {
default-key "rndc-key";
default-server 127.0.0.1;
default-port 953;
};
##################

and in a file called /etc/rndc.key

##################
key "rndc-key" {
algorithm hmac-md5;
secret "fu91wVAO2dam53RyGBqmvg==";
};
##################


you can do a search in the cpanel section for "rndc" and come up with others who have had the issue, suck as this link below.


http://forum.ev1servers.net/showthread.php...&highlight=rndc


You should be able to get it going with this info. ( you could use the examples above and get it working on most boxes.)
CobaltConn
thanks.
CobaltConn
Hmm...only thing I was missing (was just blank) was rndc.key

Filled it in with my info--now get this error:


root@bigbird [~]# /usr/sbin/rndc stats
rndc: 'stats' failed: permission denied

any ideas?

thank you so much..
phatblink
specify this line in your options section of your named.conf file.
and be sure that the directory /var/named/ exists and is writable by the owner that the name server is running as. usually (named)

statistics-file "/var/named/named.stats";
CobaltConn
That was resolved...now:

root@bigbird [~]# /usr/sbin/rndc stats
rndc: connect failed: connection refused

I've got a firewall--but that shouldn't matter through localhost--should it?
CobaltConn
Yea I've screwed something up...named is down (which i assume it why connection is refused)
CobaltConn
Got it--I think.

/usr/sbin/rndc stats

returns nothing...that good?
CobaltConn
root@bigbird [~]# tail /var/named/named.stats
failure 0
--- Statistics Dump --- (1065565188)
+++ Statistics Dump +++ (1065565234)
success 13
referral 0
nxrrset 4
nxdomain 0
recursion 1
failure 0
--- Statistics Dump --- (1065565234)


I'd assume thats good icon_smile.gif

Thanks for your help. I truly appreciate it.
phatblink
glad to help!!
night-red
The is the corret output
vagos161182
Greetings from sunny(this period) Greece icon_smile.gificon_smile.gif

After a longgg search for a suitable and easy-to-use script for monitoring the DNS server(using mrtg),I found your script.

The problem is that it shows me the following errors(when trying to run manually the mrtg with LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok )



Thursday, 27 August 2009 at 12:48: WARNING: Could not get any data from external command '/etc/mrtg/bind.pl'
Maybe the external command did not even start. (Illegal seek)

Thursday, 27 August 2009 at 12:48: WARNING: Problem with External get '/etc/mrtg/bind.pl':
Expected a Number for 'in' but nothing'

Thursday, 27 August 2009 at 12:48: WARNING: Problem with External get '/etc/mrtg/bind.pl':
Expected a Number for 'out' but nothing'

Thursday, 27 August 2009 at 12:48: ERROR: Target[dns][_IN_] ' $target->[4]{$mode} ' did not eval into defined data
Thursday, 27 August 2009 at 12:48: ERROR: Target[dns][_OUT_] ' $target->[4]{$mode} ' did not eval into defined data
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.