Fix separation of multiple prometheus_client outputs (#3570)
(cherry picked from commit 8484de6c12
)
This commit is contained in:
parent
fd964bd4eb
commit
8d4a09c3ea
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue