Skip to content

Commit

Permalink
Add version metric (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov authored May 12, 2023
2 parents 129e09c + 380af94 commit ce89b38
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/s3-gw/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (a *App) initAPI(ctx context.Context) {

func (a *App) initMetrics() {
gateMetricsProvider := newGateMetrics(neofs.NewPoolStatistic(a.pool))
gateMetricsProvider.SetGWVersion(version.Version)
a.metrics = newAppMetrics(a.log, gateMetricsProvider, a.cfg.GetBool(cfgPrometheusEnabled))
}

Expand Down
13 changes: 13 additions & 0 deletions cmd/s3-gw/app_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type GateMetrics struct {

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

type poolMetricsCollector struct {
Expand Down Expand Up @@ -80,6 +81,14 @@ func newStateMetrics() *stateMetrics {
Name: "health",
Help: "Current S3 gateway state",
}),
gwVersion: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Help: "Gateway version",
Name: "version",
Namespace: namespace,
},
[]string{"version"},
),
}
}

Expand Down Expand Up @@ -238,3 +247,7 @@ func NewPrometheusService(v *viper.Viper, log *zap.Logger) *Service {
log: log.With(zap.String("service", "Prometheus")),
}
}

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

0 comments on commit ce89b38

Please sign in to comment.