Skip to content

Commit

Permalink
app: Add version metric
Browse files Browse the repository at this point in the history
closes #87

Signed-off-by: Evgenii Baidakov <[email protected]>
  • Loading branch information
smallhive committed Aug 31, 2023
1 parent c9b589f commit 529cea7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/neofs-rest-gw/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ func newNeofsAPI(ctx context.Context, logger *zap.Logger, v *viper.Viper) (*hand
apiPrm.PrometheusService = metrics.NewPrometheusService(logger, prometheusConfig)
if prometheusConfig.Enabled {
apiPrm.GateMetric = metrics.NewGateMetrics(poolStat)
apiPrm.GateMetric.SetGWVersion(Version)
}

apiPrm.ServiceShutdownTimeout = defaultShutdownTimeout
Expand Down
14 changes: 14 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type GateMetrics struct {

type stateMetrics struct {
healthCheck prometheus.Gauge
gwVersion *prometheus.GaugeVec
}

type poolMetricsCollector struct {
Expand Down Expand Up @@ -71,11 +72,20 @@ func newStateMetrics() *stateMetrics {
Name: "health",
Help: "Current REST gateway state",
}),
gwVersion: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Help: "Gateway version",
Name: "version",
Namespace: namespace,
},
[]string{"version"},
),
}
}

func (m stateMetrics) register() {
prometheus.MustRegister(m.healthCheck)
prometheus.MustRegister(m.gwVersion)
}

func (m stateMetrics) SetHealth(s int32) {
Expand Down Expand Up @@ -224,3 +234,7 @@ func NewPrometheusService(log *zap.Logger, cfg Config) *Service {
log: log.With(zap.String("service", "Prometheus")),
}
}

func (g *GateMetrics) SetGWVersion(ver string) {
g.gwVersion.WithLabelValues(ver).Add(1)
}

0 comments on commit 529cea7

Please sign in to comment.