diff --git a/README.md b/README.md index bcedec7..5a77c01 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Zooid supports a few environment variables, which configure shared resources lik - `DATA` - where to store databse files. Defaults to `./data`. - `API_HOST` - the hostname on which to expose the management API. If not set, the API is disabled. - `API_WHITELIST` - a comma-separated list of nostr hex pubkeys authorized to use the management API. Required when `API_HOST` is set. +- `PPROF_ADDR` - an http host to serve pprof stats on. ## Configuration diff --git a/cmd/relay/main.go b/cmd/relay/main.go index 3cb7b86..1f4fe1d 100644 --- a/cmd/relay/main.go +++ b/cmd/relay/main.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "net/http" + _ "net/http/pprof" "os" "os/signal" "syscall" @@ -22,6 +23,18 @@ func main() { apiHost := zooid.Env("API_HOST") apiWhitelist := zooid.Env("API_WHITELIST") configDir := zooid.Env("CONFIG") + pprofAddr := zooid.Env("PPROF_ADDR") + + // pprof server — only starts when PPROF_ADDR is set. Bind to + // 127.0.0.1:6060 (or similar) and tunnel via SSH; never expose publicly. + if pprofAddr != "" { + go func() { + log.Printf("pprof listening on %s\n", pprofAddr) + if err := http.ListenAndServe(pprofAddr, nil); err != nil { + log.Printf("pprof server error: %v\n", err) + } + }() + } // Create the main handler mainHandler := http.HandlerFunc( diff --git a/relay b/relay deleted file mode 100755 index fe6ec1c..0000000 Binary files a/relay and /dev/null differ