Documentation
¶
Overview ¶
Package prom provides stats tracker implementation based on prometheus client.
Index ¶
- type Tracker
- func (t *Tracker) Add(ctx context.Context, name string, value float64, labelsAndValues ...string)
- func (t *Tracker) DeclareCounter(name string, opts prometheus.CounterOpts)
- func (t *Tracker) DeclareGauge(name string, opts prometheus.GaugeOpts)
- func (t *Tracker) DeclareHistogram(name string, opts prometheus.HistogramOpts)
- func (t *Tracker) DeclareSummary(name string, opts prometheus.SummaryOpts)
- func (t *Tracker) Reset()
- func (t *Tracker) Set(ctx context.Context, name string, absolute float64, labelsAndValues ...string)
- func (t *Tracker) StatsTracker() stats.Tracker
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Tracker ¶
type Tracker struct {
Registry *prometheus.Registry
ErrLogger func(ctx context.Context, err error, labels []string)
// contains filtered or unexported fields
}
Tracker implements stats tracker with prometheus registry.
Please use NewStatsTracker to create new instance.
Example ¶
package main
import (
"context"
"github.com/bool64/stats"
"github.com/bool64/stats/prom"
"github.com/prometheus/client_golang/prometheus"
)
func main() {
// Bring your own Prometheus registry.
registry := prometheus.NewRegistry()
tr := prom.Tracker{
Registry: registry,
}
// Add custom Prometheus configuration where necessary.
tr.DeclareHistogram("my_latency_seconds", prometheus.HistogramOpts{
Buckets: []float64{1e-4, 1e-3, 1e-2, 1e-1, 1, 10, 100},
})
ctx := context.Background()
// Add labels to context.
ctx = stats.AddKeysAndValues(ctx, "ctx-label", "ctx-value0")
// Override label values.
ctx = stats.AddKeysAndValues(ctx, "ctx-label", "ctx-value1")
// Collect stats with last mile labels.
tr.Add(ctx, "my_count", 1,
"some-label", "some-value",
)
tr.Add(ctx, "my_latency_seconds", 1.23)
tr.Set(ctx, "temperature", 33.3)
}
func NewStatsTracker ¶
func NewStatsTracker(registry *prometheus.Registry) (*Tracker, error)
NewStatsTracker creates prometheus stats tracker.
func (*Tracker) DeclareCounter ¶
func (t *Tracker) DeclareCounter(name string, opts prometheus.CounterOpts)
DeclareCounter registers counter metric for given name.
func (*Tracker) DeclareGauge ¶
func (t *Tracker) DeclareGauge(name string, opts prometheus.GaugeOpts)
DeclareGauge registers gauge metric for given name.
func (*Tracker) DeclareHistogram ¶
func (t *Tracker) DeclareHistogram(name string, opts prometheus.HistogramOpts)
DeclareHistogram registers histogram metric for given name.
func (*Tracker) DeclareSummary ¶
func (t *Tracker) DeclareSummary(name string, opts prometheus.SummaryOpts)
DeclareSummary registers summary metric for given name.
func (*Tracker) Reset ¶ added in v0.1.1
func (t *Tracker) Reset()
Reset unregisters and removes all registered collectors.
func (*Tracker) Set ¶
func (t *Tracker) Set(ctx context.Context, name string, absolute float64, labelsAndValues ...string)
Set collects absolute value to Gauge.
func (*Tracker) StatsTracker ¶
StatsTracker is a service locator provider.
Click to show internal directories.
Click to hide internal directories.