On most modern Linux machines, systemd-resolved sits between your programs and the DNS server and keeps a local cache. I always wondered how much that cache does, and it turns out resolved counts it for you.
One command prints the counters:
resolvectl statistics
sudo resolvectl reset-statistics
The output has a few blocks. Transactions shows Current Transactions and Total Transactions, how many DNS transactions resolved has handled. Cache shows Current Cache Size, Cache Hits and Cache Misses. DNSSEC Verdicts counts answers as Secure, Insecure, Bogus or Indeterminate. The second command sets all counters back to zero; the man page notes that it needs root.
Here’s how I’d use it. Reset the counters, use the machine normally for an hour, then run resolvectl statistics again. Divide the hits by hits plus misses and you have a hit rate. A low rate isn’t automatically bad (lots of new names, short TTLs), but if you’ve just pointed the machine at a slow resolver, it tells you how many lookups actually go over the wire. A Bogus count above zero is worth a look too: something failed DNSSEC validation, and resolvectl query on the suspect name shows more.
The caveat: resolved only counts what goes through resolved. A browser with its own DNS over HTTPS, a Docker container with its own DNS setting, or a tool that reads a hand-edited /etc/resolv.conf pointing elsewhere never shows up here. The counters also live in memory, so a restart of systemd-resolved starts them at zero again. The command has been in resolvectl since systemd 239.
Further reading: resolvectl(1) man page