Add pprof endpoint, disabled by default

This commit is contained in:
Deluan 2023-03-15 10:56:13 -04:00
parent cad8156353
commit 1f6ec1d9f5
2 changed files with 6 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/go-chi/chi/v5/middleware"
"github.com/navidrome/navidrome/conf" "github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/consts" "github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/core" "github.com/navidrome/navidrome/core"
@ -96,6 +97,9 @@ func startServer(ctx context.Context) func() error {
core.WriteInitialMetrics() core.WriteInitialMetrics()
a.MountRouter("Prometheus metrics", conf.Server.Prometheus.MetricsPath, promhttp.Handler()) a.MountRouter("Prometheus metrics", conf.Server.Prometheus.MetricsPath, promhttp.Handler())
} }
if conf.Server.DevEnableProfiler {
a.MountRouter("Profiling", "/debug", middleware.Profiler())
}
if strings.HasPrefix(conf.Server.UILoginBackgroundURL, "/") { if strings.HasPrefix(conf.Server.UILoginBackgroundURL, "/") {
a.MountRouter("Background images", consts.DefaultUILoginBackgroundURL, backgrounds.NewHandler()) a.MountRouter("Background images", consts.DefaultUILoginBackgroundURL, backgrounds.NewHandler())
} }

View File

@ -83,6 +83,7 @@ type configOptions struct {
// DevFlags. These are used to enable/disable debugging and incomplete features // DevFlags. These are used to enable/disable debugging and incomplete features
DevLogSourceLine bool DevLogSourceLine bool
DevLogLevels map[string]string DevLogLevels map[string]string
DevEnableProfiler bool
DevAutoCreateAdminPassword string DevAutoCreateAdminPassword string
DevAutoLoginUsername string DevAutoLoginUsername string
DevActivityPanel bool DevActivityPanel bool
@ -303,6 +304,7 @@ func init() {
// DevFlags. These are used to enable/disable debugging and incomplete features // DevFlags. These are used to enable/disable debugging and incomplete features
viper.SetDefault("devlogsourceline", false) viper.SetDefault("devlogsourceline", false)
viper.SetDefault("devenableprofiler", false)
viper.SetDefault("devautocreateadminpassword", "") viper.SetDefault("devautocreateadminpassword", "")
viper.SetDefault("devautologinusername", "") viper.SetDefault("devautologinusername", "")
viper.SetDefault("devactivitypanel", true) viper.SetDefault("devactivitypanel", true)