2022-02-02 12:11:41 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import "github.com/VictoriaMetrics/metrics"
|
|
|
|
|
|
|
|
type namedMetric struct {
|
|
|
|
Name string
|
2025-02-21 09:36:29 +00:00
|
|
|
|
|
|
|
set *metrics.Set
|
2022-02-02 12:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unregister removes the metric by name from default registry
|
|
|
|
func (nm namedMetric) Unregister() {
|
2025-02-21 09:36:29 +00:00
|
|
|
nm.set.UnregisterMetric(nm.Name)
|
2022-02-02 12:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Gauge is a metrics.Gauge with Name
|
|
|
|
type Gauge struct {
|
|
|
|
namedMetric
|
|
|
|
*metrics.Gauge
|
|
|
|
}
|
|
|
|
|
2025-02-21 09:36:29 +00:00
|
|
|
// NewGauge creates a new Gauge with the given name
|
|
|
|
func NewGauge(set *metrics.Set, name string, f func() float64) *Gauge {
|
2022-02-02 12:11:41 +00:00
|
|
|
return &Gauge{
|
2025-02-21 09:36:29 +00:00
|
|
|
namedMetric: namedMetric{Name: name, set: set},
|
|
|
|
Gauge: set.NewGauge(name, f),
|
2022-02-02 12:11:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Counter is a metrics.Counter with Name
|
|
|
|
type Counter struct {
|
|
|
|
namedMetric
|
|
|
|
*metrics.Counter
|
|
|
|
}
|
|
|
|
|
2025-02-21 09:36:29 +00:00
|
|
|
// NewCounter creates a new Counter with the given name
|
|
|
|
func NewCounter(set *metrics.Set, name string) *Counter {
|
2022-02-02 12:11:41 +00:00
|
|
|
return &Counter{
|
2025-02-21 09:36:29 +00:00
|
|
|
namedMetric: namedMetric{Name: name, set: set},
|
|
|
|
Counter: set.NewCounter(name),
|
2022-02-02 12:11:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Summary is a metrics.Summary with Name
|
|
|
|
type Summary struct {
|
|
|
|
namedMetric
|
|
|
|
*metrics.Summary
|
|
|
|
}
|
|
|
|
|
2025-02-21 09:36:29 +00:00
|
|
|
// NewSummary creates a new Summary with the given name
|
|
|
|
func NewSummary(set *metrics.Set, name string) *Summary {
|
2022-02-02 12:11:41 +00:00
|
|
|
return &Summary{
|
2025-02-21 09:36:29 +00:00
|
|
|
namedMetric: namedMetric{Name: name, set: set},
|
|
|
|
Summary: set.NewSummary(name),
|
2022-02-02 12:11:41 +00:00
|
|
|
}
|
|
|
|
}
|