frostfs-s3-gw/cmd/s3-gw/app_metrics.go

69 lines
1.3 KiB
Go
Raw Normal View History

2020-07-06 09:18:16 +00:00
package main
import (
"net/http"
"github.com/prometheus/client_golang/prometheus"
2020-07-06 09:18:16 +00:00
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/viper"
2020-07-12 23:00:47 +00:00
"go.uber.org/zap"
2020-07-06 09:18:16 +00:00
)
const (
namespace = "neofs_s3_gw"
stateSubsystem = "state"
)
type GateMetrics struct {
stateMetrics
}
type stateMetrics struct {
healthCheck prometheus.Gauge
}
func newGateMetrics() *GateMetrics {
stateMetric := newStateMetrics()
stateMetric.register()
return &GateMetrics{
stateMetrics: *stateMetric,
2020-07-06 09:18:16 +00:00
}
}
2020-07-06 09:18:16 +00:00
func newStateMetrics() *stateMetrics {
return &stateMetrics{
healthCheck: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: stateSubsystem,
Name: "health",
Help: "Current S3 gateway state",
}),
}
}
func (m stateMetrics) register() {
prometheus.MustRegister(m.healthCheck)
}
func (m stateMetrics) SetHealth(s int32) {
m.healthCheck.Set(float64(s))
}
// NewPrometheusService creates a new service for gathering prometheus metrics.
func NewPrometheusService(v *viper.Viper, log *zap.Logger) *Service {
if log == nil {
return nil
}
return &Service{
Server: &http.Server{
Addr: v.GetString(cfgPrometheusAddress),
Handler: promhttp.Handler(),
},
enabled: v.GetBool(cfgPrometheusEnabled),
serviceType: "Prometheus",
log: log.With(zap.String("service", "Prometheus")),
}
2020-07-06 09:18:16 +00:00
}