ir: Add health status #87
3 changed files with 21 additions and 4 deletions
|
@ -925,7 +925,7 @@ func New(ctx context.Context, log *logger.Logger, cfg *viper.Viper, errChan chan
|
|||
queueSize: cfg.GetUint32("workers.subnet"),
|
||||
})
|
||||
|
||||
if cfg.GetString("metrics.address") != "" {
|
||||
if cfg.GetString("prometheus.address") != "" {
|
||||
m := metrics.NewInnerRingMetrics()
|
||||
server.metrics = &m
|
||||
}
|
||||
|
|
|
@ -167,6 +167,9 @@ func (s *Server) ResetEpochTimer(h uint32) error {
|
|||
|
||||
func (s *Server) setHealthStatus(hs control.HealthStatus) {
|
||||
s.healthStatus.Store(hs)
|
||||
if s.metrics != nil {
|
||||
s.metrics.SetHealth(int32(hs))
|
||||
}
|
||||
}
|
||||
|
||||
// HealthStatus returns the current health status of the IR application.
|
||||
|
|
|
@ -2,11 +2,12 @@ package metrics
|
|||
|
||||
import "github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
const innerRingSubsystem = "object"
|
||||
const innerRingSubsystem = "ir"
|
||||
|
||||
// InnerRingServiceMetrics contains metrics collected by inner ring.
|
||||
type InnerRingServiceMetrics struct {
|
||||
epoch prometheus.Gauge
|
||||
epoch prometheus.Gauge
|
||||
health prometheus.Gauge
|
||||
}
|
||||
|
||||
// NewInnerRingMetrics returns new instance of metrics collectors for inner ring.
|
||||
|
@ -18,12 +19,20 @@ func NewInnerRingMetrics() InnerRingServiceMetrics {
|
|||
Name: "epoch",
|
||||
Help: "Current epoch as seen by inner-ring node.",
|
||||
})
|
||||
health = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: innerRingSubsystem,
|
||||
Name: "health",
|
||||
Help: "Current inner-ring node state.",
|
||||
})
|
||||
)
|
||||
|
||||
prometheus.MustRegister(epoch)
|
||||
prometheus.MustRegister(health)
|
||||
|
||||
return InnerRingServiceMetrics{
|
||||
epoch: epoch,
|
||||
epoch: epoch,
|
||||
health: health,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,3 +40,8 @@ func NewInnerRingMetrics() InnerRingServiceMetrics {
|
|||
func (m InnerRingServiceMetrics) SetEpoch(epoch uint64) {
|
||||
m.epoch.Set(float64(epoch))
|
||||
}
|
||||
|
||||
// SetHealth updates health metrics.
|
||||
func (m InnerRingServiceMetrics) SetHealth(s int32) {
|
||||
m.health.Set(float64(s))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue