add profiler support

profiling is now available via the HTTP base URL /debug/pprof/

examples, use this URL to start and download a 30 seconds CPU profile:

/debug/pprof/profile?seconds=30

use this URL to profile used memory:

/debug/pprof/heap?gc=1

use this URL to profile allocated memory:

/debug/pprof/allocs?gc=1

Full docs here:

https://golang.org/pkg/net/http/pprof/
This commit is contained in:
Nicola Murino
2020-03-15 15:16:35 +01:00
parent f4e872c782
commit 81c8e8d898
9 changed files with 44 additions and 12 deletions

View File

@@ -30,6 +30,7 @@ const (
dumpDataPath = "/api/v1/dumpdata"
loadDataPath = "/api/v1/loaddata"
metricsPath = "/metrics"
pprofBasePath = "/debug"
webBasePath = "/web"
webUsersPath = "/web/users"
webUserPath = "/web/user"
@@ -85,7 +86,7 @@ func SetDataProvider(provider dataprovider.Provider) {
}
// Initialize the HTTP server
func (c Conf) Initialize(configDir string) error {
func (c Conf) Initialize(configDir string, profiler bool) error {
var err error
logger.Debug(logSender, "", "initializing HTTP server with config %+v", c)
backupsPath = getConfigPath(c.BackupsPath, configDir)
@@ -103,7 +104,7 @@ func (c Conf) Initialize(configDir string) error {
certificateFile := getConfigPath(c.CertificateFile, configDir)
certificateKeyFile := getConfigPath(c.CertificateKeyFile, configDir)
loadTemplates(templatesPath)
initializeRouter(staticFilesPath)
initializeRouter(staticFilesPath, profiler)
httpServer := &http.Server{
Addr: fmt.Sprintf("%s:%d", c.BindAddress, c.BindPort),
Handler: router,