Skip to content

Commit

Permalink
Serve pprof on loopback on a separate port by default (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
ffilippopoulos authored Sep 5, 2024
1 parent c03a784 commit 18a013c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
flagMaxRequestsPerSecond = flag.Float64("max-requests-per-second", 500.0, "maximum allowed requests to the server per second")
flagMaxPeerRequestsPerSecond = flag.Float64("max-peer-requests-per-second", 50.0, "maximum allowed requests from a peer per second")
flagMetricsListenPort = flag.String("metrics-listen-port", "8080", "Listen port to serve prometheus metrics")
flagPprofListenAddress = flag.String("pprof-listen-address", "127.0.0.1:8081", "Listen address to expose pprof endpoints")

bearerRe = regexp.MustCompile(`[A-Z|a-z0-9\-\._~\+\/]+=*`)
)
Expand All @@ -54,7 +55,8 @@ func main() {
localClient, remoteClients := createClientsFromConfig(*flagClustersConfigPath)
snapshotter := xds.NewSnapshotter(*flagAuthorityName, *flagServerListenPort, *flagMaxRequestsPerSecond, *flagMaxPeerRequestsPerSecond)
xds.InitSnapMetricsCollector(snapshotter)
go serveMetricsAndPprof(fmt.Sprintf(":%s", *flagMetricsListenPort))
go serveMetrics(fmt.Sprintf(":%s", *flagMetricsListenPort))
go servePprof(*flagPprofListenAddress)

controller := controller.NewController(
localClient,
Expand All @@ -71,16 +73,28 @@ func main() {
controller.Stop()
}

func serveMetricsAndPprof(address string) {
func serveMetrics(address string) {
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
server := http.Server{
Addr: address,
Handler: mux,
}
log.Logger.Error(
"Listen and Serve",
"err", server.ListenAndServe(),
)
}

func servePprof(address string) {
mux := http.NewServeMux()
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/{action}", pprof.Index)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
server := http.Server{
Addr: address,
Handler: mux,
}
log.Logger.Error(
"Listen and Serve",
"err", server.ListenAndServe(),
Expand Down

0 comments on commit 18a013c

Please sign in to comment.