Skip to content

Commit

Permalink
feat: enable pprof endpoints on localhost (#3110)
Browse files Browse the repository at this point in the history
* feat: enable pprof endpoints on localhost
  • Loading branch information
cgrinds authored Aug 19, 2024
1 parent 504a2c1 commit faead9d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cmd/exporters/prometheus/httpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/netapp/harvest/v2/pkg/set"
"net"
"net/http"
"net/http/pprof"
"strconv"
"strings"
"time"
Expand All @@ -23,6 +24,11 @@ func (p *Prometheus) startHTTPD(addr string, port int) {
mux := http.NewServeMux()
mux.HandleFunc("/", p.ServeInfo)
mux.HandleFunc("/metrics", p.ServeMetrics)
mux.HandleFunc("localhost/debug/pprof/", pprof.Index)
mux.HandleFunc("localhost/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("localhost/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("localhost/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("localhost/debug/pprof/trace", pprof.Trace)

server := &http.Server{
Addr: addr + ":" + strconv.Itoa(port),
Expand Down
4 changes: 3 additions & 1 deletion cmd/poller/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ func (p *Poller) Init() error {

logger = logging.Configure(logConfig)

// if profiling port > 0 start profiling service
// If profiling port > 0, start an HTTP server on that port with the profiling endpoints setup.
// When using the Prometheus exporter, the profiling endpoints will be setup automatically in
// cmd/exporters/prometheus/httpd.go
if p.options.Profiling > 0 {
addr := fmt.Sprintf("localhost:%d", p.options.Profiling)
logger.Info().Msgf("profiling enabled on [%s]", addr)
Expand Down

0 comments on commit faead9d

Please sign in to comment.