package lazymetrics ¶
import "golazy.dev/lazytelemetry/lazymetrics"
Functions ¶
func PrometheusHandler ¶
PrometheusHandler returns an HTTP handler for Prometheus text exposition.
func PrometheusHandler(registry *Registry, collectors ...PrometheusCollector) http.Handler
func WithLabels ¶
WithLabels attaches metric labels to ctx.
func WithLabels(ctx context.Context, labels Labels) context.Context
func WithRequestLabels ¶
WithRequestLabels attaches request-scoped metric labels to ctx. Descendant WithLabels calls merge into the same label set, which lets outer request middleware record labels discovered later in routing.
func WithRequestLabels(ctx context.Context, labels Labels) context.Context
func WritePrometheus ¶
WritePrometheus writes snapshot using the Prometheus text exposition format.
func WritePrometheus(w io.Writer, snapshot Snapshot) error
Types ¶
type Counter ¶
Counter is a counter metric handle.
type Counter struct {
// contains filtered or unexported fields
}
func (c Counter) Add ¶
Add increments the counter by value. Negative values are ignored.
func (c Counter) Add(value float64)
func (c Counter) Inc ¶
Inc increments the counter by one.
func (c Counter) Inc()
type CounterVec ¶
CounterVec is a named counter with declared label names.
type CounterVec struct {
// contains filtered or unexported fields
}
func (v *CounterVec) With ¶
With returns a counter for labels.
func (v *CounterVec) With(labels Labels) Counter
func (v *CounterVec) WithLabelValues ¶
WithLabelValues returns a counter for values in label-name order.
func (v *CounterVec) WithLabelValues(values ...string) Counter
type Gauge ¶
Gauge is a gauge metric handle.
type Gauge struct {
// contains filtered or unexported fields
}
func (g Gauge) Add ¶
Add changes the gauge by value.
func (g Gauge) Add(value float64)
func (g Gauge) Set ¶
Set sets the gauge value.
func (g Gauge) Set(value float64)
type GaugeVec ¶
GaugeVec is a named gauge with declared label names.
type GaugeVec struct {
// contains filtered or unexported fields
}
func (v *GaugeVec) With ¶
With returns a gauge for labels.
func (v *GaugeVec) With(labels Labels) Gauge
func (v *GaugeVec) WithLabelValues ¶
WithLabelValues returns a gauge for values in label-name order.
func (v *GaugeVec) WithLabelValues(values ...string) Gauge
type Histogram ¶
Histogram is a histogram metric handle.
type Histogram struct {
// contains filtered or unexported fields
}
func (h Histogram) Observe ¶
Observe records a histogram observation.
func (h Histogram) Observe(value float64)
type HistogramBucketSnapshot ¶
HistogramBucketSnapshot is a cumulative histogram bucket.
type HistogramBucketSnapshot struct {
Le float64
Count int64
}
type HistogramSnapshot ¶
HistogramSnapshot is a point-in-time histogram summary.
type HistogramSnapshot struct {
Name string
Labels Labels
Count int64
Sum float64
Min float64
Max float64
Buckets []HistogramBucketSnapshot
}
type HistogramVec ¶
HistogramVec is a named histogram with declared label names.
type HistogramVec struct {
// contains filtered or unexported fields
}
func (v *HistogramVec) With ¶
With returns a histogram for labels.
func (v *HistogramVec) With(labels Labels) Histogram
func (v *HistogramVec) WithLabelValues ¶
WithLabelValues returns a histogram for values in label-name order.
func (v *HistogramVec) WithLabelValues(values ...string) Histogram
type Labels ¶
Labels stores low-cardinality metric labels.
type Labels map[string]string
func LabelsFromContext ¶
LabelsFromContext returns metric labels attached to ctx.
func LabelsFromContext(ctx context.Context) Labels
type MetricSnapshot ¶
MetricSnapshot is a point-in-time counter or gauge value.
type MetricSnapshot struct {
Name string
Labels Labels
Value float64
}
type PrometheusCollector ¶
PrometheusCollector writes additional Prometheus text exposition metrics.
type PrometheusCollector func(io.Writer) error
type Registry ¶
Registry stores in-memory metrics.
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
NewRegistry creates an empty metric registry.
func NewRegistry() *Registry
func (r *Registry) NewCounter ¶
NewCounter creates a counter vector.
func (r *Registry) NewCounter(name string, labelNames ...string) *CounterVec
func (r *Registry) NewGauge ¶
NewGauge creates a gauge vector.
func (r *Registry) NewGauge(name string, labelNames ...string) *GaugeVec
func (r *Registry) NewHistogram ¶
NewHistogram creates a histogram vector.
func (r *Registry) NewHistogram(name string, labelNames ...string) *HistogramVec
func (r *Registry) Snapshot ¶
Snapshot returns a copy of all registry values.
func (r *Registry) Snapshot() Snapshot
type Snapshot ¶
Snapshot contains all metrics in a registry.
type Snapshot struct {
Counters []MetricSnapshot
Gauges []MetricSnapshot
Histograms []HistogramSnapshot
}
Package lazymetrics provides lightweight metric helpers for GoLazy telemetry.