Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ Tip: you can force using config file in the same directory with executable by cr

It is not recommended to amend config file while application is still running.

## Monitoring

AWL includes built-in Prometheus metrics support. You can access the metrics endpoint at `http://localhost:8639/metrics`.

A pre-packaged monitoring stack with Prometheus and Grafana dashboards is available in the [monitoring/](monitoring/) directory. See [monitoring/README.md](monitoring/README.md) for setup instructions.

## Terminal based client

Both `awl` and `awl-tray` versions have CLI to communicate with vpn server.
Expand Down Expand Up @@ -262,12 +268,6 @@ systemctl restart awl

As alternative, on Desktop/Server you can download new version from [releases page](https://github.com/anywherelan/awl/releases) and manually replace old files with new ones.

# Roadmap

- performance improvements for vpn tunnel protocol
- exit nodes - let you route all internet traffic through other peers
- add support for awl dns for android ([#17](https://github.com/anywherelan/awl/issues/17))

# Contributing

Contributions to this repository are very welcome.
Expand Down
14 changes: 14 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/go-playground/validator/v10"
"github.com/ipfs/go-log/v2"
"github.com/labstack/echo-contrib/echoprometheus"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"

Expand Down Expand Up @@ -79,6 +80,15 @@ func (h *Handler) SetupAPI() error {
return nil
}

// use global to register metric only once
var metricsMiddleware = echoprometheus.NewMiddlewareWithConfig(
echoprometheus.MiddlewareConfig{
Namespace: "awl",
Subsystem: "api",
},
)
var metricsHandler = echoprometheus.NewHandler()

func (h *Handler) setupRouter(address string) (*echo.Echo, error) {
e := echo.New()
e.HideBanner = true
Expand All @@ -98,6 +108,10 @@ func (h *Handler) setupRouter(address string) (*echo.Echo, error) {

// Routes

// Metrics
e.Use(metricsMiddleware)
e.GET("/metrics", metricsHandler)

// Peers
e.GET(GetKnownPeersPath, h.GetKnownPeers)
e.POST(GetKnownPeerSettingsPath, h.GetKnownPeerSettings)
Expand Down
44 changes: 44 additions & 0 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import (
dssync "github.com/ipfs/go-datastore/sync"
"github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/p2p/host/eventbus"
"github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoremem"
rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"golang.zx2c4.com/wireguard/tun"
Expand All @@ -30,6 +32,7 @@ import (
"github.com/anywherelan/awl/awldns"
"github.com/anywherelan/awl/awlevent"
"github.com/anywherelan/awl/config"
"github.com/anywherelan/awl/metrics"
"github.com/anywherelan/awl/p2p"
"github.com/anywherelan/awl/protocol"
"github.com/anywherelan/awl/ringbuffer"
Expand Down Expand Up @@ -160,6 +163,11 @@ func (a *Application) Init(ctx context.Context, tunDevice tun.Device) error {
}
}

// Metrics
metrics.SetNodeInfo(config.Version, p2pHost.ID().String())
cma := &configMetricsAdapter{conf: a.Conf, authStatus: a.AuthStatus, p2p: a.P2p}
go metrics.StartBackgroundUpdater(a.ctx, cma, a.P2p)

a.logger.Info("Application initialized successfully")

return nil
Expand Down Expand Up @@ -288,6 +296,7 @@ func (a *Application) makeP2pHostConfig() p2p.HostConfig {
libp2p.ResourceManager(mgr),
libp2p.EnableHolePunching(),
libp2p.NATPortMap(),
libp2p.PrometheusRegisterer(prometheus.DefaultRegisterer),
}, a.ExtraLibp2pOpts...),
ConnManager: struct {
LowWater int
Expand Down Expand Up @@ -414,3 +423,38 @@ func (a *DNSService) AwlDNSAddress() string {
func (a *DNSService) IsAwlDNSSetAsSystem() bool {
return a.isAwlDNSSetAsSystem
}

// configMetricsAdapter implements metrics.ConfigMetrics by combining Config and AuthStatus.
type configMetricsAdapter struct {
conf *config.Config
authStatus *service.AuthStatus
p2p *p2p.P2p
}

func (a *configMetricsAdapter) GetKnownPeersSnapshot() (total, confirmed, connected int, peerIDs []peer.ID) {
a.conf.RLock()
defer a.conf.RUnlock()
total = len(a.conf.KnownPeers)
peerIDs = make([]peer.ID, 0, total)
for _, kp := range a.conf.KnownPeers {
pid := kp.PeerId()
peerIDs = append(peerIDs, pid)
if kp.Confirmed {
confirmed++
}
if a.p2p.IsConnected(pid) {
connected++
}
}
return
}

func (a *configMetricsAdapter) GetBlockedPeersCount() int {
a.conf.RLock()
defer a.conf.RUnlock()
return len(a.conf.BlockedPeers)
}

func (a *configMetricsAdapter) GetAuthRequestCounts() (ingoing, outgoing int) {
return a.authStatus.GetAuthRequestCounts()
}
33 changes: 33 additions & 0 deletions application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,3 +881,36 @@ func BenchmarkTunnelPackets(b *testing.B) {
})
}
}

func TestMetricsEndpoint(t *testing.T) {
// NOTE: all tests use the same metrics register - so we can't rely on metrics values here
ts := NewTestSuite(t)

peer1 := ts.NewTestPeer(true)

// Make some API requests first so counter metrics get populated
_, _ = peer1.api.PeerInfo()

// Query the /metrics endpoint
metricsURL := fmt.Sprintf("http://%s/metrics", peer1.app.Api.Address())
resp, err := http.Get(metricsURL) //nolint:gosec
ts.NoError(err)
defer resp.Body.Close()

ts.Equal(http.StatusOK, resp.StatusCode)

body, err := io.ReadAll(resp.Body)
ts.NoError(err)

metricsOutput := string(body)

// Verify AWL-specific metrics are present
ts.Contains(metricsOutput, "awl_node_info")
ts.Contains(metricsOutput, "awl_node_start_timestamp")
ts.Contains(metricsOutput, "awl_node_uptime_seconds")
ts.Contains(metricsOutput, "awl_peers_known_total")
ts.Contains(metricsOutput, "awl_api_request_duration_seconds_bucket")

// Verify libp2p built-in metrics are present
ts.Contains(metricsOutput, "libp2p_")
}
21 changes: 21 additions & 0 deletions awldns/awldns.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/ipfs/go-log/v2"
"github.com/miekg/dns"

"github.com/anywherelan/awl/metrics"
)

const (
Expand Down Expand Up @@ -142,6 +144,12 @@ func (r *Resolver) Close() {
}

func (r *Resolver) dnsLocalDomainHandler(resp dns.ResponseWriter, req *dns.Msg) {
metrics.DNSQueriesTotal.WithLabelValues("awl").Inc()
start := time.Now()
defer func() {
metrics.DNSQueryDurationSeconds.Observe(time.Since(start).Seconds())
}()

if len(req.Question) == 0 {
return
}
Expand Down Expand Up @@ -183,6 +191,12 @@ func (r *Resolver) dnsLocalDomainHandler(resp dns.ResponseWriter, req *dns.Msg)
}

func (r *Resolver) ptrv4Handler(resp dns.ResponseWriter, req *dns.Msg) {
metrics.DNSQueriesTotal.WithLabelValues("awl_ptr").Inc()
start := time.Now()
defer func() {
metrics.DNSQueryDurationSeconds.Observe(time.Since(start).Seconds())
}()

if len(req.Question) == 0 || req.Question[0].Qtype != dns.TypePTR {
r.dnsProxyHandler(resp, req)
return
Expand Down Expand Up @@ -222,6 +236,12 @@ func (r *Resolver) ptrv4Handler(resp dns.ResponseWriter, req *dns.Msg) {
}

func (r *Resolver) dnsProxyHandler(resp dns.ResponseWriter, req *dns.Msg) {
metrics.DNSQueriesTotal.WithLabelValues("proxy").Inc()
start := time.Now()
defer func() {
metrics.DNSQueryDurationSeconds.Observe(time.Since(start).Seconds())
}()

cfg := r.loadConfig()

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

upstreamResp, _, err := dnsClient.Exchange(req, cfg.upstreamDNS)
if err != nil {
metrics.DNSQueryErrorsTotal.Inc()
r.logger.Warnf("send request to upstream dns: %v", err)
m := new(dns.Msg)
m.SetRcode(req, dns.RcodeServerFailure)
Expand Down
7 changes: 4 additions & 3 deletions cmd/awl-tray/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ require (
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/koron/go-ssdp v0.0.6 // indirect
github.com/labstack/echo/v4 v4.14.0 // indirect
github.com/labstack/echo-contrib v0.50.1 // indirect
github.com/labstack/echo/v4 v4.15.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
Expand Down Expand Up @@ -128,8 +129,8 @@ require (
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_golang v1.23.2 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.66.1 // indirect
github.com/prometheus/procfs v0.17.0 // indirect
github.com/prometheus/common v0.67.5 // indirect
github.com/prometheus/procfs v0.19.2 // indirect
github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/quic-go v0.59.0 // indirect
github.com/quic-go/webtransport-go v0.10.0 // indirect
Expand Down
18 changes: 12 additions & 6 deletions cmd/awl-tray/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 h1:elKwZS1OcdQ0
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86/go.mod h1:aFAMtuldEgx/4q7iSGazk22+IcgvtiC+HIimFO9XlS8=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/koron/go-ssdp v0.0.6 h1:Jb0h04599eq/CY7rB5YEqPS83HmRfHP2azkxMN2rFtU=
Expand All @@ -133,8 +135,12 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/labstack/echo/v4 v4.14.0 h1:+tiMrDLxwv6u0oKtD03mv+V1vXXB3wCqPHJqPuIe+7M=
github.com/labstack/echo/v4 v4.14.0/go.mod h1:xmw1clThob0BSVRX1CRQkGQ/vjwcpOMjQZSZa9fKA/c=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/labstack/echo-contrib v0.50.1 h1:W9cZZ9viA4TDdFtm8cuA+XGFwOcnfbjJpl7VgfsRLHE=
github.com/labstack/echo-contrib v0.50.1/go.mod h1:8r/++U/Fw/QniApFnzunLanKaviPfBX7fX7/2QX0qOk=
github.com/labstack/echo/v4 v4.15.0 h1:hoRTKWcnR5STXZFe9BmYun9AMTNeSbjHi2vtDuADJ24=
github.com/labstack/echo/v4 v4.15.0/go.mod h1:xmw1clThob0BSVRX1CRQkGQ/vjwcpOMjQZSZa9fKA/c=
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
Expand Down Expand Up @@ -277,10 +283,10 @@ github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9ZoGs=
github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA=
github.com/prometheus/procfs v0.17.0 h1:FuLQ+05u4ZI+SS/w9+BWEM2TXiHKsUQ9TADiRH7DuK0=
github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUOVhe0wYB2zw=
github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4=
github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw=
github.com/prometheus/procfs v0.19.2 h1:zUMhqEW66Ex7OXIiDkll3tl9a1ZdilUOd/F6ZXw4Vws=
github.com/prometheus/procfs v0.19.2/go.mod h1:M0aotyiemPhBCM0z5w87kL22CxfcH05ZpYlu+b4J7mw=
github.com/pymq/zenity v0.0.0-20230509161854-c117c448544d h1:vrhQkfRgAGr/dUCtJ3bUg16FbHjw6Yl8CKz0eF9NdeM=
github.com/pymq/zenity v0.0.0-20230509161854-c117c448544d/go.mod h1:FzjqP1loicusCFJTdIt5Oqbmoj2zySHpM0RsgJeeCbk=
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ require (
github.com/haxii/socks5 v1.0.0
github.com/ipfs/go-datastore v0.9.0
github.com/ipfs/go-log/v2 v2.9.1
github.com/labstack/echo/v4 v4.14.0
github.com/labstack/echo-contrib v0.50.1
github.com/labstack/echo/v4 v4.15.0
github.com/libp2p/go-libp2p v0.47.0
github.com/libp2p/go-libp2p-kad-dht v0.37.1
github.com/libp2p/go-libp2p-kbucket v0.8.0
Expand All @@ -27,6 +28,7 @@ require (
github.com/multiformats/go-multiaddr v0.16.1
github.com/multiformats/go-multistream v0.6.1
github.com/olekukonko/tablewriter v0.0.5
github.com/prometheus/client_golang v1.23.2
github.com/quic-go/quic-go v0.59.0
github.com/stretchr/testify v1.11.1
github.com/urfave/cli/v2 v2.27.7
Expand Down Expand Up @@ -123,10 +125,9 @@ require (
github.com/pion/webrtc/v4 v4.1.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_golang v1.23.2 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.66.1 // indirect
github.com/prometheus/procfs v0.17.0 // indirect
github.com/prometheus/common v0.67.5 // indirect
github.com/prometheus/procfs v0.19.2 // indirect
github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/webtransport-go v0.10.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Expand Down
18 changes: 12 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 h1:elKwZS1OcdQ0
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86/go.mod h1:aFAMtuldEgx/4q7iSGazk22+IcgvtiC+HIimFO9XlS8=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/koron/go-ssdp v0.0.6 h1:Jb0h04599eq/CY7rB5YEqPS83HmRfHP2azkxMN2rFtU=
Expand All @@ -112,8 +114,12 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/labstack/echo/v4 v4.14.0 h1:+tiMrDLxwv6u0oKtD03mv+V1vXXB3wCqPHJqPuIe+7M=
github.com/labstack/echo/v4 v4.14.0/go.mod h1:xmw1clThob0BSVRX1CRQkGQ/vjwcpOMjQZSZa9fKA/c=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/labstack/echo-contrib v0.50.1 h1:W9cZZ9viA4TDdFtm8cuA+XGFwOcnfbjJpl7VgfsRLHE=
github.com/labstack/echo-contrib v0.50.1/go.mod h1:8r/++U/Fw/QniApFnzunLanKaviPfBX7fX7/2QX0qOk=
github.com/labstack/echo/v4 v4.15.0 h1:hoRTKWcnR5STXZFe9BmYun9AMTNeSbjHi2vtDuADJ24=
github.com/labstack/echo/v4 v4.15.0/go.mod h1:xmw1clThob0BSVRX1CRQkGQ/vjwcpOMjQZSZa9fKA/c=
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
Expand Down Expand Up @@ -254,10 +260,10 @@ github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9ZoGs=
github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA=
github.com/prometheus/procfs v0.17.0 h1:FuLQ+05u4ZI+SS/w9+BWEM2TXiHKsUQ9TADiRH7DuK0=
github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUOVhe0wYB2zw=
github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4=
github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw=
github.com/prometheus/procfs v0.19.2 h1:zUMhqEW66Ex7OXIiDkll3tl9a1ZdilUOd/F6ZXw4Vws=
github.com/prometheus/procfs v0.19.2/go.mod h1:M0aotyiemPhBCM0z5w87kL22CxfcH05ZpYlu+b4J7mw=
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
github.com/quic-go/quic-go v0.59.0 h1:OLJkp1Mlm/aS7dpKgTc6cnpynnD2Xg7C1pwL6vy/SAw=
Expand Down
30 changes: 30 additions & 0 deletions metrics/dns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package metrics

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

var (
DNSQueriesTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: "dns",
Name: "queries_total",
Help: "Total DNS queries handled.",
}, []string{"handler"})

DNSQueryErrorsTotal = promauto.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: "dns",
Name: "query_errors_total",
Help: "Total DNS query errors (upstream failures).",
})

DNSQueryDurationSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: "dns",
Name: "query_duration_seconds",
Help: "DNS query duration in seconds.",
Buckets: []float64{0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 10},
})
)
Loading