Skip to content

Commit 5f353df

Browse files
committed
feat: add support for profiling router
1 parent a6a3762 commit 5f353df

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ type Config struct {
6565
// If not set, it defaults to "warn".
6666
LogLevel string `mapstructure:"logLevel"`
6767

68+
// EnableProfiler enables the pprof profiler on the server.
69+
// This is not recommended for production use.
70+
EnableProfiler bool `mapstructure:"enableProfiler"`
71+
6872
// ReloadFunc is called when a reload is done via http api.
6973
ReloadFunc func()
7074

redirector.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package redirector
22

33
import (
4+
"net/http"
5+
46
"github.com/armbian/redirector/middleware"
5-
"github.com/chi-middleware/logrus-logger"
7+
logger "github.com/chi-middleware/logrus-logger"
68
"github.com/go-chi/chi/v5"
9+
cm "github.com/go-chi/chi/v5/middleware"
710
lru "github.com/hashicorp/golang-lru"
811
"github.com/oschwald/maxminddb-golang"
912
"github.com/prometheus/client_golang/prometheus"
1013
"github.com/prometheus/client_golang/prometheus/promauto"
1114
"github.com/prometheus/client_golang/prometheus/promhttp"
1215
log "github.com/sirupsen/logrus"
13-
"net/http"
1416
)
1517

1618
var (
@@ -116,6 +118,11 @@ func (r *Redirector) Start() http.Handler {
116118
router.Get("/geoip", r.geoIPHandler)
117119
router.Get("/metrics", promhttp.Handler().ServeHTTP)
118120

121+
if r.config.EnableProfiler {
122+
log.Warn("Enabling pprof profiler endpoints")
123+
router.Mount("/debug", cm.Profiler())
124+
}
125+
119126
router.NotFound(r.redirectHandler)
120127

121128
if r.config.BindAddress != "" {

0 commit comments

Comments
 (0)