Skip to content
Contents
GuidesOpenWrt

Graph AdGuard Home queries, blocked requests and WAN upload in Grafana

Check an allowed and a blocked query, export the two window counts to Prometheus, then verify the WAN interface and sample time separately.

If your dashboard suddenly shows a thousand more blocked DNS queries, check the time window first. AdGuard Home counts queries and blocks within a moving window. WAN upload comes from the interface's cumulative byte counter. Label each series with its own unit.

Check one allowed and one blocked request in the query log

Open Query Log in AdGuard Home. From a client using it for DNS, look up an ordinary domain and a domain covered by a test rule. Search for each domain and expand its row to see the client, result and matching rule. If neither appears, check which DNS server the client uses and whether query logging is enabled. If both were allowed, open Filters → Custom filtering rules. Use a test client and remove the temporary rule afterwards.

Expand the blocked row in the isolated instance's query log to see which rule matched.

The recording shows an SSH session on an OpenWrt 25.12.6 virtual machine. In this fresh AdGuard Home instance the management port 15735 listens on loopback only and DNS listens on 15736. A synthetic upstream resolves news.sample.test to 192.0.2.48 and a custom rule returns NXDOMAIN for ads.sample.test. Run the commands on the router. Use your own addresses and authentication on an existing installation.

ubus call system board | jsonfilter -e "@.release.description"
stats() { wget -qO- http://127.0.0.1:15735/control/stats | jsonfilter -e "@.num_dns_queries" -e "@.num_blocked_filtering"; }
echo "queries / blocked"; stats
nslookup -type=A news.sample.test 127.0.0.1:15736
nslookup -type=A ads.sample.test 127.0.0.1:15736
echo "queries / blocked"; stats

In the recording the counts change from 0 and 0 to 2 and 1. A home network has other traffic, so match the time and domain in the query log. Disabled statistics or a different time window can change what you see.

Export the last successful reading on the collector

Use a Linux collector with curl, jq and Prometheus node_exporter. Confirm that node_exporter uses --collector.textfile.directory and substitute its actual directory below. Create a netrc file with mode 0600 containing the management hostname and credentials in curl's netrc format. Use trusted HTTPS. The collector account needs read access to the credentials and write access to the metrics directory. Test the script manually before running it once a minute.

#!/bin/sh
set -eu
dir=/var/lib/node_exporter/textfile_collector
tmp=$(mktemp "$dir/.adguard.XXXXXX")
trap 'rm -f "$tmp"' EXIT
stats=$(curl --fail --silent --show-error --max-time 10 --netrc-file /etc/adguard-metrics.netrc https://dns.home.example/control/stats)
printf '%s' "$stats" | jq -er '
  if ([.num_dns_queries, .num_blocked_filtering] | all(type == "number")) then
    "# HELP adguard_window_queries DNS queries in the configured statistics window.",
    "# TYPE adguard_window_queries gauge",
    "adguard_window_queries \(.num_dns_queries)",
    "# HELP adguard_window_blocked DNS queries blocked by filtering in this window.",
    "# TYPE adguard_window_blocked gauge",
    "adguard_window_blocked \(.num_blocked_filtering)"
  else error("missing statistics") end' > "$tmp"
printf '# HELP adguard_snapshot_unixtime_seconds Last successful sample.\n# TYPE adguard_snapshot_unixtime_seconds gauge\nadguard_snapshot_unixtime_seconds %s\n' "$(date +%s)" >> "$tmp"
chmod 0644 "$tmp"
mv "$tmp" "$dir/adguard.prom"

Replace the sample hostname with an address covered by the certificate. Check authentication for a 401 response. Keep the previous file if either numeric field is missing. Look for all three metrics at the collector's /metrics endpoint and check the scrape on the Prometheus Targets page. If values stay flat, compare time() - adguard_snapshot_unixtime_seconds in Grafana Explore with the expected interval. For an unreachable target also check up and missing metrics.

Plot counts and bandwidth separately in Grafana

Select the Prometheus data source in Explore and plot adguard_window_queries and adguard_window_blocked. Choose a count unit and describe the current window. For a percentage, use 100 * adguard_window_blocked / (adguard_window_queries > 0) for the same instance. The denominator must be positive. Both readings are gauges because old queries leave the window.

At the router's metrics endpoint, identify the WAN device, instance and transmitted byte counter. If node_exporter supplies the matching metric, use 8 * rate(node_network_transmit_bytes_total{instance="router:9100",device="wan"}[5m]) with the actual instance and device. Select bit/s. A counter from the collector's own interface cannot show router egress. Match the two test events to the next successful scrape. To retire the collector, disable its schedule, remove its dedicated metrics file and revoke its credentials. For router metrics, see Find the right temperature and traffic metrics for OpenWrt in Grafana 。

Send a query log sample to Loki

A Grafana Logs panel needs a log data source. On a Linux collector with access to AdGuard Home and an existing Loki instance, select a client you manage and a known test domain. Check the two recent records in Query Log. Replace news.sample.test with the test domain below and reuse the management address and netrc file from the previous step. Access Loki over controlled loopback or an authenticated private connection.

(
  set -eu
  umask 077
  sample_dir=$(mktemp -d)
  trap 'rm -f "$sample_dir/query.json" "$sample_dir/push.json"; rmdir "$sample_dir"' EXIT
  curl --fail --silent --show-error --max-time 10 --netrc-file /etc/adguard-metrics.netrc \
    --get --data-urlencode 'search=news.sample.test' --data-urlencode 'limit=2' \
    'https://dns.home.example/control/querylog' > "$sample_dir/query.json"
  python3 - "$sample_dir/query.json" > "$sample_dir/push.json" <<'PY'
import json, sys, time
with open(sys.argv[1]) as source:
    rows = json.load(source)["data"]
if not rows:
    raise SystemExit("No matching queries")
stamp = time.time_ns()
values = []
for index, row in enumerate(reversed(rows)):
    event = {"observed_at": row["time"], "rrtype": row["question"]["type"],
             "status": row["status"], "reason": row["reason"]}
    values.append([str(stamp + index), json.dumps(event)])
print(json.dumps({"streams": [{"stream": {"job": "adguard_check"}, "values": values}]}))
PY
  curl --fail --silent --show-error --max-time 10 --write-out '%{http_code}\n' \
    -H 'Content-Type: application/json' --data-binary @"$sample_dir/push.json" \
    http://127.0.0.1:3100/loki/api/v1/push
)

HTTP 204 means Loki accepted the batch. Add a Loki data source in Grafana with a URL reachable from the Grafana server. Create a Logs panel, query {job="adguard_check"} and select the last hour. Compare observed_at to the AdGuard Home query time. Inspect status and reason for the response type. The panel timestamps mark the import. Running the script twice imports the same historical events twice. Use it once for this check and keep it out of scheduled jobs.

The Grafana Logs panel displays allowed and blocked results from the isolated test.

The two result types shown come from saved synthetic queries in the isolated lab. Only the query time, record type, status and reason were imported. Client addresses, domain names and full responses were excluded from Loki. If the panel is empty, check the HTTP response, data source, label and time range. Continue to use the interface counter in Prometheus for upload rate. DNS logs contain no WAN byte count. Close the dedicated collection endpoint when finished and expire the logs under the test instance's retention policy.

Reference

Explore hardware

Comments