Skip to content

Commit

Permalink
Merge pull request #1768 from guybrush/BIDS-1507/pprof
Browse files Browse the repository at this point in the history
metrics: enable pprof via config
  • Loading branch information
recy21 authored Feb 1, 2023
2 parents 045385a + a244005 commit ba435ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package metrics

import (
"database/sql"
"eth2-exporter/utils"
"eth2-exporter/version"
"net/http"
"net/http/pprof"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -146,6 +148,18 @@ func Serve(addr string) error {
</body>
</html>`))
}))

if utils.Config.Metrics.Pprof {
logrus.WithFields(logrus.Fields{"addr": addr}).Infof("serving pprof")
router.HandleFunc("/debug/pprof/", pprof.Index)
router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
router.HandleFunc("/debug/pprof/profile", pprof.Profile)
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
router.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
router.Handle("/debug/pprof/heap", pprof.Handler("heap"))
router.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
}

srv := &http.Server{
ReadTimeout: time.Second * 10,
WriteTimeout: time.Second * 10,
Expand Down
1 change: 1 addition & 0 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ type Config struct {
Metrics struct {
Enabled bool `yaml:"enabled" envconfig:"METRICS_ENABLED"`
Address string `yaml:"address" envconfig:"METRICS_ADDRESS"`
Pprof bool `yaml:"pprof" envconfig:"METRICS_PPROF"`
} `yaml:"metrics"`
Notifications struct {
Enabled bool `yaml:"enabled" envconfig:"FRONTEND_NOTIFICATIONS_ENABLED"`
Expand Down

0 comments on commit ba435ae

Please sign in to comment.