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) }