Help us shape the future of Go! Take the 2026 Go Developer Survey

metrics

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetricHTTPRequests = "ploykit_http_requests"

	MetricHTTPDurationSeconds = "ploykit_http_request_duration_seconds"
)
View Source
const (
	// BotHuman is the default for everything that is not a recognized bot —
	// including unmatched crawlers the heuristic does not know.
	BotHuman = "human"
	// BotGoogle is the Googlebot family; kept separate because it is the
	// crawler whose behavior products actually act on.
	BotGoogle = "google"
	// BotSearch covers the remaining search-engine crawlers (Bing, Yandex,
	// Baidu, DuckDuckGo, Applebot plain, …).
	BotSearch = "search"
	// BotAI covers LLM / AI-answer crawlers (GPTBot, ClaudeBot, PerplexityBot,
	// CCBot, Bytespider, …) — the crawler class that grew fastest.
	BotAI = "ai"
	// BotSocial covers link-preview fetchers (Twitterbot, Slackbot, …).
	BotSocial = "social"
	// BotTool covers libraries, probes and scanners (curl, kube-probe,
	// uptime monitors, nmap). A UA-less request is classified here too —
	// scripts far outnumber real clients that omit the header.
	BotTool = "tool"
)

Bot classes returned by ClassifyUA.

View Source
const (
	MetricTrafficRequests = "ploykit_traffic_requests"
)

Traffic counting for the public/rendered surface: how much traffic came from crawlers vs humans, what serving layer answered (cache hit vs on-the-spot render), and whether crawlers got errors. This is the server-side SEO observation that third-party analytics structurally cannot provide — a script beacon never runs for a crawler. Counts are anonymous and carry no per-request storage: labels are bounded classes, never paths or user agents (per-page detail is deliberately absent here; that is the deferred visitor-analytics product, see docs/visitor-analytics.md).

Variables

View Source
var DefaultDurationBuckets = []float64{0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10}

Functions

func ClassifyUA added in v0.7.2

func ClassifyUA(ua string) string

ClassifyUA buckets a User-Agent header into the Bot* classes. It is a heuristic over a curated token table: exported so products can inspect it, extend the shape with TrafficConfig.Classify, or assert against it in tests.

Types

type Config

type Config struct {
	Enabled *bool

	Path string

	Token string
}

type Mount

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

func NewMount

func NewMount(cfg Config, opts ...Option) *Mount

func (*Mount) Handler

func (m *Mount) Handler() http.Handler

func (*Mount) Middleware

func (m *Mount) Middleware(next http.Handler) http.Handler

func (*Mount) Path

func (m *Mount) Path() string

func (*Mount) Registry

func (m *Mount) Registry() *Registry

func (*Mount) Traffic added in v0.7.2

func (m *Mount) Traffic(cfg TrafficConfig) func(http.Handler) http.Handler

Traffic returns the counting middleware to wrap around the public render handler (the renderx/SPA catch-all), after Mount.Middleware in the chain. It records one ploykit_traffic_requests{bot,tier,status} increment per request. On a disabled mount it is a pass-through, the same silent degradation as Middleware. Bot classification is a UA heuristic — good enough for observation, worthless as a security control (UA is spoofable).

type Option

type Option func(*config)

func WithHistogramBuckets

func WithHistogramBuckets(name string, buckets []float64) Option

func WithRegistry

func WithRegistry(r *Registry) Option

type Registry

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

func New

func New(opts ...Option) *Registry

func (*Registry) Add

func (r *Registry) Add(name string, delta int64)

func (*Registry) Counter

func (r *Registry) Counter(name string) *atomic.Int64

func (*Registry) Gauge

func (r *Registry) Gauge(name string, v float64)

func (*Registry) Handler

func (r *Registry) Handler() http.Handler

func (*Registry) HandlerWithToken

func (r *Registry) HandlerWithToken(token string) http.Handler

func (*Registry) Incr

func (r *Registry) Incr(name string)

func (*Registry) IncrAttrs

func (r *Registry) IncrAttrs(name string, attrs map[string]string)

func (*Registry) InstallGlobal

func (r *Registry) InstallGlobal()

func (*Registry) Observe

func (r *Registry) Observe(name string, v float64)

func (*Registry) ObserveAttrs

func (r *Registry) ObserveAttrs(name string, v float64, attrs map[string]string)

func (*Registry) Snapshot

func (r *Registry) Snapshot() map[string]int64

type TrafficConfig added in v0.7.2

type TrafficConfig struct {
	// Header names the response header carrying the serving tier (see
	// renderx.HeaderTier, whose literal "X-Renderx-Tier" is the default). A
	// response without the header is counted as tier "none".
	Header string

	// Classify overrides the User-Agent classifier; nil uses ClassifyUA.
	// Values must be short lowercase tokens (anything else is folded into
	// "other") to keep label cardinality bounded.
	Classify func(ua string) string
}

TrafficConfig configures Mount.Traffic.

Jump to

Keyboard shortcuts

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