diff --git a/README.md b/README.md index e202e00..ad0d1f3 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ This repo contains 'nse-remote-vlan' an NSE application for Network Service Mesh * `NSM_METRICS_EXPORT_INTERVAL` - interval between metrics exports (default: "10s") * `NSM_LOG_LEVEL` - Log level (default: "INFO") * `NSM_SERVICES` - list of supported services +* `NSM_PPROF_ENABLED` - is pprof enabled (default: "false") +* `NSM_PPROF_LISTEN_ON` - pprof URL to ListenAndServe (default: "localhost:6060") ## Build diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index 4f11783..88c50ac 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -53,6 +53,8 @@ type Config struct { MetricsExportInterval time.Duration `default:"10s" desc:"interval between metrics exports" split_words:"true"` LogLevel string `default:"INFO" desc:"Log level" split_words:"true"` Services []ServiceConfig `default:"" desc:"list of supported services"` + PprofEnabled bool `default:"false" desc:"is pprof enabled" split_words:"true"` + PprofListenOn string `default:"localhost:6060" desc:"pprof URL to ListenAndServe" split_words:"true"` } // Process prints and processes env to config diff --git a/internal/pkg/imports/imports_linux.go b/internal/pkg/imports/imports_linux.go index b930af6..8f6631f 100644 --- a/internal/pkg/imports/imports_linux.go +++ b/internal/pkg/imports/imports_linux.go @@ -31,6 +31,7 @@ import ( _ "github.com/networkservicemesh/sdk/pkg/tools/log" _ "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" _ "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" + _ "github.com/networkservicemesh/sdk/pkg/tools/pprofutils" _ "github.com/networkservicemesh/sdk/pkg/tools/spiffejwt" _ "github.com/networkservicemesh/sdk/pkg/tools/token" _ "github.com/networkservicemesh/sdk/pkg/tools/tracing" diff --git a/main.go b/main.go index 94d44e1..cb4cca5 100644 --- a/main.go +++ b/main.go @@ -62,6 +62,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/tools/log" "github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" + "github.com/networkservicemesh/sdk/pkg/tools/pprofutils" "github.com/networkservicemesh/sdk/pkg/tools/spiffejwt" "github.com/networkservicemesh/sdk/pkg/tools/token" "github.com/networkservicemesh/sdk/pkg/tools/tracing" @@ -136,6 +137,13 @@ func main() { }() } + // ******************************************************************************** + // Configure pprof + // ******************************************************************************** + if cfg.PprofEnabled { + go pprofutils.ListenAndServe(ctx, cfg.PprofListenOn) + } + // ******************************************************************************** logger.Infof("executing phase 2: retrieving svid, check spire agent logs if this is the last line you see") // ********************************************************************************