-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add Prometheus metrics support for DNS query monitoring #7937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add Prometheus metrics support for DNS query monitoring #7937
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 To request another review, post a new comment with "/windsurf-review".
// Register metrics endpoint without control prefix, similar to /dns-query | ||
// Use empty method to bypass auth/gzip middleware like dns-query does | ||
httpRegister("", "/metrics", web.metricsHandler.ServeHTTP) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it makes sense to have the metrics endpoint unauthenticated like the /dns-query
endpoint for Prometheus scraping, it would be good to document the security considerations of exposing metrics without authentication. Consider adding a comment explaining what information is exposed and any potential security implications.
- Add prometheus/client_golang dependency - Initialize Prometheus registry with Go and process collectors - Expose metrics endpoint at /metrics (without auth, similar to /dns-query) - Set up base infrastructure for future DNS filtering metrics
- Create metrics/dns.go with counters for total and blocked queries - Integrate metrics collection in stats unit.add() method - Register DNS metrics in web API Prometheus registry - Add comprehensive tests for metrics functionality Metrics exposed: - adguard_dns_queries_total: Total DNS queries processed - adguard_dns_queries_by_result_total: Queries by result type (filtered, not_filtered, etc.) - adguard_dns_queries_blocked_total: Legacy metric for blocked queries The metrics mirror the dashboard counters exactly, providing real-time DNS query statistics for monitoring and alerting.
- Add native exponential histogram for DNS response times - Track response times by result type (filtered, not_filtered, etc.) - Use factor 1.1 for automatic bucket generation - Integrate with existing stats processing flow
2916d13
to
7058411
Compare
highly needed |
Yep. I'm running this custom build for months now. It works great. It would be fantastic to get a review! |
Do you have any updates on this? If there's interest in merging this, I will rebase. |
Closes #516
This PR implements native Prometheus metrics support for AdGuard Home, addressing the long-standing community request for built-in monitoring capabilities.
🚀 Features Added
/metrics
endpoint (unauthenticated, similar to/dns-query
)📊 Metrics Exposed
adguard_dns_queries_total{result}
- Total DNS queries by processing resultadguard_dns_response_time_seconds{result}
- DNS response time histograms🏗️ Implementation Details
internal/metrics/dns.go
with clean API for metric collectioninternal/stats/unit.go
)🔧 Technical Approach
1.1
for automatic bucket generation✅ Testing & Validation
Real Examples
I've deployed a binary with the changes in this PR on my NAS and put my home network's load on this instance.
Here we can see the
rate(adguard_dns_queries_total[5m])
query. It shows the requests per second grouped by result type:Here we can see a
1000 * histogram_quantile(0.75, sum by(result) (rate(adguard_dns_response_time_seconds[5m])))
query. It shows the milliseconds (hence1000 *
) over time. 75% of requests by result type are faster than the given duration and 25% are slower.