forked from TrueCloudLab/frostfs-s3-gw
62 lines
1.2 KiB
Go
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)
|
|
}
|