frostfs-s3-gw/metrics/gate.go
Pavel Pogodaev 80afebff7a
All checks were successful
/ DCO (pull_request) Successful in 2m26s
/ Vulncheck (pull_request) Successful in 2m27s
/ Builds (pull_request) Successful in 2m36s
/ Lint (pull_request) Successful in 2m30s
/ Tests (pull_request) Successful in 2m9s
[#502] Add Dropped logs (by sampling) metric
Signed-off-by: Pavel Pogodaev <p.pogodaev@yadro.com>
2024-11-20 15:05:04 +03:00

86 lines
2.2 KiB
Go

package metrics
import (
"net/http"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool/tree"
"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 TreePoolStatistic interface {
Statistic() tree.Statistic
}
type GateMetrics struct {
registry prometheus.Registerer
State *StateMetrics
Pool *poolMetricsCollector
Billing *billingMetrics
Stats *APIStatMetrics
HTTPServer *httpServerMetrics
TreePool *treePoolMetricsCollector
Logs *logsMetric
}
func NewGateMetrics(scraper StatisticScraper, treeScraper TreePoolStatistic, registry prometheus.Registerer) *GateMetrics {
stateMetric := newStateMetrics()
registry.MustRegister(stateMetric)
poolMetric := newPoolMetricsCollector(scraper)
registry.MustRegister(poolMetric)
billingMetric := newBillingMetrics()
billingMetric.Register()
statsMetric := newAPIStatMetrics()
registry.MustRegister(statsMetric)
serverMetric := newHTTPServerMetrics()
registry.MustRegister(serverMetric)
treePoolMetric := newTreePoolMetricsCollector(treeScraper)
registry.MustRegister(treePoolMetric)
logsMetrics := newLogsMetrics()
registry.MustRegister(logsMetrics)
return &GateMetrics{
registry: registry,
State: stateMetric,
Pool: poolMetric,
Billing: billingMetric,
Stats: statsMetric,
HTTPServer: serverMetric,
TreePool: treePoolMetric,
Logs: logsMetrics,
}
}
func (g *GateMetrics) Unregister() {
g.registry.Unregister(g.State)
g.registry.Unregister(g.Pool)
g.Billing.Unregister()
g.registry.Unregister(g.Stats)
g.registry.Unregister(g.HTTPServer)
g.registry.Unregister(g.Logs)
}
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()
}