Fix separation of multiple prometheus_client outputs (#3570)

This commit is contained in:
Daniel Nelson 2017-12-11 18:00:19 -08:00 committed by GitHub
parent 09fddafed6
commit 2cf34dd875
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,