Documentation
¶
Index ¶
- Constants
- Variables
- func ClassifyUA(ua string) string
- type Config
- type Mount
- type Option
- type Registry
- func (r *Registry) Add(name string, delta int64)
- func (r *Registry) Counter(name string) *atomic.Int64
- func (r *Registry) Gauge(name string, v float64)
- func (r *Registry) Handler() http.Handler
- func (r *Registry) HandlerWithToken(token string) http.Handler
- func (r *Registry) Incr(name string)
- func (r *Registry) IncrAttrs(name string, attrs map[string]string)
- func (r *Registry) InstallGlobal()
- func (r *Registry) Observe(name string, v float64)
- func (r *Registry) ObserveAttrs(name string, v float64, attrs map[string]string)
- func (r *Registry) Snapshot() map[string]int64
- type TrafficConfig
Constants ¶
const ( MetricHTTPRequests = "ploykit_http_requests" MetricHTTPDurationSeconds = "ploykit_http_request_duration_seconds" )
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.
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 ¶
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
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 Mount ¶
type Mount struct {
// contains filtered or unexported fields
}
func (*Mount) Traffic ¶ added in v0.7.2
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 Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) InstallGlobal ¶
func (r *Registry) InstallGlobal()
func (*Registry) ObserveAttrs ¶
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.