metrics

package
v0.6.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FallbackEvent added in v0.6.2

type FallbackEvent struct {
	Timestamp time.Time
	QueryName string
	QType     uint16
	QClass    uint16
	// PrimaryFailureReason describes why the primary resolver failed:
	// e.g. "SERVFAIL", "connection refused", "timeout", "nil result".
	PrimaryFailureReason string
	// ResolverAddr is the fallback resolver address that handled this query.
	ResolverAddr string
	Recovered    bool
	RCODE        uint8
	Error        string
}

FallbackEvent records a single fallback query attempt.

type FallbackEventRing added in v0.6.2

type FallbackEventRing struct {
	// contains filtered or unexported fields
}

FallbackEventRing is a thread-safe, bounded ring buffer of FallbackEvents. Pre-allocated [100]FallbackEvent array — no heap growth after init.

func NewFallbackEventRing added in v0.6.2

func NewFallbackEventRing() *FallbackEventRing

NewFallbackEventRing creates a new FallbackEventRing.

func (*FallbackEventRing) Add added in v0.6.2

func (r *FallbackEventRing) Add(e FallbackEvent)

Add appends an event to the ring buffer, overwriting the oldest when full.

func (*FallbackEventRing) Events added in v0.6.2

func (r *FallbackEventRing) Events() []FallbackEvent

Events returns all events in oldest-to-newest order.

type Metrics

type Metrics struct {

	// RecordFallbackFunc is an optional callback invoked each time a fallback
	// query fires (query=1) or recovers (recovery=1). Set by the web package
	// to route fallback events into the time-series aggregator.
	RecordFallbackFunc func(query, recovery int64)
	// contains filtered or unexported fields
}

Metrics holds all application metrics using lock-free atomic counters.

func NewMetrics

func NewMetrics() *Metrics

NewMetrics creates a new Metrics instance.

func (*Metrics) AddCacheEvictions

func (m *Metrics) AddCacheEvictions(reason string, count int)

func (*Metrics) FallbackEventRing added in v0.6.2

func (m *Metrics) FallbackEventRing() *FallbackEventRing

FallbackEventRing returns the fallback event ring buffer.

func (*Metrics) IncBlockedQueries

func (m *Metrics) IncBlockedQueries()

func (*Metrics) IncCacheEvictions

func (m *Metrics) IncCacheEvictions(reason string)

func (*Metrics) IncCacheHits

func (m *Metrics) IncCacheHits()

func (*Metrics) IncCacheMisses

func (m *Metrics) IncCacheMisses()

func (*Metrics) IncDNSSECBogus

func (m *Metrics) IncDNSSECBogus()

func (*Metrics) IncDNSSECInsecure

func (m *Metrics) IncDNSSECInsecure()

func (*Metrics) IncDNSSECSecure

func (m *Metrics) IncDNSSECSecure()

func (*Metrics) IncFallbackQueries added in v0.5.3

func (m *Metrics) IncFallbackQueries()

func (*Metrics) IncFallbackRecoveries added in v0.5.3

func (m *Metrics) IncFallbackRecoveries()

func (*Metrics) IncQueries

func (m *Metrics) IncQueries(qtype string)

func (*Metrics) IncRateLimited

func (m *Metrics) IncRateLimited()

func (*Metrics) IncResponses

func (m *Metrics) IncResponses(rcode string)

func (*Metrics) IncUpstreamErrors

func (m *Metrics) IncUpstreamErrors()

func (*Metrics) IncUpstreamQueries

func (m *Metrics) IncUpstreamQueries()

func (*Metrics) ObserveQueryDuration

func (m *Metrics) ObserveQueryDuration(d time.Duration)

func (*Metrics) ServeHTTP

func (m *Metrics) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler for the /metrics endpoint.

func (*Metrics) Snapshot

func (m *Metrics) Snapshot() MetricsSnapshot

Snapshot returns a point-in-time snapshot of all metrics.

func (*Metrics) StartTime

func (m *Metrics) StartTime() time.Time

func (*Metrics) WriteMetrics

func (m *Metrics) WriteMetrics(w io.Writer)

WriteMetrics writes all metrics in Prometheus text format.

type MetricsSnapshot

type MetricsSnapshot struct {
	QueriesByType      map[string]int64
	ResponsesByRCode   map[string]int64
	CacheHits          int64
	CacheMisses        int64
	CacheEvictions     int64
	UpstreamQueries    int64
	UpstreamErrors     int64
	RateLimited        int64
	UptimeSeconds      float64
	Goroutines         int
	QueryDurationCount int64
	DNSSECSecure       int64
	DNSSECInsecure     int64
	DNSSECBogus        int64
	BlockedQueries     int64
	FallbackQueries    int64
	FallbackRecoveries int64
}

MetricsSnapshot holds a point-in-time snapshot of all metrics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL