profiling: Support binding pprof server to custom network interfaces (#36580)

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
This commit is contained in:
Victor Cinaglia
2021-08-18 07:28:39 -04:00
committed by GitHub
parent 552ecfeda3
commit 0819d15942
4 changed files with 28 additions and 13 deletions

View File

@ -63,6 +63,7 @@ func main() {
v = flag.Bool("v", false, "prints current version and exits")
vv = flag.Bool("vv", false, "prints current version, all dependencies and exits")
profile = flag.Bool("profile", false, "Turn on pprof profiling")
profileAddr = flag.String("profile-addr", "localhost", "Define custom address for profiling")
profilePort = flag.Uint64("profile-port", 6060, "Define custom port for profiling")
tracing = flag.Bool("tracing", false, "Turn on tracing")
tracingFile = flag.String("tracing-file", "trace.out", "Define tracing output file")
@ -83,7 +84,7 @@ func main() {
os.Exit(0)
}
profileDiagnostics := newProfilingDiagnostics(*profile, *profilePort)
profileDiagnostics := newProfilingDiagnostics(*profile, *profileAddr, *profilePort)
if err := profileDiagnostics.overrideWithEnv(); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
@ -96,10 +97,10 @@ func main() {
}
if profileDiagnostics.enabled {
fmt.Println("diagnostics: pprof profiling enabled", "port", profileDiagnostics.port)
fmt.Println("diagnostics: pprof profiling enabled", "addr", profileDiagnostics.addr, "port", profileDiagnostics.port)
runtime.SetBlockProfileRate(1)
go func() {
err := http.ListenAndServe(fmt.Sprintf("localhost:%d", profileDiagnostics.port), nil)
err := http.ListenAndServe(fmt.Sprintf("%s:%d", profileDiagnostics.addr, profileDiagnostics.port), nil)
if err != nil {
panic(err)
}