Skip to content

Commit 8809b70

Browse files
committed
metrics: add prometheus-based libp2p and awl-specific metrics
1 parent dfff5e3 commit 8809b70

19 files changed

Lines changed: 603 additions & 20 deletions

File tree

api/api.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/go-playground/validator/v10"
1414
"github.com/ipfs/go-log/v2"
15+
"github.com/labstack/echo-contrib/echoprometheus"
1516
"github.com/labstack/echo/v4"
1617
"github.com/labstack/echo/v4/middleware"
1718

@@ -79,6 +80,10 @@ func (h *Handler) SetupAPI() error {
7980
return nil
8081
}
8182

83+
// use global to register metric only once
84+
var metricsMiddleware = echoprometheus.NewMiddleware("awl")
85+
var metricsHandler = echoprometheus.NewHandler()
86+
8287
func (h *Handler) setupRouter(address string) (*echo.Echo, error) {
8388
e := echo.New()
8489
e.HideBanner = true
@@ -98,6 +103,10 @@ func (h *Handler) setupRouter(address string) (*echo.Echo, error) {
98103

99104
// Routes
100105

106+
// Metrics
107+
e.Use(metricsMiddleware)
108+
e.GET("/metrics", metricsHandler)
109+
101110
// Peers
102111
e.GET(GetKnownPeersPath, h.GetKnownPeers)
103112
e.POST(GetKnownPeerSettingsPath, h.GetKnownPeerSettings)

application.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ import (
1919
dssync "github.com/ipfs/go-datastore/sync"
2020
"github.com/ipfs/go-log/v2"
2121
"github.com/libp2p/go-libp2p"
22+
"github.com/libp2p/go-libp2p/core/peer"
2223
"github.com/libp2p/go-libp2p/p2p/host/eventbus"
2324
"github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoremem"
2425
rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
26+
"github.com/prometheus/client_golang/prometheus"
2527
"go.uber.org/zap"
2628
"go.uber.org/zap/zapcore"
2729
"golang.zx2c4.com/wireguard/tun"
@@ -30,6 +32,7 @@ import (
3032
"github.com/anywherelan/awl/awldns"
3133
"github.com/anywherelan/awl/awlevent"
3234
"github.com/anywherelan/awl/config"
35+
"github.com/anywherelan/awl/metrics"
3336
"github.com/anywherelan/awl/p2p"
3437
"github.com/anywherelan/awl/protocol"
3538
"github.com/anywherelan/awl/ringbuffer"
@@ -160,6 +163,11 @@ func (a *Application) Init(ctx context.Context, tunDevice tun.Device) error {
160163
}
161164
}
162165

166+
// Metrics
167+
metrics.SetNodeInfo(config.Version, p2pHost.ID().String())
168+
cma := &configMetricsAdapter{conf: a.Conf, authStatus: a.AuthStatus, p2p: a.P2p}
169+
go metrics.StartBackgroundUpdater(a.ctx, cma, a.P2p)
170+
163171
a.logger.Info("Application initialized successfully")
164172

165173
return nil
@@ -288,6 +296,7 @@ func (a *Application) makeP2pHostConfig() p2p.HostConfig {
288296
libp2p.ResourceManager(mgr),
289297
libp2p.EnableHolePunching(),
290298
libp2p.NATPortMap(),
299+
libp2p.PrometheusRegisterer(prometheus.DefaultRegisterer),
291300
}, a.ExtraLibp2pOpts...),
292301
ConnManager: struct {
293302
LowWater int
@@ -414,3 +423,38 @@ func (a *DNSService) AwlDNSAddress() string {
414423
func (a *DNSService) IsAwlDNSSetAsSystem() bool {
415424
return a.isAwlDNSSetAsSystem
416425
}
426+
427+
// configMetricsAdapter implements metrics.ConfigMetrics by combining Config and AuthStatus.
428+
type configMetricsAdapter struct {
429+
conf *config.Config
430+
authStatus *service.AuthStatus
431+
p2p *p2p.P2p
432+
}
433+
434+
func (a *configMetricsAdapter) GetKnownPeersSnapshot() (total, confirmed, connected int, peerIDs []peer.ID) {
435+
a.conf.RLock()
436+
defer a.conf.RUnlock()
437+
total = len(a.conf.KnownPeers)
438+
peerIDs = make([]peer.ID, 0, total)
439+
for _, kp := range a.conf.KnownPeers {
440+
pid := kp.PeerId()
441+
peerIDs = append(peerIDs, pid)
442+
if kp.Confirmed {
443+
confirmed++
444+
}
445+
if a.p2p.IsConnected(pid) {
446+
connected++
447+
}
448+
}
449+
return
450+
}
451+
452+
func (a *configMetricsAdapter) GetBlockedPeersCount() int {
453+
a.conf.RLock()
454+
defer a.conf.RUnlock()
455+
return len(a.conf.BlockedPeers)
456+
}
457+
458+
func (a *configMetricsAdapter) GetAuthRequestCounts() (ingoing, outgoing int) {
459+
return a.authStatus.GetAuthRequestCounts()
460+
}

application_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,3 +881,36 @@ func BenchmarkTunnelPackets(b *testing.B) {
881881
})
882882
}
883883
}
884+
885+
func TestMetricsEndpoint(t *testing.T) {
886+
// NOTE: all tests use the same metrics register - so we can't rely on metrics values here
887+
ts := NewTestSuite(t)
888+
889+
peer1 := ts.NewTestPeer(true)
890+
891+
// Make some API requests first so counter metrics get populated
892+
_, _ = peer1.api.PeerInfo()
893+
894+
// Query the /metrics endpoint
895+
metricsURL := fmt.Sprintf("http://%s/metrics", peer1.app.Api.Address())
896+
resp, err := http.Get(metricsURL)
897+
ts.NoError(err)
898+
defer resp.Body.Close()
899+
900+
ts.Equal(http.StatusOK, resp.StatusCode)
901+
902+
body, err := io.ReadAll(resp.Body)
903+
ts.NoError(err)
904+
905+
metricsOutput := string(body)
906+
907+
// Verify AWL-specific metrics are present
908+
ts.Contains(metricsOutput, "awl_node_info")
909+
ts.Contains(metricsOutput, "awl_node_start_timestamp")
910+
ts.Contains(metricsOutput, "awl_node_uptime_seconds")
911+
ts.Contains(metricsOutput, "awl_peers_known_total")
912+
ts.Contains(metricsOutput, "awl_api_requests_in_flight")
913+
914+
// Verify libp2p built-in metrics are present
915+
ts.Contains(metricsOutput, "libp2p_")
916+
}

awldns/awldns.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99

1010
"github.com/ipfs/go-log/v2"
1111
"github.com/miekg/dns"
12+
13+
"github.com/anywherelan/awl/metrics"
1214
)
1315

1416
const (
@@ -142,6 +144,12 @@ func (r *Resolver) Close() {
142144
}
143145

144146
func (r *Resolver) dnsLocalDomainHandler(resp dns.ResponseWriter, req *dns.Msg) {
147+
metrics.DNSQueriesTotal.WithLabelValues("awl").Inc()
148+
start := time.Now()
149+
defer func() {
150+
metrics.DNSQueryDurationSeconds.Observe(time.Since(start).Seconds())
151+
}()
152+
145153
if len(req.Question) == 0 {
146154
return
147155
}
@@ -183,6 +191,12 @@ func (r *Resolver) dnsLocalDomainHandler(resp dns.ResponseWriter, req *dns.Msg)
183191
}
184192

185193
func (r *Resolver) ptrv4Handler(resp dns.ResponseWriter, req *dns.Msg) {
194+
metrics.DNSQueriesTotal.WithLabelValues("awl_ptr").Inc()
195+
start := time.Now()
196+
defer func() {
197+
metrics.DNSQueryDurationSeconds.Observe(time.Since(start).Seconds())
198+
}()
199+
186200
if len(req.Question) == 0 || req.Question[0].Qtype != dns.TypePTR {
187201
r.dnsProxyHandler(resp, req)
188202
return
@@ -222,6 +236,12 @@ func (r *Resolver) ptrv4Handler(resp dns.ResponseWriter, req *dns.Msg) {
222236
}
223237

224238
func (r *Resolver) dnsProxyHandler(resp dns.ResponseWriter, req *dns.Msg) {
239+
metrics.DNSQueriesTotal.WithLabelValues("proxy").Inc()
240+
start := time.Now()
241+
defer func() {
242+
metrics.DNSQueryDurationSeconds.Observe(time.Since(start).Seconds())
243+
}()
244+
225245
cfg := r.loadConfig()
226246

227247
dnsClient := r.udpClient
@@ -231,6 +251,7 @@ func (r *Resolver) dnsProxyHandler(resp dns.ResponseWriter, req *dns.Msg) {
231251

232252
upstreamResp, _, err := dnsClient.Exchange(req, cfg.upstreamDNS)
233253
if err != nil {
254+
metrics.DNSQueryErrorsTotal.Inc()
234255
r.logger.Warnf("send request to upstream dns: %v", err)
235256
m := new(dns.Msg)
236257
m.SetRcode(req, dns.RcodeServerFailure)

cmd/awl-tray/go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ require (
6666
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 // indirect
6767
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
6868
github.com/koron/go-ssdp v0.0.6 // indirect
69-
github.com/labstack/echo/v4 v4.14.0 // indirect
69+
github.com/labstack/echo-contrib v0.50.1 // indirect
70+
github.com/labstack/echo/v4 v4.15.0 // indirect
7071
github.com/labstack/gommon v0.4.2 // indirect
7172
github.com/leodido/go-urn v1.4.0 // indirect
7273
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
@@ -128,8 +129,8 @@ require (
128129
github.com/polydawn/refmt v0.89.0 // indirect
129130
github.com/prometheus/client_golang v1.23.2 // indirect
130131
github.com/prometheus/client_model v0.6.2 // indirect
131-
github.com/prometheus/common v0.66.1 // indirect
132-
github.com/prometheus/procfs v0.17.0 // indirect
132+
github.com/prometheus/common v0.67.5 // indirect
133+
github.com/prometheus/procfs v0.19.2 // indirect
133134
github.com/quic-go/qpack v0.6.0 // indirect
134135
github.com/quic-go/quic-go v0.59.0 // indirect
135136
github.com/quic-go/webtransport-go v0.10.0 // indirect

cmd/awl-tray/go.sum

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 h1:elKwZS1OcdQ0
122122
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86/go.mod h1:aFAMtuldEgx/4q7iSGazk22+IcgvtiC+HIimFO9XlS8=
123123
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
124124
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
125+
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
126+
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
125127
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
126128
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
127129
github.com/koron/go-ssdp v0.0.6 h1:Jb0h04599eq/CY7rB5YEqPS83HmRfHP2azkxMN2rFtU=
@@ -133,8 +135,12 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
133135
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
134136
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
135137
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
136-
github.com/labstack/echo/v4 v4.14.0 h1:+tiMrDLxwv6u0oKtD03mv+V1vXXB3wCqPHJqPuIe+7M=
137-
github.com/labstack/echo/v4 v4.14.0/go.mod h1:xmw1clThob0BSVRX1CRQkGQ/vjwcpOMjQZSZa9fKA/c=
138+
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
139+
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
140+
github.com/labstack/echo-contrib v0.50.1 h1:W9cZZ9viA4TDdFtm8cuA+XGFwOcnfbjJpl7VgfsRLHE=
141+
github.com/labstack/echo-contrib v0.50.1/go.mod h1:8r/++U/Fw/QniApFnzunLanKaviPfBX7fX7/2QX0qOk=
142+
github.com/labstack/echo/v4 v4.15.0 h1:hoRTKWcnR5STXZFe9BmYun9AMTNeSbjHi2vtDuADJ24=
143+
github.com/labstack/echo/v4 v4.15.0/go.mod h1:xmw1clThob0BSVRX1CRQkGQ/vjwcpOMjQZSZa9fKA/c=
138144
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
139145
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
140146
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
@@ -277,10 +283,10 @@ github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h
277283
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
278284
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
279285
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
280-
github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9ZoGs=
281-
github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA=
282-
github.com/prometheus/procfs v0.17.0 h1:FuLQ+05u4ZI+SS/w9+BWEM2TXiHKsUQ9TADiRH7DuK0=
283-
github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUOVhe0wYB2zw=
286+
github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4=
287+
github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw=
288+
github.com/prometheus/procfs v0.19.2 h1:zUMhqEW66Ex7OXIiDkll3tl9a1ZdilUOd/F6ZXw4Vws=
289+
github.com/prometheus/procfs v0.19.2/go.mod h1:M0aotyiemPhBCM0z5w87kL22CxfcH05ZpYlu+b4J7mw=
284290
github.com/pymq/zenity v0.0.0-20230509161854-c117c448544d h1:vrhQkfRgAGr/dUCtJ3bUg16FbHjw6Yl8CKz0eF9NdeM=
285291
github.com/pymq/zenity v0.0.0-20230509161854-c117c448544d/go.mod h1:FzjqP1loicusCFJTdIt5Oqbmoj2zySHpM0RsgJeeCbk=
286292
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=

go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ require (
1515
github.com/haxii/socks5 v1.0.0
1616
github.com/ipfs/go-datastore v0.9.0
1717
github.com/ipfs/go-log/v2 v2.9.1
18-
github.com/labstack/echo/v4 v4.14.0
18+
github.com/labstack/echo-contrib v0.50.1
19+
github.com/labstack/echo/v4 v4.15.0
1920
github.com/libp2p/go-libp2p v0.47.0
2021
github.com/libp2p/go-libp2p-kad-dht v0.37.1
2122
github.com/libp2p/go-libp2p-kbucket v0.8.0
@@ -27,6 +28,7 @@ require (
2728
github.com/multiformats/go-multiaddr v0.16.1
2829
github.com/multiformats/go-multistream v0.6.1
2930
github.com/olekukonko/tablewriter v0.0.5
31+
github.com/prometheus/client_golang v1.23.2
3032
github.com/quic-go/quic-go v0.59.0
3133
github.com/stretchr/testify v1.11.1
3234
github.com/urfave/cli/v2 v2.27.7
@@ -123,10 +125,9 @@ require (
123125
github.com/pion/webrtc/v4 v4.1.2 // indirect
124126
github.com/pmezard/go-difflib v1.0.0 // indirect
125127
github.com/polydawn/refmt v0.89.0 // indirect
126-
github.com/prometheus/client_golang v1.23.2 // indirect
127128
github.com/prometheus/client_model v0.6.2 // indirect
128-
github.com/prometheus/common v0.66.1 // indirect
129-
github.com/prometheus/procfs v0.17.0 // indirect
129+
github.com/prometheus/common v0.67.5 // indirect
130+
github.com/prometheus/procfs v0.19.2 // indirect
130131
github.com/quic-go/qpack v0.6.0 // indirect
131132
github.com/quic-go/webtransport-go v0.10.0 // indirect
132133
github.com/russross/blackfriday/v2 v2.1.0 // indirect

go.sum

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 h1:elKwZS1OcdQ0
101101
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86/go.mod h1:aFAMtuldEgx/4q7iSGazk22+IcgvtiC+HIimFO9XlS8=
102102
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
103103
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
104+
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
105+
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
104106
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
105107
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
106108
github.com/koron/go-ssdp v0.0.6 h1:Jb0h04599eq/CY7rB5YEqPS83HmRfHP2azkxMN2rFtU=
@@ -112,8 +114,12 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
112114
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
113115
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
114116
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
115-
github.com/labstack/echo/v4 v4.14.0 h1:+tiMrDLxwv6u0oKtD03mv+V1vXXB3wCqPHJqPuIe+7M=
116-
github.com/labstack/echo/v4 v4.14.0/go.mod h1:xmw1clThob0BSVRX1CRQkGQ/vjwcpOMjQZSZa9fKA/c=
117+
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
118+
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
119+
github.com/labstack/echo-contrib v0.50.1 h1:W9cZZ9viA4TDdFtm8cuA+XGFwOcnfbjJpl7VgfsRLHE=
120+
github.com/labstack/echo-contrib v0.50.1/go.mod h1:8r/++U/Fw/QniApFnzunLanKaviPfBX7fX7/2QX0qOk=
121+
github.com/labstack/echo/v4 v4.15.0 h1:hoRTKWcnR5STXZFe9BmYun9AMTNeSbjHi2vtDuADJ24=
122+
github.com/labstack/echo/v4 v4.15.0/go.mod h1:xmw1clThob0BSVRX1CRQkGQ/vjwcpOMjQZSZa9fKA/c=
117123
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
118124
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
119125
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
@@ -254,10 +260,10 @@ github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h
254260
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
255261
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
256262
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
257-
github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9ZoGs=
258-
github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA=
259-
github.com/prometheus/procfs v0.17.0 h1:FuLQ+05u4ZI+SS/w9+BWEM2TXiHKsUQ9TADiRH7DuK0=
260-
github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUOVhe0wYB2zw=
263+
github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4=
264+
github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw=
265+
github.com/prometheus/procfs v0.19.2 h1:zUMhqEW66Ex7OXIiDkll3tl9a1ZdilUOd/F6ZXw4Vws=
266+
github.com/prometheus/procfs v0.19.2/go.mod h1:M0aotyiemPhBCM0z5w87kL22CxfcH05ZpYlu+b4J7mw=
261267
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
262268
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
263269
github.com/quic-go/quic-go v0.59.0 h1:OLJkp1Mlm/aS7dpKgTc6cnpynnD2Xg7C1pwL6vy/SAw=

metrics/dns.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package metrics
2+
3+
import (
4+
"github.com/prometheus/client_golang/prometheus"
5+
"github.com/prometheus/client_golang/prometheus/promauto"
6+
)
7+
8+
var (
9+
DNSQueriesTotal = promauto.NewCounterVec(prometheus.CounterOpts{
10+
Namespace: namespace,
11+
Subsystem: "dns",
12+
Name: "queries_total",
13+
Help: "Total DNS queries handled.",
14+
}, []string{"handler"})
15+
16+
DNSQueryErrorsTotal = promauto.NewCounter(prometheus.CounterOpts{
17+
Namespace: namespace,
18+
Subsystem: "dns",
19+
Name: "query_errors_total",
20+
Help: "Total DNS query errors (upstream failures).",
21+
})
22+
23+
DNSQueryDurationSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
24+
Namespace: namespace,
25+
Subsystem: "dns",
26+
Name: "query_duration_seconds",
27+
Help: "DNS query duration in seconds.",
28+
Buckets: []float64{0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 10},
29+
})
30+
)

0 commit comments

Comments
 (0)