mirror of
https://github.com/luxfi/metric.git
synced 2026-07-27 04:12:44 +00:00
1.3 KiB
1.3 KiB
Lux Metrics Library (AI Notes)
This package provides the native metrics system for Lux. It does not depend on external metrics clients and emits a scrape-compatible text format.
Core Concepts
- Registry: collects metrics and implements
Gatherer. - Metrics: namespace-scoped factories created via
metric.New(namespace). - Handlers:
metric.Handler()andmetric.NewHTTPHandler(reg, opts)expose text output.
Primary APIs
reg := metric.NewRegistry()
m := metric.NewWithRegistry("myapp", reg)
reqs := m.NewCounter("requests_total", "Total requests")
latency := m.NewHistogram("request_seconds", "Request latency", metric.DefBuckets)
reqs.Inc()
latency.Observe(0.123)
Vector metrics:
byRoute := m.NewCounterVec("requests_total", "Requests by route", []string{"method", "route"})
byRoute.WithLabelValues("GET", "/").Inc()
Text Format
Use metric.EncodeText(w, families) to serialize gathered metrics, or
metric.Handler() / metric.NewHTTPHandler(...) to serve metrics over HTTP.
Metrics-Off Build
The package supports build-tagged no-op defaults. When compiled without
the metrics tag, NewRegistry and the package defaults return no-op
implementations to minimize overhead. Pre-bind label values in hot paths to
avoid expensive argument construction.