Statistics for average duration of forwarded requests?

There's data on each individual dns query's duration. This is especially interesting when they result from being forwarded to upstream dns servers:

query-time

Since Pi-hole offers lots of different upstream dns options (I currently have it running with BIND9 as a backend), it would be quite interesting to get statistical data about the average time of those backend dns resolutions. This way, we could use Google, Quad9 and the likes each for a day and compare average resolution times to select the fastest backend from this time on.

Since Pi-hole stores the data required for this anyway, is there a way to access it easily?

I hate doing things manually :wink:

https://docs.pi-hole.net/ftldns/dns-resolver/

Improve detection algorithm for determining the "best" forward destination

The DNS forward destination determination algorithm in FTL DNS's is modified to be much less restrictive than the original algorithm in dnsmasq . We keep using the fastest responding server now for 1000 queries or 10 minutes (whatever happens earlier) instead of 50 queries or 10 seconds (default values in dnsmasq ). We keep the exceptions, i.e., we try all possible forward destinations if SERVFAIL or REFUSED is received or if a timeout occurs. Overall, this change has proven to greatly reduce the number of actually performed queries in typical Pi-hole environments. It may even be understood as being preferential in terms of privacy (as we send queries much less often to all servers). This has been implemented in commit d1c163e on the FTLDNS branch.

I hate doing things manually :wink:

Oh, me too … :wink: But if I understand the link correctly, that's an automatic selection process for when more than one upstream DNS server has been selected, right? It doesn't seem to give any user feedback as far as statistics are concerned (apart from the representation in Dashboard where most of the queries got forwarded to).

Since I use my own DNS server both for recursion and local domain resolution (e.g. server.lan), I cannot select any regular upstream DNS servers as then I'd lose local resolution. Therefore, the only option would be to have both BIND9 and Unbound running locally and entered as custom upstream servers. Then Pi-hole would select the fastest, I guess, but not show me by how much they differ in response times. This would make proper debugging and experimentation with cache times and the likes essentially impossible.

A nice little statistics time output, on the other hand, would make that beautifully clear.

While FTLDNS will pick its fastest responding server from the set of configured upstream servers on its own, it indeed doesn't supply corresponding statistics.
Lack of this data does not allow the user to make an informed decision on what servers he actually wants to keep.

However, response time observations may vary over time, so it's probably best to base your upstream DNS server on other factors like privacy, encryption or additional filtering, according to your personal preferences.
Then put a few servers that fulfill your criteria on your upstream list and leave response time optimisation to Pi-hole.

As you seem interested in the statistics themselves:
Neither pihole.log nor the current long term database hold response times, unfortunately.
Response time seems to be calculated for recent queries as shown by the Dashboard's Query Log only - they are not shown for queries in Long term data | Query Log.
A developer might be able to add additional insights.

You could also consider making this into a feature request.

You can preserve local name resolution by using Conditional Forwarding. You'll find that option on the bottom of Settings | DNS

Thank you, I just did.

The idea of conditional forwarding is quite interesting, I have to say. Will dig more into this ...

EDIT: moved my reply to here: