frostfs-s3-gw/metrics/state.go
Denis Kirillov c154f934e4 [#80] Add type to metrics description
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
2023-04-20 11:14:52 +03:00

66 lines
1.3 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: mustNewGauge(appMetricsDesc[stateSubsystem][healthMetric]),
versionInfo: mustNewGaugeVec(appMetricsDesc[stateSubsystem][versionInfoMetric]),
}
}
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)
}
func (m *StateMetrics) Describe(desc chan<- *prometheus.Desc) {
if m == nil {
return
}
m.healthCheck.Describe(desc)
m.versionInfo.Describe(desc)
}
func (m *StateMetrics) Collect(ch chan<- prometheus.Metric) {
if m == nil {
return
}
m.healthCheck.Collect(ch)
m.versionInfo.Collect(ch)
}