mirror of
https://github.com/slackhq/nebula.git
synced 2025-01-11 03:48:12 +00:00
0af7e6a1dd
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
34 lines
823 B
Go
34 lines
823 B
Go
package nebula
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
_ "net/http/pprof"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/slackhq/nebula/config"
|
|
)
|
|
|
|
// startHttp returns a function to start an http server with pprof support and optionally a provided stats
|
|
// http handler.
|
|
func startHttp(l *logrus.Logger, c *config.C, listen string, statsHandler statsHandlerFunc) (func(), error) {
|
|
if listen == "" {
|
|
return nil, nil
|
|
}
|
|
|
|
var statsPath string
|
|
if statsHandler != nil {
|
|
statsPath = c.GetString("stats.path", "")
|
|
if statsPath == "" {
|
|
return nil, fmt.Errorf("stats.path should not be empty")
|
|
}
|
|
}
|
|
|
|
return func() {
|
|
l.Infof("Go pprof handler listening on %s at /debug/pprof", listen)
|
|
if statsHandler != nil {
|
|
http.Handle(statsPath, statsHandler(listen, statsPath))
|
|
}
|
|
l.Fatal(http.ListenAndServe(listen, nil))
|
|
}, nil
|
|
}
|