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-10-08 09:32:00 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
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"
|
|
|
|
)
|
|
|
|
|
2021-12-27 12:24:05 +00:00
|
|
|
// InnerRingServiceMetrics contains metrics collected by inner ring.
|
|
|
|
type InnerRingServiceMetrics struct {
|
2023-05-26 09:15:50 +00:00
|
|
|
epoch prometheus.Gauge
|
|
|
|
health prometheus.Gauge
|
|
|
|
eventDuration *prometheus.HistogramVec
|
|
|
|
morphCacheMetrics *morphCacheMetrics
|
2023-10-08 09:32:00 +00:00
|
|
|
logMetrics logger.LogMetrics
|
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{
|
2023-06-14 09:12:47 +00:00
|
|
|
Namespace: innerRingNamespace,
|
2021-12-27 12:24:05 +00:00
|
|
|
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-06-14 09:12:47 +00:00
|
|
|
Namespace: innerRingNamespace,
|
2023-03-13 06:21:28 +00:00
|
|
|
Subsystem: innerRingSubsystem,
|
|
|
|
Name: "health",
|
|
|
|
Help: "Current inner-ring node state.",
|
|
|
|
})
|
2023-05-31 09:25:32 +00:00
|
|
|
eventDuration = metrics.NewHistogramVec(prometheus.HistogramOpts{
|
2023-06-14 09:12:47 +00:00
|
|
|
Namespace: innerRingNamespace,
|
2023-05-26 10:24:41 +00:00
|
|
|
Subsystem: innerRingSubsystem,
|
|
|
|
Name: "event_duration_seconds",
|
|
|
|
Help: "Duration of processing of inner-ring events",
|
2023-06-16 07:13:22 +00:00
|
|
|
}, []string{typeLabel, successLabel})
|
2021-12-27 12:24:05 +00:00
|
|
|
)
|
|
|
|
|
2023-04-26 12:45:57 +00:00
|
|
|
return &InnerRingServiceMetrics{
|
2023-05-26 09:15:50 +00:00
|
|
|
epoch: epoch,
|
|
|
|
health: health,
|
|
|
|
eventDuration: eventDuration,
|
2023-06-14 09:12:47 +00:00
|
|
|
morphCacheMetrics: newMorphCacheMetrics(innerRingNamespace),
|
2023-10-08 09:32:00 +00:00
|
|
|
logMetrics: logger.NewLogMetrics(innerRingNamespace),
|
2021-12-27 12:24:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetEpoch updates epoch metrics.
|
2023-06-14 07:05:51 +00:00
|
|
|
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.
|
2023-06-14 07:05:51 +00:00
|
|
|
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
|
|
|
|
2023-06-14 07:05:51 +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-06-16 07:13:22 +00:00
|
|
|
typeLabel: typ,
|
|
|
|
successLabel: strconv.FormatBool(success),
|
2023-05-26 10:24:41 +00:00
|
|
|
}).Observe(d.Seconds())
|
|
|
|
}
|
2023-05-26 09:15:50 +00:00
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
func (m *InnerRingServiceMetrics) MorphCacheMetrics() MorphCacheMetrics {
|
2023-05-26 09:15:50 +00:00
|
|
|
return m.morphCacheMetrics
|
|
|
|
}
|
2023-10-08 09:32:00 +00:00
|
|
|
|
|
|
|
func (m *InnerRingServiceMetrics) LogMetrics() logger.LogMetrics {
|
|
|
|
return m.logMetrics
|
|
|
|
}
|