Skip to main content

Converts dnscrypt-proxy query_log TSV values to Prometheus-compatible metrics.

Project description

dnscrypt-proxy-logs-analyzer

Converts the dnscrypt-proxy query log into Prometheus metrics, suitable for the node_exporter textfile collector.

This is particularly useful on Debian 13 and similar distros, where dnscrypt-proxy is shipped without built-in Prometheus metrics and without the old --analyze-logs tool.

This script restores observability without replacing packages or running additional daemons.

Target audience: mostly me, probably future me, and maybe you.

Features

  • Designed for dnscrypt-proxy 2.1.x (as packaged by Debian/Ubuntu).
  • No daemon / no exporter HTTP listener — works via textfile collector.
  • Tracks per-qtype and per-upstream query stats.
  • Persists statistics across restarts (does not reset per run).
  • Requires zero logrotate configuration — logs are truncated automatically.
  • Zero external dependencies besides prometheus_client (and optionally argcomplete).

Install

pip install dnscrypt_proxy_logs_analyzer

Optinally, for CLI completion, install argcomplete package.

Requirements

Your dnscrypt-proxy must be configured to log TSV format, which this script parses.

Add to /etc/dnscrypt-proxy/dnscrypt-proxy.toml:

[query_log]
file = '/var/log/dnscrypt-proxy/query.log'
format = 'tsv' # REQUIRED

If you enable log rotation externally, disable truncation in this script with --no-trunc flag. By default the script truncates log file after processing.

Usage

dnscrypt-proxy-logs-analyzer \
  --query-log /var/log/dnscrypt-proxy/query.log \
  --output /var/lib/node_exporter/textfile_collector/dnscrypt-proxy.prom

After each run:

  • Metrics get updated.
  • The query log is truncated.

This makes it safe to run frequently, e.g., every 30 seconds.

systemd timer example

/etc/systemd/system/dnscrypt-proxy-logs-analyzer.service:

[Unit]
Description=Convert dnscrypt-proxy logs to Prometheus metrics
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/dnscrypt-proxy-logs-analyzer

/etc/systemd/system/dnscrypt-proxy-logs-analyzer.timer:

[Unit]
Description=Run dnscrypt-proxy log analyzer periodically

[Timer]
OnBootSec=30s
OnUnitActiveSec=1m
AccuracySec=10s
Unit=dnscrypt-proxy-logs-analyzer.service

[Install]
WantedBy=timers.target

Enable:

systemctl daemon-reload
systemctl enable --now dnscrypt-proxy-logs-analyzer.timer

Check logs for errors (no output by default):

journalctl -u dnscrypt-proxy-logs-analyzer.service -f

Output metrics

Query count

dnscrypt_proxy_queries_total{qtype="A",result="PASS",upstream="scaleway-fr-ipv6"} 42

Latency histogram in seconds

dnscrypt_proxy_latency_seconds_bucket{le="0.1",qtype="A",result="PASS",upstream="scaleway-fr-ipv6"} 18
dnscrypt_proxy_latency_seconds_sum{qtype="A",result="PASS",upstream="scaleway-fr-ipv6"} 0.283
dnscrypt_proxy_latency_seconds_count{qtype="A",result="PASS",upstream="scaleway-fr-ipv6"} 18

Query results tracked include: PASS, NXDOMAIN, NODATA, SERVFAIL, NETWORK_ERROR, TIMEOUT, etc.

Buckets are 0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0.

Self-health metrics

dnscrypt_proxy_logs_analyzer_last_run_timestamp 1.7614262632420218e+09
dnscrypt_proxy_logs_analyzer_last_run_success 1.0

Why this instead of built-in Prometheus metrics?

Because Debian’s dnscrypt-proxy build disables them.

This script provides:

  • Observability without replacing the resolver.
  • Persistent metrics (survive daemon restarts).
  • No running HTTP endpoint.
  • No daemon, no background process — runs on a schedule.

Philosophy

“Small, deterministic, zero-maintenance tools beat large monitoring stacks.”

License

MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dnscrypt_proxy_logs_analyzer-1.0.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dnscrypt_proxy_logs_analyzer-1.0.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file dnscrypt_proxy_logs_analyzer-1.0.0.tar.gz.

File metadata

File hashes

Hashes for dnscrypt_proxy_logs_analyzer-1.0.0.tar.gz
Algorithm Hash digest
SHA256 13a9743924e5ab86082c9b109e68ce375c3b17ddc5a010a5dc259cb607406274
MD5 991e6157bb7c390826982c15ea079ea3
BLAKE2b-256 9e5dde2640c08b255fd7fa38d5fa5482a331c748d1100ca8b9dae8b05e59613d

See more details on using hashes here.

File details

Details for the file dnscrypt_proxy_logs_analyzer-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dnscrypt_proxy_logs_analyzer-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 105d77fc0f8817bb283706d569122f77c524ac9359a772b69a70a7d1d2767582
MD5 2a2a73707305c319b000c0effb643507
BLAKE2b-256 25a0257fe4aa5c0d04eed162f7c3253bc300db192259ab2b5ed87d7951b78b6b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page