frostfs-s3-gw/metrics/gate.go
Denis Kirillov 499f4c6495
All checks were successful
/ DCO (pull_request) Successful in 3m45s
/ Lint (pull_request) Successful in 3m29s
/ Tests (1.19) (pull_request) Successful in 2m44s
/ Tests (1.20) (pull_request) Successful in 3m19s
/ Vulncheck (pull_request) Successful in 4m40s
/ Builds (1.19) (pull_request) Successful in 2m58s
/ Builds (1.20) (pull_request) Successful in 1m47s
[#155] metrics: Use default registerer for app metrics
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
2023-06-28 12:00:47 +03:00

66 lines
1.6 KiB
Go

package metrics
import (
"net/http"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
dto "github.com/prometheus/client_model/go"
)
const namespace = "frostfs_s3_gw"
type StatisticScraper interface {
Statistic() pool.Statistic
}
type GateMetrics struct {
registry prometheus.Registerer
State *StateMetrics
Pool *poolMetricsCollector
Billing *billingMetrics
Stats *APIStatMetrics
}
func NewGateMetrics(scraper StatisticScraper) *GateMetrics {
registry := prometheus.DefaultRegisterer
stateMetric := newStateMetrics()
registry.MustRegister(stateMetric)
poolMetric := newPoolMetricsCollector(scraper)
registry.MustRegister(poolMetric)
billingMetric := newBillingMetrics()
billingMetric.Register()
statsMetric := newAPIStatMetrics()
registry.MustRegister(statsMetric)
return &GateMetrics{
registry: registry,
State: stateMetric,
Pool: poolMetric,
Billing: billingMetric,
Stats: statsMetric,
}
}
func (g *GateMetrics) Unregister() {
g.registry.Unregister(g.State)
g.registry.Unregister(g.Pool)
g.Billing.Unregister()
g.registry.Unregister(g.Stats)
}
func (g *GateMetrics) Handler() http.Handler {
handler := http.NewServeMux()
handler.Handle("/", promhttp.Handler())
handler.Handle("/metrics/billing", promhttp.HandlerFor(g.Billing.Gatherer(), promhttp.HandlerOpts{}))
return handler
}
func (g *GateMetrics) Gather() ([]*dto.MetricFamily, error) {
return prometheus.Gatherers([]prometheus.Gatherer{g.Billing.Gatherer()}).Gather()
}