frostfs-s3-gw/metrics/state.go
Denis Kirillov 9e72fe1662 [#80] Refactor metrics, support dump descriptions
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
2023-04-20 11:14:52 +03:00

62 lines
1.2 KiB
Go

package metrics
import (
"github.com/prometheus/client_golang/prometheus"
)
const stateSubsystem = "state"
const (
healthMetric = "health"
versionInfoMetric = "version_info"
)
// HealthStatus of the gate application.
type HealthStatus int32
const (
HealthStatusUndefined HealthStatus = 0
HealthStatusStarting HealthStatus = 1
HealthStatusReady HealthStatus = 2
HealthStatusShuttingDown HealthStatus = 3
)
type StateMetrics struct {
healthCheck prometheus.Gauge
versionInfo *prometheus.GaugeVec
}
func newStateMetrics() *StateMetrics {
return &StateMetrics{
healthCheck: NewGauge(AppMetricsDesc[stateSubsystem][healthMetric]),
versionInfo: NewGaugeVec(AppMetricsDesc[stateSubsystem][versionInfoMetric]),
}
}
func (m *StateMetrics) register() {
if m == nil {
return
}
prometheus.MustRegister(m.healthCheck)
}
func (m *StateMetrics) unregister() {
if m == nil {
return
}
prometheus.Unregister(m.healthCheck)
}
func (m *StateMetrics) SetHealth(s HealthStatus) {
if m == nil {
return
}
m.healthCheck.Set(float64(s))
}
func (m *StateMetrics) SetVersion(ver string) {
if m == nil {
return
}
m.versionInfo.WithLabelValues(ver).Set(1)
}