Skip to content

Commit

Permalink
Merge pull request #4 from RedisLabs/Add-go-runtime-metrics-flag
Browse files Browse the repository at this point in the history
Added 'collector.disable-go-runtime-metrics' flag
  • Loading branch information
Amir-Hadadi authored Oct 29, 2024
2 parents 7ef0b73 + 2630978 commit 9384f0f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cmd/process-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"github.com/prometheus/client_golang/prometheus/collectors"
"log"
"net/http"
_ "net/http/pprof"
Expand Down Expand Up @@ -140,9 +141,12 @@ func (nmr *nameMapperRegex) MatchAndName(nacl common.ProcAttributes) (bool, stri
return false, ""
}

// Create a new custom Prometheus registry
var registry = prometheus.NewRegistry()

func init() {
promVersion.Version = version
prometheus.MustRegister(verCollector.NewCollector("process_exporter"))
registry.MustRegister(verCollector.NewCollector("process_exporter"))
}

func main() {
Expand Down Expand Up @@ -180,6 +184,8 @@ func main() {
showVersion = flag.Bool("version", false,
"print version information and exit")
removeEmptyGroups = flag.Bool("remove-empty-groups", false, "forget process groups with no processes")
disableGoMetrics = flag.Bool("collector.disable-go-runtime-metrics", false,
"Disable collection of Go runtime metrics")
)
flag.Parse()

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

prometheus.MustRegister(pc)
registry.MustRegister(pc)
if !*disableGoMetrics {
// Register Go runtime metrics if the flag is not set
registry.MustRegister(collectors.NewGoCollector())
}

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

http.Handle(*metricsPath, promhttp.Handler())
http.Handle(*metricsPath, promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))

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

0 comments on commit 9384f0f

Please sign in to comment.