metrics

package
v0.5.26 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: BSD-3-Clause Imports: 14 Imported by: 0

README

Name

metrics - enable prometheus metrics

Description

With metrics metrics are exported from atomdns and any handler that adds extra ones. The default address for the metrics server is localhost:9153. The metrics path is fixed to /metrics. See the global handler for details on how to change the address.

You must also enable metrics in the server block, this allows you to specify where in the handler chain the metrics are gathered. Usually this is the first handler. If the global section doesn't specify metrics the metrics will not be able to be scraped, but they are still gathered.

Enabling metrics means taking a (severe) performance hit (50 Kqps, seen in [limited] testing), to alleviate this, by default, only 1 in 10 queries will be monitored. See the global handler's documentation on how to change this. When displaying these metrics in (e.g.) Grafana, be sure to *10, otherwise your queries per second is lower then you hoped for.

In addition to the default Go metrics exported by the prometheus Go client, the following metrics are exported:

  • atomdns_dns_dropped_total{} - total count of dropped queries, because they are invalid, these will always be reported even with metrics disable, as this happens before the query hits this handler.
  • atomdns_dns_requests_total{zone, network, family, flags} - total query count.
  • atomdns_dns_responses_total{zone, network, family, rcode} - response per, among other things, the response code.
  • atomdns_dns_request_duration_seconds{zone, network, family} - duration to process each query.
  • atomdns_dns_request_size_bytes{zone, network, family} - size of the request in bytes.
  • atomdns_dns_response_size_bytes{zone, network, family} - response size in bytes.
  • network which holds the transport of the response ("udp" or "tcp")
  • The address family (family) of the transport (1 = IP (IP version 4), 2 = IP6 (IP version 6)).
  • flags is a string that consists out of header flags mnemonics seperated by spaces:
    • flags="co do" means the CO (compact answers) and DO (dnssec ok) are set.
    • The recognized flags are: co - compact answers, do - dnssec ok, de - deleg ok, ad - authenticated data, and cd - checking disabled.

If a server want to not partake in the metrics collection it sets metrics disable in the configuration. The default is to allow metrics gathering.

Syntax

metrics [|enable|disable]

Where:

  • empty or enable will enable metrics gathering, only disable will disable it.

Examples

Start a server on the default port and load the whoami handler and disable metrics.

{
    metrics
    debug
}

example.org {
    metrics disable
    whoami
}

Documentation

Index

Constants

View Source
const (
	Namespace = "atomdns"
)

Variables

View Source
var (
	Dropped = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: Namespace, Subsystem: subsystem,
		Name: "dropped_total",
		Help: "Counter of dropped requests. These are reported via the server's MsgInvalidFunc.",
	})

	Requests = promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: Namespace, Subsystem: subsystem,
		Name: "requests_total",
		Help: "Counter of requests made per zone, network and family.",
	}, []string{"zone", "network", "family", "flags"})

	Responses = promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: Namespace, Subsystem: subsystem,
		Name: "responses_total",
		Help: "Counter of responses and response codes.",
	}, []string{"zone", "network", "family", "rcode"})

	RequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: Namespace, Subsystem: subsystem,
		Name:    "request_duration_seconds",
		Buckets: prometheus.ExponentialBuckets(0.00025, 2, 16),
		Help:    "Histogram of the time (in seconds) each request took per zone.",
	}, []string{"zone", "network", "family"})

	RequestSize = promauto.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: Namespace, Subsystem: subsystem,
		Name:    "request_size_bytes",
		Help:    "Size of the requests.",
		Buckets: []float64{0, 100, 200, 300, 400, 511, 1023, 2047, 4095, 8291, 16e3, 32e3, 48e3, 64e3},
	}, []string{"zone", "network", "family"})

	ResponseSize = promauto.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: Namespace, Subsystem: subsystem,
		Name:    "response_size_bytes",
		Help:    "Size of the returned response in bytes.",
		Buckets: []float64{0, 100, 200, 300, 400, 511, 1023, 2047, 4095, 8291, 16e3, 32e3, 48e3, 64e3},
	}, []string{"zone", "network", "family"})
)

Functions

func Err added in v0.5.2

func Err(err error) slog.Attr

Types

type Metrics

type Metrics struct {
	N uint64
	// contains filtered or unexported fields
}

func (*Metrics) Err

func (h *Metrics) Err(err error) error

func (*Metrics) HandlerFunc

func (m *Metrics) HandlerFunc(next dns.HandlerFunc) dns.HandlerFunc

func (*Metrics) Key

func (h *Metrics) Key() string

func (*Metrics) Setup

func (m *Metrics) Setup(co *dnsserver.Controller) error

Jump to

Keyboard shortcuts

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