Fix separation of multiple prometheus_client outputs (#3570)

(cherry picked from commit 8484de6c12)
This commit is contained in:
Daniel Nelson 2017-12-11 18:00:19 -08:00 committed by Daniel Nelson
parent fd964bd4eb
commit 8d4a09c3ea
No known key found for this signature in database
GPG Key ID: CAAD59C9444F6155
1 changed files with 14 additions and 6 deletions

View File

@ -79,19 +79,28 @@ var sampleConfig = `
`
func (p *PrometheusClient) Start() error {
prometheus.Register(p)
defaultCollectors := map[string]bool{
"gocollector": true,
"process": true,
}
for _, collector := range p.CollectorsExclude {
delete(defaultCollectors, collector)
}
registry := prometheus.NewRegistry()
for collector, _ := range defaultCollectors {
switch collector {
case "gocollector":
prometheus.Unregister(prometheus.NewGoCollector())
registry.Register(prometheus.NewGoCollector())
case "process":
prometheus.Unregister(prometheus.NewProcessCollector(os.Getpid(), ""))
registry.Register(prometheus.NewProcessCollector(os.Getpid(), ""))
default:
return fmt.Errorf("unrecognized collector %s", collector)
}
}
registry.Register(p)
if p.Listen == "" {
p.Listen = "localhost:9273"
}
@ -102,8 +111,7 @@ func (p *PrometheusClient) Start() error {
mux := http.NewServeMux()
mux.Handle(p.Path, promhttp.HandlerFor(
prometheus.DefaultGatherer,
promhttp.HandlerOpts{ErrorHandling: promhttp.ContinueOnError}))
registry, promhttp.HandlerOpts{ErrorHandling: promhttp.ContinueOnError}))
p.server = &http.Server{
Addr: p.Listen,