From 2014cd2fdf0f0051deaa715942e0df0ba2bcfed6 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Thu, 4 Aug 2022 10:18:23 +0800 Subject: [PATCH] =?UTF-8?q?edge-node=20pprof=E5=91=BD=E4=BB=A4=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0--addr=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/edge-node/main.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/cmd/edge-node/main.go b/cmd/edge-node/main.go index 977ad36..e708cbb 100644 --- a/cmd/edge-node/main.go +++ b/cmd/edge-node/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "flag" "fmt" "github.com/TeaOSLab/EdgeNode/internal/apps" teaconst "github.com/TeaOSLab/EdgeNode/internal/const" @@ -19,7 +20,7 @@ import ( ) func main() { - app := apps.NewAppCmd(). + var app = apps.NewAppCmd(). Version(teaconst.Version). Product(teaconst.ProductName). Usage(teaconst.ProcessName + " [-v|start|stop|restart|status|quit|test|reload|service|daemon|pprof|accesslog]"). @@ -67,24 +68,30 @@ func main() { fmt.Println("done") }) app.On("pprof", func() { - // TODO 自己指定端口 - addr := "127.0.0.1:6060" + var flagSet = flag.NewFlagSet("pprof", flag.ExitOnError) + var addr string + flagSet.StringVar(&addr, "addr", "", "") + _ = flagSet.Parse(os.Args[2:]) + + if len(addr) == 0 { + addr = "127.0.0.1:6060" + } logs.Println("starting with pprof '" + addr + "'...") go func() { err := http.ListenAndServe(addr, nil) if err != nil { - logs.Println("[error]" + err.Error()) + logs.Println("[ERROR]" + err.Error()) } }() - node := nodes.NewNode() + var node = nodes.NewNode() node.Start() }) app.On("dbstat", func() { teaconst.EnableDBStat = true - node := nodes.NewNode() + var node = nodes.NewNode() node.Start() }) app.On("trackers", func() { @@ -306,7 +313,7 @@ func main() { } }) app.Run(func() { - node := nodes.NewNode() + var node = nodes.NewNode() node.Start() }) }