AdGuard Home DNS queries decreases hourly

I’ve got Home Assistant set up with the AdGuard Home integration, but I’m seeing some odd behaviour on the DNS queries sensor.

It appears that the total number of queries drops by about 1,000 every hour:

I’d only really expect this number to increase. I suspect it’s to do with the “Query logs retention” in AdGuard:

AdGuard Home Query logs retention setting, set to 90 days

Home Assistant seems to be basing this sensor on the total number of queries currently stored by AdGuard, meaning that it decreases as old logs are deleted. I can even see the graph plateau when the number of requests per day is consistent for long enough:

I assume there’s nothing I can do about this other than set up some other form of DNS monitoring (e.g. dnsmasq + Prometheus exporter)? It feels like this is something worth documenting on the AdGuard Home integration page, as you can end up with some weird values when using the statistics platform with these sensors.

Maybe you just misconfigured adguard.

Misconfigured in what way? There isn’t anything to configure on the Home Assistant side of things and I can’t see any obvious settings in AdGuard which would help with this.

Well I don’t know. From my experience with tuya wifi switches i can say that I had to add to dns1 and dns2 of my router settings ha ip address for adguard to work property. This is because if you ban those things from reporting to ccp they will use dns2 settings in router to do so.
I have it for years and never had this problem. As I remember i use my ha ip address for dns1 and dns2 settings in ha.
For adguard i use ssl on local network with some dns resolvers and dns rewrite for routing traffic trough adguard. What is the problem on your side it’s hard to tell. But I don’t have it and never seen this.

I don’t think any of that is related to the issue I’m seeing. AdGuard itself is working fine - the issue is just in the reporting in Home Assistant.

Looking at the code for AdGuard Home (specifically internal/stats), it seems like this is just a limitation of AdGuard itself - stats are always cleaned up after the configured duration and the total number of queries is calculated by summing up the stats from the database, meaning the total can decrease as stats are removed from the database during cleanup.

I’ll look at raising a PR against the integration docs, as this seems like something worth mentioning.

This is mine

That’s exhibiting the exact same issue I described in my original post (note the sawtooth shape of your graph).

AdGuard itself looks to be to blame - I’m just going to look at putting another DNS server in front of AdGuard which can calculate metrics consistently.

Something like dnsmasq with dnsmasq_exporter seems to be the best option. It won’t give the exact same numbers as AdGuard, as it can’t tell the difference between a request that was blocked by AdGuard and a request for a domain that doesn’t exist, but it will at least give consistent numbers.

I’m not that sure you are right about this. Noone is using my network currently except wifi devices. There is no comp connected, nothing.
I checked my history graph and I get the same results as you do but I’m not sure it’s the adguard isue. Maybe I’m wrong but I never noticed any stranke or odd behavoiur.