add pprof handler
This commit is contained in:
17
cmd/proxy/debug.go
Normal file
17
cmd/proxy/debug.go
Normal file
@ -0,0 +1,17 @@
|
||||
//go:build pprof
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.BoolVar(&pprofEnabled, "pprof", true, "")
|
||||
|
||||
if v, ok := os.LookupEnv("SENTRY_DSN"); ok {
|
||||
sentrydsn = v
|
||||
}
|
||||
flag.StringVar(&sentrydsn, "sentry", sentrydsn, "sentry dsn to report errors")
|
||||
}
|
@ -4,6 +4,7 @@ import (
|
||||
"flag"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@ -22,6 +23,7 @@ var (
|
||||
configFilePath = "config.yaml"
|
||||
logLevel = "info"
|
||||
sentrydsn = ""
|
||||
pprofEnabled = false
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -31,12 +33,8 @@ func init() {
|
||||
if v, ok := os.LookupEnv("LOG_LEVEL"); ok {
|
||||
logLevel = v
|
||||
}
|
||||
if v, ok := os.LookupEnv("SENTRY_DSN"); ok {
|
||||
sentrydsn = v
|
||||
}
|
||||
flag.StringVar(&configFilePath, "config", configFilePath, "path to config file")
|
||||
flag.StringVar(&logLevel, "log-level", logLevel, "log level. (trace, debug, info, warn, error)")
|
||||
flag.StringVar(&sentrydsn, "sentry", sentrydsn, "sentry dsn to report errors")
|
||||
}
|
||||
|
||||
func configFromFile(path string) (*cacheproxy.Config, error) {
|
||||
@ -124,6 +122,14 @@ func main() {
|
||||
|
||||
mux.HandleFunc("GET /", server.HandleRequestWithCache)
|
||||
|
||||
if pprofEnabled {
|
||||
mux.HandleFunc("GET /debug/pprof/", pprof.Index)
|
||||
mux.HandleFunc("GET /debug/pprof/cmdline", pprof.Cmdline)
|
||||
mux.HandleFunc("GET /debug/pprof/profile", pprof.Profile)
|
||||
mux.HandleFunc("GET /debug/pprof/symbol", pprof.Symbol)
|
||||
mux.HandleFunc("GET /debug/pprof/trace", pprof.Trace)
|
||||
}
|
||||
|
||||
slog.With("addr", ":8881").Info("serving app")
|
||||
if err := http.ListenAndServe(":8881", middleware.Use(mux,
|
||||
recover.Recover(),
|
||||
|
Reference in New Issue
Block a user