Skip to content

Commit

Permalink
Use prometheus.Gatherers to avoid duplicating std collectors
Browse files Browse the repository at this point in the history
Seen on github.com/minio/minio/cmd/metrics.go

This way, the ProcessCollector and the GoCollector will operate on the
Prometheus DefaultRegistry, whose durability is the same as the process.

On the other hand, the registry we instantiate per server will live and die with
it.

I was inclined to implement this because I think that otherwise we ended up with
a redundant set of *Collectors, ones instantiated by us, and the othe ones
instantiated by the prometheus library, as goodies of the DefaultRegistry.

Besides, now I know how to make use of multiple registries (via Gatherers, which
kinda melds them).
  • Loading branch information
panchoh authored and iknite committed Feb 19, 2019
1 parent 05f3728 commit 0897e99
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
6 changes: 5 additions & 1 deletion api/metricshttp/metricshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import (

func NewMetricsHTTP(r *prometheus.Registry) *http.ServeMux {
mux := http.NewServeMux()
g := prometheus.Gatherers{
prometheus.DefaultGatherer,
r,
}
mux.Handle(
"/metrics",
promhttp.InstrumentMetricHandler(
r,
promhttp.HandlerFor(
r,
g,
promhttp.HandlerOpts{},
),
),
Expand Down
9 changes: 0 additions & 9 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,6 @@ func NewServer(conf *Config) (*Server, error) {
server.prometheusRegistry = r
metricsMux := metricshttp.NewMetricsHTTP(r)

r.MustRegister(
prometheus.NewProcessCollector(
prometheus.ProcessCollectorOpts{},
),
)
r.MustRegister(
prometheus.NewGoCollector(),
)

server.metricsServer = newHTTPServer("localhost:9990", metricsMux)
}

Expand Down

0 comments on commit 0897e99

Please sign in to comment.