Skip to content

Commit

Permalink
Fix separation of multiple prometheus_client outputs (influxdata#3570)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored Dec 12, 2017
1 parent ab8376d commit 8484de6
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions plugins/outputs/prometheus_client/prometheus_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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,
Expand Down

0 comments on commit 8484de6

Please sign in to comment.