daemon: env var for autostarting pprof endpoint

This commit is contained in:
Christian Schwarz 2019-09-07 19:50:57 +02:00
parent a0cf9cff2a
commit 921b34235e
2 changed files with 19 additions and 0 deletions

View File

@ -16,6 +16,7 @@ import (
"github.com/zrepl/zrepl/daemon/job" "github.com/zrepl/zrepl/daemon/job"
"github.com/zrepl/zrepl/daemon/nethelpers" "github.com/zrepl/zrepl/daemon/nethelpers"
"github.com/zrepl/zrepl/logger" "github.com/zrepl/zrepl/logger"
"github.com/zrepl/zrepl/util/envconst"
"github.com/zrepl/zrepl/version" "github.com/zrepl/zrepl/version"
"github.com/zrepl/zrepl/zfs" "github.com/zrepl/zrepl/zfs"
) )
@ -86,6 +87,12 @@ func (j *controlJob) Run(ctx context.Context) {
} }
pprofServer := NewPProfServer(ctx) pprofServer := NewPProfServer(ctx)
if listen := envconst.String("ZREPL_DAEMON_AUTOSTART_PPROF_SERVER", ""); listen != "" {
pprofServer.Control(PprofServerControlMsg{
Run: true,
HttpListenAddress: listen,
})
}
mux := http.NewServeMux() mux := http.NewServeMux()
mux.Handle(ControlJobEndpointPProf, mux.Handle(ControlJobEndpointPProf,

View File

@ -56,3 +56,15 @@ func Bool(varname string, def bool) bool {
cache.Store(varname, d) cache.Store(varname, d)
return d return d
} }
func String(varname string, def string) string {
if v, ok := cache.Load(varname); ok {
return v.(string)
}
e := os.Getenv(varname)
if e == "" {
return def
}
cache.Store(varname, e)
return e
}