Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 'collector.disable-go-runtime-metrics' flag #319

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 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,12 @@ 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 +280,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