stats

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package stats provides an in-memory, bounded aggregation of DNS activity over a rolling 24h window. It has no dependency on resolvers or HTTP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

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

Collector aggregates samples into hourly buckets with a 24h sliding window.

func NewCollector

func NewCollector() *Collector

NewCollector returns a Collector using the wall clock.

func (*Collector) Record

func (c *Collector) Record(s Sample)

Record adds one sample. Safe for concurrent use.

func (*Collector) SetAllowlistCount

func (c *Collector) SetAllowlistCount(group string, n int)

SetAllowlistCount records the current entry count for an allowlist group.

func (*Collector) SetCacheEntries

func (c *Collector) SetCacheEntries(n int)

SetCacheEntries records the current result-cache size (point-in-time).

func (*Collector) SetDenylistCount

func (c *Collector) SetDenylistCount(group string, n int)

SetDenylistCount records the current entry count for a denylist group.

func (*Collector) Snapshot

func (c *Collector) Snapshot() Result

Snapshot merges all live buckets into a Result.

type Disposition

type Disposition int

Disposition is the final outcome class of a query.

const (
	DispositionAnswered Disposition = iota
	DispositionDropped
	DispositionErrored
)

type HourPoint

type HourPoint struct {
	Hour    time.Time
	Queries int
	Blocked int
}

HourPoint is one point in the per-hour time series.

type ListCounts

type ListCounts struct {
	Denylist  map[string]int
	Allowlist map[string]int
}

ListCounts holds current per-group list entry counts (point-in-time).

type NameCount

type NameCount struct {
	Name  string
	Count int
}

NameCount is a (name, count) pair for top-N lists.

type Result

type Result struct {
	Start             time.Time
	End               time.Time
	Summary           Summary
	ByResponseType    map[string]int
	ByQueryType       map[string]int
	ByResponseCode    map[string]int
	PerHour           []HourPoint
	TopDomains        []NameCount
	TopBlockedDomains []NameCount
	TopClients        []NameCount
	Lists             ListCounts
	CacheEntries      int
}

Result is the full snapshot returned to the API layer.

type Sample

type Sample struct {
	RType       string
	Disposition Disposition
	QType       string
	RCode       string
	Domain      string
	Client      string
	DurationMs  int64
}

Sample is a single recorded query — primitives only; never retains *dns.Msg. Whether the query was blocked is derived from RType (see isBlockedRType), so there is a single source of truth for the "blocked" classification.

type Summary

type Summary struct {
	Queries       int
	Cached        int
	Forwarded     int
	Blocked       int
	Local         int
	Dropped       int
	Errors        int
	AvgResponseMs int
	CacheHitRate  float64
}

Summary holds the curated outcome categories over the window.

Jump to

Keyboard shortcuts

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