Documentation
¶
Overview ¶
Package promx implements obsx.MetricsProvider on top of prometheus/client_golang, preserving labels (the expvar default discards them) with a per-metric series-cardinality cap, and exposes the scrape handler mounted by generated servers at the authenticated /metrics endpoint. Values recorded through ObserveHistogram are milliseconds (matching pkg/obsx's latency buckets).
Concurrency: the steady-state IncCounter/ObserveHistogram hot path is lock-free, mirroring the sibling ExpvarMetrics in pkg/obsx/metrics.go. Each metric name's *vecState is cached in a sync.Map, so a call for an already-registered name does a lock-free Load rather than taking a provider-wide lock; unrelated metric names never contend. A mutex is reserved only for the cold path (first-ever registration of a name). Per-vec cardinality-cap bookkeeping is likewise lock-free once a series is admitted (or once the cap is reached); a tiny per-vec lock guards only the check-and-admit window so the cap holds EXACTLY under concurrent first-time-series admission. Leaf-metric writes delegate to client_golang's own internal RWMutex (MetricVec/Registry), which is already concurrency-safe, so promx does not layer its own lock on top.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Namespace optionally prefixes every metric (prom "namespace_" form).
Namespace string
// Registry lets callers supply their own; nil creates a fresh one.
Registry *prometheus.Registry
// MaxSeriesPerMetric caps label cardinality per metric (default 500).
MaxSeriesPerMetric int
// Buckets overrides histogram buckets (default: obsx ms buckets).
Buckets []float64
// DisableGoCollector skips the go/process runtime collectors (tests).
DisableGoCollector bool
}
Config configures the provider. The zero value is production-ready.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider is a label-preserving Prometheus MetricsProvider.
func (*Provider) Handler ¶
Handler returns the Prometheus scrape handler for this provider's registry. Mount it ONLY behind authentication.
func (*Provider) IncCounter ¶
IncCounter implements obsx.MetricsProvider.
func (*Provider) ObserveHistogram ¶
ObserveHistogram implements obsx.MetricsProvider.
func (*Provider) Registry ¶
func (p *Provider) Registry() *prometheus.Registry
Registry exposes the underlying registry (custom collectors).
func (*Provider) WantsLabels ¶
WantsLabels reports that this provider consumes label maps (unlike the default expvar provider, which discards them). obsx's Emit* helpers use this capability check to skip building a per-call label map when the active provider would only throw it away.