mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
* Alerting: Don't use a separate collection system for metrics The state package had a metric collection system that ran every 15s updating the values of the metrics - there is a common pattern for this in the Prometheus ecosystem called "collectors". I have removed the behaviour of using a time-based interval to "set" the metrics in favour of a set of functions as the "value" that get called at scrape time.
32 lines
872 B
Go
32 lines
872 B
Go
package metrics
|
|
|
|
import (
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
)
|
|
|
|
type State struct {
|
|
StateUpdateDuration prometheus.Histogram
|
|
r prometheus.Registerer
|
|
}
|
|
|
|
// Registerer exposes the Prometheus register directly. The state package needs this as, it uses a collector to fetch the current alerts by state in the system.
|
|
func (s State) Registerer() prometheus.Registerer {
|
|
return s.r
|
|
}
|
|
|
|
func NewStateMetrics(r prometheus.Registerer) *State {
|
|
return &State{
|
|
r: r,
|
|
StateUpdateDuration: promauto.With(r).NewHistogram(
|
|
prometheus.HistogramOpts{
|
|
Namespace: Namespace,
|
|
Subsystem: Subsystem,
|
|
Name: "state_calculation_duration_seconds",
|
|
Help: "The duration of calculation of a single state.",
|
|
Buckets: []float64{0.01, 0.1, 1, 2, 5, 10},
|
|
},
|
|
),
|
|
}
|
|
}
|