Documentation
¶
Overview ¶
Package metrics is Ken's tiny, dependency-free Prometheus exposition: a handful of atomic counters plus on-scrape gauge collectors, rendered as text/plain exposition format. It deliberately does NOT use prometheus/client_golang — that would add ~1-2 MB and several transitive deps; Ken values a flat footprint, so the counters are plain atomics and the encoder is ~100 lines. Metrics are pull-based and in-memory: Ken stores nothing on disk for them.
Index ¶
- func OutcomeClass(code int) string
- type Collector
- type Family
- type Label
- type Registry
- func (r *Registry) AddCollector(c Collector)
- func (r *Registry) AuthFailure(surface string)
- func (r *Registry) Counting(surface string, next http.Handler) http.Handler
- func (r *Registry) RateLimitBlocked()
- func (r *Registry) RateLimitRejected()
- func (r *Registry) RecordHTTP(surface, outcome string, d time.Duration)
- func (r *Registry) RecordMCP(tool string, ok bool)
- func (r *Registry) RecordMCPDuration(tool string, d time.Duration)
- func (r *Registry) WriteText(ctx context.Context, w io.Writer)
- type Series
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OutcomeClass ¶
OutcomeClass maps an HTTP status to a coarse, low-cardinality outcome bucket (the conventional informational/success/redirection/client_error/server_error).
Types ¶
type Collector ¶
Collector produces gauge families at scrape time (e.g. DB row counts). It is given the scrape request's context so a slow DB can't wedge the handler.
type Family ¶
Family is a metric family: one HELP/TYPE header plus N series. Collectors return these for on-scrape gauges.
type Label ¶
type Label struct{ Name, Value string }
Label is a single name=value pair on a metric series.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds Ken's counters and gauge collectors. The zero value is not usable; call New.
func (*Registry) AddCollector ¶
AddCollector registers a gauge source evaluated on each scrape.
func (*Registry) AuthFailure ¶
AuthFailure records a rejected authentication on a surface (e.g. a bad token).
func (*Registry) Counting ¶
Counting wraps next, recording each served request under surface. Health and metrics paths are skipped so probes/scrapes don't inflate the counters.
func (*Registry) RateLimitBlocked ¶
func (r *Registry) RateLimitBlocked()
RateLimitBlocked records a 403 refusal from an auto-blocked IP.
func (*Registry) RateLimitRejected ¶
func (r *Registry) RateLimitRejected()
RateLimitRejected records a 429 throttle.
func (*Registry) RecordHTTP ¶
RecordHTTP records one served HTTP request and its duration for a surface.
func (*Registry) RecordMCPDuration ¶ added in v1.3.0
RecordMCPDuration records how long a tool's HANDLER ran — its work time, not the SSE stream lifetime. The caller must NOT call this for a tool that intentionally blocks (a long-poll): a parked wait is not latency, and bucketing it would drown the real work time. See the addTool wrappers, which skip the blocking tools.