Add pprof
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user