Skip to content

Commit 9384f0f

Browse files
authored
Merge pull request #4 from RedisLabs/Add-go-runtime-metrics-flag
Added 'collector.disable-go-runtime-metrics' flag
2 parents 7ef0b73 + 2630978 commit 9384f0f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

cmd/process-exporter/main.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"flag"
55
"fmt"
6+
"github.com/prometheus/client_golang/prometheus/collectors"
67
"log"
78
"net/http"
89
_ "net/http/pprof"
@@ -140,9 +141,12 @@ func (nmr *nameMapperRegex) MatchAndName(nacl common.ProcAttributes) (bool, stri
140141
return false, ""
141142
}
142143

144+
// Create a new custom Prometheus registry
145+
var registry = prometheus.NewRegistry()
146+
143147
func init() {
144148
promVersion.Version = version
145-
prometheus.MustRegister(verCollector.NewCollector("process_exporter"))
149+
registry.MustRegister(verCollector.NewCollector("process_exporter"))
146150
}
147151

148152
func main() {
@@ -180,6 +184,8 @@ func main() {
180184
showVersion = flag.Bool("version", false,
181185
"print version information and exit")
182186
removeEmptyGroups = flag.Bool("remove-empty-groups", false, "forget process groups with no processes")
187+
disableGoMetrics = flag.Bool("collector.disable-go-runtime-metrics", false,
188+
"Disable collection of Go runtime metrics")
183189
)
184190
flag.Parse()
185191

@@ -256,7 +262,11 @@ func main() {
256262
log.Fatalf("Error initializing: %v", err)
257263
}
258264

259-
prometheus.MustRegister(pc)
265+
registry.MustRegister(pc)
266+
if !*disableGoMetrics {
267+
// Register Go runtime metrics if the flag is not set
268+
registry.MustRegister(collectors.NewGoCollector())
269+
}
260270

261271
if *onceToStdoutDelay != 0 {
262272
// We throw away the first result because that first collection primes the pump, and
@@ -269,7 +279,7 @@ func main() {
269279
return
270280
}
271281

272-
http.Handle(*metricsPath, promhttp.Handler())
282+
http.Handle(*metricsPath, promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
273283

274284
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
275285
w.Write([]byte(`<html>

0 commit comments

Comments
 (0)