feat: expose expvars as profiling endpoint

This commit is contained in:
wpetit 2024-10-02 12:09:02 +02:00
parent 0ff9391a1b
commit f3b553cb10
2 changed files with 4 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package admin
import ( import (
"context" "context"
"expvar"
"fmt" "fmt"
"log" "log"
"net" "net"
@ -176,6 +177,7 @@ func (s *Server) run(parentCtx context.Context, addrs chan net.Addr, errs chan e
r.HandleFunc("/profile", pprof.Profile) r.HandleFunc("/profile", pprof.Profile)
r.HandleFunc("/symbol", pprof.Symbol) r.HandleFunc("/symbol", pprof.Symbol)
r.HandleFunc("/trace", pprof.Trace) r.HandleFunc("/trace", pprof.Trace)
r.Handle("/vars", expvar.Handler())
r.HandleFunc("/{name}", func(w http.ResponseWriter, r *http.Request) { r.HandleFunc("/{name}", func(w http.ResponseWriter, r *http.Request) {
name := chi.URLParam(r, "name") name := chi.URLParam(r, "name")
pprof.Handler(name).ServeHTTP(w, r) pprof.Handler(name).ServeHTTP(w, r)

View File

@ -3,6 +3,7 @@ package proxy
import ( import (
"bytes" "bytes"
"context" "context"
"expvar"
"fmt" "fmt"
"html/template" "html/template"
"io" "io"
@ -171,6 +172,7 @@ func (s *Server) run(parentCtx context.Context, addrs chan net.Addr, errs chan e
r.HandleFunc("/profile", pprof.Profile) r.HandleFunc("/profile", pprof.Profile)
r.HandleFunc("/symbol", pprof.Symbol) r.HandleFunc("/symbol", pprof.Symbol)
r.HandleFunc("/trace", pprof.Trace) r.HandleFunc("/trace", pprof.Trace)
r.Handle("/vars", expvar.Handler())
r.HandleFunc("/{name}", func(w http.ResponseWriter, r *http.Request) { r.HandleFunc("/{name}", func(w http.ResponseWriter, r *http.Request) {
name := chi.URLParam(r, "name") name := chi.URLParam(r, "name")
pprof.Handler(name).ServeHTTP(w, r) pprof.Handler(name).ServeHTTP(w, r)