mirror of
https://github.com/slackhq/nebula.git
synced 2026-02-14 08:44:24 +01:00
add stats.pprof flag to expose pprof on stats listener
This commit is contained in:
@@ -318,6 +318,11 @@ logging:
|
|||||||
#subsystem: nebula
|
#subsystem: nebula
|
||||||
#interval: 10s
|
#interval: 10s
|
||||||
|
|
||||||
|
# enables pprof endpoints on the stats listener
|
||||||
|
# endpoints: /debug/pprof/, /debug/pprof/cmdline, /debug/pprof/profile,
|
||||||
|
# /debug/pprof/symbol, /debug/pprof/trace
|
||||||
|
#pprof: false
|
||||||
|
|
||||||
# enables counter metrics for meta packets
|
# enables counter metrics for meta packets
|
||||||
# e.g.: `messages.tx.handshake`
|
# e.g.: `messages.tx.handshake`
|
||||||
# NOTE: `message.{tx,rx}.recv_error` is always emitted
|
# NOTE: `message.{tx,rx}.recv_error` is always emitted
|
||||||
|
|||||||
11
stats.go
11
stats.go
@@ -6,6 +6,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/pprof"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -93,6 +94,8 @@ func startPrometheusStats(l *logrus.Logger, i time.Duration, c *config.C, buildV
|
|||||||
return nil, fmt.Errorf("stats.path should not be empty")
|
return nil, fmt.Errorf("stats.path should not be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enablePprof := c.GetBool("stats.pprof", false)
|
||||||
|
|
||||||
pr := prometheus.NewRegistry()
|
pr := prometheus.NewRegistry()
|
||||||
pClient := mp.NewPrometheusProvider(metrics.DefaultRegistry, namespace, subsystem, pr, i)
|
pClient := mp.NewPrometheusProvider(metrics.DefaultRegistry, namespace, subsystem, pr, i)
|
||||||
if !configTest {
|
if !configTest {
|
||||||
@@ -119,6 +122,14 @@ func startPrometheusStats(l *logrus.Logger, i time.Duration, c *config.C, buildV
|
|||||||
startFn = func() {
|
startFn = func() {
|
||||||
l.Infof("Prometheus stats listening on %s at %s", listen, path)
|
l.Infof("Prometheus stats listening on %s at %s", listen, path)
|
||||||
http.Handle(path, promhttp.HandlerFor(pr, promhttp.HandlerOpts{ErrorLog: l}))
|
http.Handle(path, promhttp.HandlerFor(pr, promhttp.HandlerOpts{ErrorLog: l}))
|
||||||
|
if enablePprof {
|
||||||
|
l.Info("pprof endpoints enabled on stats listener")
|
||||||
|
http.HandleFunc("GET /debug/pprof/", pprof.Index)
|
||||||
|
http.HandleFunc("GET /debug/pprof/cmdline", pprof.Cmdline)
|
||||||
|
http.HandleFunc("GET /debug/pprof/profile", pprof.Profile)
|
||||||
|
http.HandleFunc("GET /debug/pprof/symbol", pprof.Symbol)
|
||||||
|
http.HandleFunc("GET /debug/pprof/trace", pprof.Trace)
|
||||||
|
}
|
||||||
log.Fatal(http.ListenAndServe(listen, nil))
|
log.Fatal(http.ListenAndServe(listen, nil))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user