mirror of
https://github.com/docker/cli.git
synced 2026-11-06 13:10:41 -04:00
- Add support for creating timers with custom histogram buckets. - Update `github.com/prometheus/client_golang` to v1.20.5. - Update the minimum supported Go version to Go 1.21. - Improve HTTP handler instrumentation, including minor performance improvements and cleanup. - Avoid mutating shared label maps when creating namespaces and metrics. - Encapsulate the Prometheus collector used by `HTTPMetric`. - Improve package and API documentation. - Update `golang.org/x/sys` and other dependencies. full diff: https://github.com/docker/go-metrics/compare/v0.0.1...v0.1.0 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
77 lines
1.5 KiB
Go
77 lines
1.5 KiB
Go
package metrics
|
|
|
|
import "github.com/prometheus/client_golang/prometheus"
|
|
|
|
// Gauge is a metric that allows incrementing and decrementing a value
|
|
type Gauge interface {
|
|
Inc(...float64)
|
|
Dec(...float64)
|
|
|
|
// Add adds the provided value to the gauge's current value
|
|
Add(float64)
|
|
|
|
// Set replaces the gauge's current value with the provided value
|
|
Set(float64)
|
|
}
|
|
|
|
// LabeledGauge describes a gauge the must have values populated before use.
|
|
type LabeledGauge interface {
|
|
WithValues(labels ...string) Gauge
|
|
}
|
|
|
|
type labeledGauge struct {
|
|
pg *prometheus.GaugeVec
|
|
}
|
|
|
|
func (lg *labeledGauge) WithValues(labels ...string) Gauge {
|
|
return &gauge{pg: lg.pg.WithLabelValues(labels...)}
|
|
}
|
|
|
|
// Describe implements [prometheus.Collector].
|
|
func (lg *labeledGauge) Describe(c chan<- *prometheus.Desc) {
|
|
lg.pg.Describe(c)
|
|
}
|
|
|
|
// Collect implements [prometheus.Collector].
|
|
func (lg *labeledGauge) Collect(c chan<- prometheus.Metric) {
|
|
lg.pg.Collect(c)
|
|
}
|
|
|
|
type gauge struct {
|
|
pg prometheus.Gauge
|
|
}
|
|
|
|
func (g *gauge) Inc(vs ...float64) {
|
|
if len(vs) == 0 {
|
|
g.pg.Inc()
|
|
}
|
|
|
|
g.Add(sumFloat64(vs...))
|
|
}
|
|
|
|
func (g *gauge) Dec(vs ...float64) {
|
|
if len(vs) == 0 {
|
|
g.pg.Dec()
|
|
}
|
|
|
|
g.Add(-sumFloat64(vs...))
|
|
}
|
|
|
|
func (g *gauge) Add(v float64) {
|
|
g.pg.Add(v)
|
|
}
|
|
|
|
func (g *gauge) Set(v float64) {
|
|
g.pg.Set(v)
|
|
}
|
|
|
|
// Describe implements [prometheus.Collector].
|
|
func (g *gauge) Describe(c chan<- *prometheus.Desc) {
|
|
g.pg.Describe(c)
|
|
}
|
|
|
|
// Collect implements [prometheus.Collector].
|
|
func (g *gauge) Collect(c chan<- prometheus.Metric) {
|
|
g.pg.Collect(c)
|
|
}
|