# How do you calculate "Queries Per Second" in BIND 9?



## w3nd377 (May 26, 2011)

How do you calculate queries per second (QPS) in BIND 9 on FreeBSD?  Is there a pre-built script someone has or knows about?  Our environment InfoSec parameters prevent me from installing additional software onto the system like MRTG unfortunately.


----------



## SirDice (May 27, 2011)

Enable the statistics file in named.conf in the options section:

```
statistics-file "/var/stats/named.stats";
```

Let it run for a while then issue:
`# rndc stats`

And look at the statistics file:

```
root@maelcum:~#cat /var/named/var/stats/named.stats 
+++ Statistics Dump +++ (1306478640)
++ Incoming Requests ++
              402314 QUERY
                2809 UPDATE
++ Incoming Queries ++
              193268 A
                 867 SOA
               42785 PTR
                2133 TXT
              163183 AAAA
                  77 SRV
                   1 ANY
++ Outgoing Queries ++
[View: internal]
              340624 A
                 113 NS
                1074 SOA
                4841 PTR
              355096 AAAA
                   9 SRV
[View: external]
[View: _bind]
++ Name Server Statistics ++
              398469 IPv4 requests received
                6654 IPv6 requests received
                2809 requests with TSIG received
              401980 responses sent
                2809 responses with TSIG sent
              251717 queries resulted in successful answer
              111484 queries resulted in authoritative answer
              261504 queries resulted in non authoritative answer
               74827 queries resulted in nxrrset
               26183 queries resulted in SERVFAIL
               46444 queries resulted in NXDOMAIN
              152350 queries caused recursion
                3140 duplicate queries received
                   3 queries dropped
                 111 updates completed
                2698 updates failed
                1349 updates rejected due to prerequisite failure
++ Zone Maintenance Statistics ++
++ Resolver Statistics ++
[Common]
[View: internal]
              585283 IPv4 queries sent
              116474 IPv6 queries sent
              380038 IPv4 responses received
               44285 IPv6 responses received
                2608 NXDOMAIN received
                3717 SERVFAIL received
                5346 FORMERR received
                 393 other errors received
                7043 EDNS(0) query failures
                  48 truncated responses received
                 317 lame delegations received
              299724 query retries
               34381 query timeouts
               76398 IPv4 NS address fetches
               66026 IPv6 NS address fetches
                2610 IPv4 NS address fetch failed
               51802 IPv6 NS address fetch failed
              257150 queries with RTT 10-100ms
              163983 queries with RTT 100-500ms
                 658 queries with RTT 500-800ms
                  15 queries with RTT 800-1600ms
[View: external]
[View: _bind]
++ Cache DB RRsets ++
[View: internal]
                1408 A
                 480 NS
                 120 CNAME
                   3 PTR
                 232 AAAA
                  23 DS
                 106 RRSIG
                  22 NSEC
                 154 !AAAA
                   7 NXDOMAIN
[View: external]
[View: _bind]
++ Socket I/O Statistics ++
              585337 UDP/IPv4 sockets opened
              116472 UDP/IPv6 sockets opened
                  47 TCP/IPv4 sockets opened
                   7 TCP/IPv6 sockets opened
              585335 UDP/IPv4 sockets closed
              116470 UDP/IPv6 sockets closed
                  46 TCP/IPv4 sockets closed
                   4 TCP/IPv6 sockets closed
                  96 UDP/IPv4 socket bind failures
              177278 UDP/IPv4 socket connect failures
              407961 UDP/IPv4 connections established
              116470 UDP/IPv6 connections established
                  27 TCP/IPv4 connections established
                   3 TCP/IPv6 connections established
                   3 TCP/IPv4 connections accepted
              177282 UDP/IPv4 send errors
               68226 UDP/IPv6 send errors
                2447 UDP/IPv4 recv errors
                  75 UDP/IPv6 recv errors
++ Per Zone Query Statistics ++
--- Statistics Dump --- (1306478640)
```
(Note, I'm running bind chroot'ed, hence the /var/named/var/stats/named.stats)

It's not queries per second but if you get the stats at regular intervals you can do the calculations yourself. Should be relatively easy to script something around it with perl for example.


----------



## w3nd377 (May 31, 2011)

I have that line in the conf file for Named.  However, I do not know PERL or any other scripting language..."Windows Bigot finding his love for *NIX systems"...

Additionally, if I was to attempt to quickly learn PERL to write the script, do you think it would be possible to determine who is querying and how many queries they do on a 24 hour period?  I assume attempting that would require pulling the stats file and the standard log file of the named service to compile for the answer...which would end up leading me back to finding a way to persuade the "powers above" to allow MRTG.  :\

Regardless, will start looking into learning PERL just to start making my life a little easier.


----------

