mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-05 09:30:26 +08:00
增加edge-node top命令,用来调用系统的top命令并传入edge-node进程ID
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/nodes"
|
"github.com/TeaOSLab/EdgeNode/internal/nodes"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||||
|
executils "github.com/TeaOSLab/EdgeNode/internal/utils/exec"
|
||||||
fsutils "github.com/TeaOSLab/EdgeNode/internal/utils/fs"
|
fsutils "github.com/TeaOSLab/EdgeNode/internal/utils/fs"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
@@ -22,8 +23,10 @@ import (
|
|||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,7 +34,7 @@ func main() {
|
|||||||
var app = apps.NewAppCmd().
|
var app = apps.NewAppCmd().
|
||||||
Version(teaconst.Version).
|
Version(teaconst.Version).
|
||||||
Product(teaconst.ProductName).
|
Product(teaconst.ProductName).
|
||||||
Usage(teaconst.ProcessName + " [-v|start|stop|restart|status|quit|test|reload|service|daemon|config|pprof|accesslog|uninstall]").
|
Usage(teaconst.ProcessName + " [-v|start|stop|restart|status|quit|test|reload|service|daemon|config|pprof|top|accesslog|uninstall]").
|
||||||
Usage(teaconst.ProcessName + " [trackers|goman|conns|gc|bandwidth|disk|cache.garbage]").
|
Usage(teaconst.ProcessName + " [trackers|goman|conns|gc|bandwidth|disk|cache.garbage]").
|
||||||
Usage(teaconst.ProcessName + " [ip.drop|ip.reject|ip.remove|ip.close] IP")
|
Usage(teaconst.ProcessName + " [ip.drop|ip.reject|ip.remove|ip.close] IP")
|
||||||
|
|
||||||
@@ -560,6 +563,37 @@ func main() {
|
|||||||
|
|
||||||
fmt.Println("success")
|
fmt.Println("success")
|
||||||
})
|
})
|
||||||
|
app.On("top", func() {
|
||||||
|
var sock = gosock.NewTmpSock(teaconst.ProcessName)
|
||||||
|
reply, err := sock.Send(&gosock.Command{Code: "pid"})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("[ERROR]not started yet")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var pid = maps.NewMap(reply.Params).GetInt("pid")
|
||||||
|
if pid <= 0 {
|
||||||
|
fmt.Println("[ERROR]invalid pid '" + types.String(pid) + "'")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
topExe, _ := executils.LookPath("top")
|
||||||
|
if len(topExe) > 0 {
|
||||||
|
if runtime.GOOS == "linux" {
|
||||||
|
err = syscall.Exec(topExe, []string{topExe, "-p", types.String(pid)}, os.Environ())
|
||||||
|
} else if runtime.GOOS == "darwin" {
|
||||||
|
err = syscall.Exec(topExe, []string{topExe, "-pid", types.String(pid)}, os.Environ())
|
||||||
|
} else {
|
||||||
|
fmt.Println("[ERROR]not supported os '" + runtime.GOOS + "'")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("[ERROR]start failed: " + err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("[ERROR]could not found 'top' command in this system")
|
||||||
|
}
|
||||||
|
})
|
||||||
app.Run(func() {
|
app.Run(func() {
|
||||||
var node = nodes.NewNode()
|
var node = nodes.NewNode()
|
||||||
node.Start()
|
node.Start()
|
||||||
|
|||||||
Reference in New Issue
Block a user