all: query statistics
This commit is contained in:
parent
6633ad6304
commit
4795a2c8fb
3
go.mod
3
go.mod
|
@ -3,7 +3,8 @@ module github.com/AdguardTeam/AdGuardHome
|
|||
go 1.23.5
|
||||
|
||||
require (
|
||||
github.com/AdguardTeam/dnsproxy v0.73.5
|
||||
// TODO!!
|
||||
github.com/AdguardTeam/dnsproxy v0.74.2-0.20250116174805-966cabfa8953
|
||||
github.com/AdguardTeam/golibs v0.31.0
|
||||
github.com/AdguardTeam/urlfilter v0.20.0
|
||||
github.com/NYTimes/gziphandler v1.1.1
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,5 +1,5 @@
|
|||
github.com/AdguardTeam/dnsproxy v0.73.5 h1:3EiVaTfmuW6PcJGbqloR6ZdHACsrYkm9z0eH8ZQTZnQ=
|
||||
github.com/AdguardTeam/dnsproxy v0.73.5/go.mod h1:Oqw+k7LyjDObfYzXYCkpgtirbzbUrmotr92jrb3N09I=
|
||||
github.com/AdguardTeam/dnsproxy v0.74.2-0.20250116174805-966cabfa8953 h1:oWKRUtLrKqUO0g3Vh/uEvuxH4wpqh5mV2r7fwqmABF8=
|
||||
github.com/AdguardTeam/dnsproxy v0.74.2-0.20250116174805-966cabfa8953/go.mod h1:Oqw+k7LyjDObfYzXYCkpgtirbzbUrmotr92jrb3N09I=
|
||||
github.com/AdguardTeam/golibs v0.31.0 h1:Z0oPfLTLw6iZmpE58dePy2Bel0MaX+lnDwtFEE5EmIo=
|
||||
github.com/AdguardTeam/golibs v0.31.0/go.mod h1:wIkZ9o2UnppeW6/YD7yJB71dYbMhiuC1Fh/I2ElW7GQ=
|
||||
github.com/AdguardTeam/urlfilter v0.20.0 h1:X32qiuVCVd8WDYCEsbdZKfXMzwdVqrdulamtUi4rmzs=
|
||||
|
|
|
@ -122,9 +122,14 @@ func (s *Server) logQuery(dctx *dnsContext, ip net.IP, processingTime time.Durat
|
|||
|
||||
if pctx.Upstream != nil {
|
||||
p.Upstream = pctx.Upstream.Address()
|
||||
} else if cachedUps := pctx.CachedUpstreamAddr; cachedUps != "" {
|
||||
p.Upstream = pctx.CachedUpstreamAddr
|
||||
p.Cached = true
|
||||
}
|
||||
|
||||
if qs := pctx.QueryStatistics(); qs != nil {
|
||||
ms := qs.Main()
|
||||
if len(ms) == 1 && ms[0].IsCached {
|
||||
p.Upstream = ms[0].Address
|
||||
p.Cached = true
|
||||
}
|
||||
}
|
||||
|
||||
s.queryLog.Add(p)
|
||||
|
@ -138,11 +143,10 @@ func (s *Server) updateStats(dctx *dnsContext, clientIP string, processingTime t
|
|||
Domain: aghnet.NormalizeDomain(pctx.Req.Question[0].Name),
|
||||
Result: stats.RNotFiltered,
|
||||
ProcessingTime: processingTime,
|
||||
UpstreamTime: pctx.QueryDuration,
|
||||
}
|
||||
|
||||
if pctx.Upstream != nil {
|
||||
e.Upstream = pctx.Upstream.Address()
|
||||
e.Upstream, e.UpstreamTime = upstreamDur(pctx)
|
||||
}
|
||||
|
||||
if clientID := dctx.clientID; clientID != "" {
|
||||
|
@ -167,3 +171,32 @@ func (s *Server) updateStats(dctx *dnsContext, clientIP string, processingTime t
|
|||
|
||||
s.stats.Update(e)
|
||||
}
|
||||
|
||||
// upstreamDur returns the upstream DNS server address and the DNS lookup
|
||||
// duration. If the upstream address is empty, it means the request was served
|
||||
// from the cache.
|
||||
func upstreamDur(pctx *proxy.DNSContext) (upstream string, dur time.Duration) {
|
||||
if pctx.Upstream == nil {
|
||||
return "", 0
|
||||
}
|
||||
|
||||
qs := pctx.QueryStatistics()
|
||||
if qs == nil {
|
||||
return "", 0
|
||||
}
|
||||
|
||||
addr := pctx.Upstream.Address()
|
||||
for _, u := range qs.Main() {
|
||||
if u.Address == addr {
|
||||
return u.Address, u.QueryDuration
|
||||
}
|
||||
}
|
||||
|
||||
for _, u := range qs.Fallback() {
|
||||
if u.Address == addr {
|
||||
return u.Address, u.QueryDuration
|
||||
}
|
||||
}
|
||||
|
||||
return "", 0
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue