Skip to content

Commit

Permalink
Merge pull request #253 from andyxning/add_pprof
Browse files Browse the repository at this point in the history
add pprof
  • Loading branch information
brancz authored Sep 14, 2017
2 parents f0f94b3 + 1ad96f6 commit d316c01
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"

"net/http/pprof"

"k8s.io/kube-state-metrics/collectors"
)

Expand Down Expand Up @@ -252,15 +254,24 @@ func metricsServer(registry prometheus.Gatherer, port int) {
listenAddress := fmt.Sprintf(":%d", port)

glog.Infof("Starting metrics server: %s", listenAddress)

mux := http.NewServeMux()

mux.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index))
mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
mux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))

// Add metricsPath
http.Handle(metricsPath, promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
mux.Handle(metricsPath, promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
// Add healthzPath
http.HandleFunc(healthzPath, func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(healthzPath, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Write([]byte("ok"))
})
// Add index
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Kube Metrics Server</title></head>
<body>
Expand All @@ -272,7 +283,7 @@ func metricsServer(registry prometheus.Gatherer, port int) {
</body>
</html>`))
})
log.Fatal(http.ListenAndServe(listenAddress, nil))
log.Fatal(http.ListenAndServe(listenAddress, mux))
}

// registerCollectors creates and starts informers and initializes and
Expand Down

0 comments on commit d316c01

Please sign in to comment.