2021-12-27 12:24:05 +00:00
|
|
|
package metrics
|
|
|
|
|
2023-05-26 10:24:41 +00:00
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"time"
|
2021-12-27 12:24:05 +00:00
|
|
|
|
2023-05-31 09:25:32 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
2023-05-26 10:24:41 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
innerRingSubsystem = "ir"
|
|
|
|
innerRingLabelSuccess = "success"
|
|
|
|
innerRingLabelType = "type"
|
|
|
|
)
|
2021-12-27 12:24:05 +00:00
|
|
|
|
|
|
|
// InnerRingServiceMetrics contains metrics collected by inner ring.
|
|
|
|
type InnerRingServiceMetrics struct {
|
2023-05-31 09:25:32 +00:00
|
|
|
epoch prometheus.Gauge
|
|
|
|
health prometheus.Gauge
|
|
|
|
eventDuration *prometheus.HistogramVec
|
2021-12-27 12:24:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewInnerRingMetrics returns new instance of metrics collectors for inner ring.
|
2023-04-26 12:45:57 +00:00
|
|
|
func NewInnerRingMetrics() *InnerRingServiceMetrics {
|
2021-12-27 12:24:05 +00:00
|
|
|
var (
|
2023-05-31 09:25:32 +00:00
|
|
|
epoch = metrics.NewGauge(prometheus.GaugeOpts{
|
2021-12-27 12:24:05 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: innerRingSubsystem,
|
|
|
|
Name: "epoch",
|
|
|
|
Help: "Current epoch as seen by inner-ring node.",
|
|
|
|
})
|
2023-05-31 09:25:32 +00:00
|
|
|
health = metrics.NewGauge(prometheus.GaugeOpts{
|
2023-03-13 06:21:28 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: innerRingSubsystem,
|
|
|
|
Name: "health",
|
|
|
|
Help: "Current inner-ring node state.",
|
|
|
|
})
|
2023-05-31 09:25:32 +00:00
|
|
|
eventDuration = metrics.NewHistogramVec(prometheus.HistogramOpts{
|
2023-05-26 10:24:41 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: innerRingSubsystem,
|
|
|
|
Name: "event_duration_seconds",
|
|
|
|
Help: "Duration of processing of inner-ring events",
|
|
|
|
}, []string{innerRingLabelType, innerRingLabelSuccess})
|
2021-12-27 12:24:05 +00:00
|
|
|
)
|
|
|
|
|
2023-04-26 12:45:57 +00:00
|
|
|
return &InnerRingServiceMetrics{
|
2023-05-26 10:24:41 +00:00
|
|
|
epoch: epoch,
|
|
|
|
health: health,
|
|
|
|
eventDuration: eventDuration,
|
2021-12-27 12:24:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetEpoch updates epoch metrics.
|
|
|
|
func (m InnerRingServiceMetrics) SetEpoch(epoch uint64) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.epoch.Set(float64(epoch))
|
2021-12-27 12:24:05 +00:00
|
|
|
}
|
2023-03-13 06:21:28 +00:00
|
|
|
|
|
|
|
// SetHealth updates health metrics.
|
|
|
|
func (m InnerRingServiceMetrics) SetHealth(s int32) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.health.Set(float64(s))
|
2023-03-13 06:21:28 +00:00
|
|
|
}
|
2023-05-26 10:24:41 +00:00
|
|
|
|
|
|
|
func (m InnerRingServiceMetrics) AddEvent(d time.Duration, typ string, success bool) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.eventDuration.With(prometheus.Labels{
|
2023-05-26 10:24:41 +00:00
|
|
|
innerRingLabelType: typ,
|
|
|
|
innerRingLabelSuccess: strconv.FormatBool(success),
|
|
|
|
}).Observe(d.Seconds())
|
|
|
|
}
|