2021-12-27 12:24:05 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import "github.com/prometheus/client_golang/prometheus"
|
|
|
|
|
2023-03-13 06:21:28 +00:00
|
|
|
const innerRingSubsystem = "ir"
|
2021-12-27 12:24:05 +00:00
|
|
|
|
|
|
|
// InnerRingServiceMetrics contains metrics collected by inner ring.
|
|
|
|
type InnerRingServiceMetrics struct {
|
2023-04-05 10:39:02 +00:00
|
|
|
epoch metric[prometheus.Gauge]
|
|
|
|
health metric[prometheus.Gauge]
|
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-04-05 10:39:02 +00:00
|
|
|
epoch = 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-04-05 10:39:02 +00:00
|
|
|
health = newGauge(prometheus.GaugeOpts{
|
2023-03-13 06:21:28 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: innerRingSubsystem,
|
|
|
|
Name: "health",
|
|
|
|
Help: "Current inner-ring node state.",
|
|
|
|
})
|
2021-12-27 12:24:05 +00:00
|
|
|
)
|
|
|
|
|
2023-04-05 08:44:13 +00:00
|
|
|
mustRegister(epoch)
|
|
|
|
mustRegister(health)
|
2021-12-27 12:24:05 +00:00
|
|
|
|
2023-04-26 12:45:57 +00:00
|
|
|
return &InnerRingServiceMetrics{
|
2023-03-13 06:21:28 +00:00
|
|
|
epoch: epoch,
|
|
|
|
health: health,
|
2021-12-27 12:24:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetEpoch updates epoch metrics.
|
|
|
|
func (m InnerRingServiceMetrics) SetEpoch(epoch uint64) {
|
2023-04-05 10:39:02 +00:00
|
|
|
m.epoch.value.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-04-05 10:39:02 +00:00
|
|
|
m.health.value.Set(float64(s))
|
2023-03-13 06:21:28 +00:00
|
|
|
}
|