Run pprof server on agent with --profiler flag

This commit is contained in:
Nimrod Gilboa Markevich 2022-05-12 11:53:57 +03:00
parent ece673bd25
commit 413ebc3b9d

View File

@ -14,6 +14,7 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/gin-contrib/pprof"
"github.com/gin-contrib/static" "github.com/gin-contrib/static"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/up9inc/mizu/agent/pkg/dependency" "github.com/up9inc/mizu/agent/pkg/dependency"
@ -46,6 +47,7 @@ var apiServerAddress = flag.String("api-server-address", "", "Address of mizu AP
var namespace = flag.String("namespace", "", "Resolve IPs if they belong to resources in this namespace (default is all)") var namespace = flag.String("namespace", "", "Resolve IPs if they belong to resources in this namespace (default is all)")
var harsReaderMode = flag.Bool("hars-read", false, "Run in hars-read mode") var harsReaderMode = flag.Bool("hars-read", false, "Run in hars-read mode")
var harsDir = flag.String("hars-dir", "", "Directory to read hars from") var harsDir = flag.String("hars-dir", "", "Directory to read hars from")
var profiler = flag.Bool("profiler", false, "Run pprof server")
const ( const (
socketConnectionRetries = 30 socketConnectionRetries = 30
@ -70,7 +72,14 @@ func main() {
} else if *tapperMode { } else if *tapperMode {
runInTapperMode() runInTapperMode()
} else if *apiServerMode { } else if *apiServerMode {
utils.StartServer(runInApiServerMode(*namespace)) app := runInApiServerMode(*namespace)
if *profiler {
pprof.Register(app)
}
utils.StartServer(app)
} else if *harsReaderMode { } else if *harsReaderMode {
runInHarReaderMode() runInHarReaderMode()
} }