mirror of
https://2025-dev.shylinux.com/x/20250213-machine
synced 2025-04-25 04:28:04 +08:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
9b0046fa51 | |||
862000e2ce | |||
10f5cc7099 | |||
6a3f0d8bb9 | |||
9bcc69bb48 | |||
20f7311c13 | |||
d28e211359 | |||
62cc9bdefa | |||
c8562f0272 | |||
c63ebf3304 |
8
go.mod
8
go.mod
@ -2,12 +2,12 @@ module 2025-dev.shylinux.com/x/20250213-machine
|
||||
|
||||
go 1.13
|
||||
|
||||
require 2025-dev.shylinux.com/x/20250215-cluster v0.0.4
|
||||
require 2025-dev.shylinux.com/x/20250215-cluster v0.0.7
|
||||
|
||||
require (
|
||||
shylinux.com/x/ice v1.5.68
|
||||
shylinux.com/x/icebergs v1.9.70
|
||||
shylinux.com/x/toolkits v1.0.18
|
||||
shylinux.com/x/ice v1.5.73
|
||||
shylinux.com/x/icebergs v1.9.75
|
||||
shylinux.com/x/toolkits v1.0.19
|
||||
)
|
||||
|
||||
require github.com/shirou/gopsutil/v4 v4.25.1
|
||||
|
16
go.sum
16
go.sum
@ -1,5 +1,5 @@
|
||||
2025-dev.shylinux.com/x/20250215-cluster v0.0.4 h1:Fv6MbAQAAK0ILpswo1yotdp1dqvmHb/gsIr6UsEMU9o=
|
||||
2025-dev.shylinux.com/x/20250215-cluster v0.0.4/go.mod h1:Y/WAz+0Tc5mg8wdUJ2REorcVPN0cI7IDkab2m01hzNQ=
|
||||
2025-dev.shylinux.com/x/20250215-cluster v0.0.7 h1:GhQImaF6RbliJ6467gdeB4AVzCNyz5LwmA9AeCphEvo=
|
||||
2025-dev.shylinux.com/x/20250215-cluster v0.0.7/go.mod h1:rhNacwQogLrmiNkmoptqpKY9ieRXAhVHenHwZRcdBB8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@ -49,12 +49,12 @@ shylinux.com/x/go-git/v5 v5.6.7 h1:WD5QSco7m3QooPCgdvQ6/GyGIFPun8C+hex5N41LYlk=
|
||||
shylinux.com/x/go-git/v5 v5.6.7/go.mod h1:Qb0lA+uIrofZg8NQerhYcJHgGWixFqvS6p3aJ/L5Nlk=
|
||||
shylinux.com/x/go-qrcode v0.0.3 h1:RMo+Vidbgq3HatLBj7DDXcTbTLFUwzis5K7TqBkD38U=
|
||||
shylinux.com/x/go-qrcode v0.0.3/go.mod h1:KAbtU+KwiiABMZ/CJ0zh9PI2AX82Uf9rRYcQ4ODm4po=
|
||||
shylinux.com/x/ice v1.5.68 h1:oFUpwJS3ER6pAmdpHAyQrVdc4YozcHPuRn2UJmUtpFo=
|
||||
shylinux.com/x/ice v1.5.68/go.mod h1:LjHSkg3o+kT3k6lSFJVreez6qiI9ghpnr9Ql94k3+Iw=
|
||||
shylinux.com/x/icebergs v1.9.70 h1:NyoMrTX1Dtf0HosB7GNAO8NODZabdcNw1ZZLSfbhUDw=
|
||||
shylinux.com/x/icebergs v1.9.70/go.mod h1:+4bl7yJRMFtlTQRDLd+xh6b0hwXkqWaHLmx63Jeewwk=
|
||||
shylinux.com/x/ice v1.5.73 h1:wp+KeQ14hLOdxxSou/Y0zHi48Jm4nLx1rFOwGz8ix04=
|
||||
shylinux.com/x/ice v1.5.73/go.mod h1:uGI73gYkk+FiJt5qmy/aYhoKRJ4wobcJk3WrPGh8Waw=
|
||||
shylinux.com/x/icebergs v1.9.75 h1:9zAm0ppwUWl0As/vqfQG/QR/vwXa5zmfdIGE/gmvErQ=
|
||||
shylinux.com/x/icebergs v1.9.75/go.mod h1:3Bdp3tjzw+hUKJF+kR8pfsrbjAf72DVZmCaE8/MPFtk=
|
||||
shylinux.com/x/toolkits v0.7.10/go.mod h1:CHDJarGlDkg60kVsvMLYL/a5hAnRLEOShiEsMOuEp0Q=
|
||||
shylinux.com/x/toolkits v1.0.18 h1:jtQZhmvU10Ajegc87tU0cYFUBSviaODo5TsCXpYb2O4=
|
||||
shylinux.com/x/toolkits v1.0.18/go.mod h1:CHDJarGlDkg60kVsvMLYL/a5hAnRLEOShiEsMOuEp0Q=
|
||||
shylinux.com/x/toolkits v1.0.19 h1:Nrx0xYRc5ph1WS66EZ1hJUCe+2FdSWQ4QP6tBlguikQ=
|
||||
shylinux.com/x/toolkits v1.0.19/go.mod h1:CHDJarGlDkg60kVsvMLYL/a5hAnRLEOShiEsMOuEp0Q=
|
||||
shylinux.com/x/websocket v0.0.4 h1:AJpwblePoOpiE6C8NrvgNYpKTotXMLrDDX2chTvx44Q=
|
||||
shylinux.com/x/websocket v0.0.4/go.mod h1:3UGWkjTu3ie5NAZen7J+uLPBrO7DFeKloj6Jxo13Oiw=
|
||||
|
11
src/document/index.shy
Normal file
11
src/document/index.shy
Normal file
@ -0,0 +1,11 @@
|
||||
navmenu `
|
||||
"{{ .Title }}" /
|
||||
_
|
||||
"下 载" download/
|
||||
"文 档" started/
|
||||
"开 发" development/
|
||||
_
|
||||
"应 用" "https://web.shylinux.com/s/20240903-operation/c/web.team.operation.portal"
|
||||
"源 码" "https://git.shylinux.com/dev/machine"
|
||||
"社 区" "https://bbs.shylinux.com"
|
||||
`
|
@ -5,6 +5,7 @@ refer `
|
||||
后台 https://dev.shylinux.com/s/20250213-machine
|
||||
`
|
||||
field web.chat.dev.machine.monitor
|
||||
field web.chat.dev.machine.process
|
||||
|
||||
section "gopsutil"
|
||||
refer `
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"shylinux.com/x/ice"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
@ -20,13 +21,44 @@ import (
|
||||
"github.com/shirou/gopsutil/v4/net"
|
||||
)
|
||||
|
||||
type monitor struct {
|
||||
type Monitor struct {
|
||||
travel.Travel
|
||||
fields string `data:"Total,Free,Available,Used,UsedPercent,ModelName,Mhz,Core,Thread,CorePercent,ThreadPercent,DiskTotal,DiskFree,DiskUsed,DiskUsedPercent,BytesRecv,BytesSent,PacketsRecv,PacketsSent,version,time"`
|
||||
fields string `data:"ModelName,Mhz,Core,Thread,CorePercent,ThreadPercent,Total,Free,Available,Used,UsedPercent,DiskTotal,DiskFree,DiskUsed,DiskUsedPercent,BytesRecv,BytesSent,PacketsRecv,PacketsSent,ip,hostname,version,time"`
|
||||
script string `name:"script dev nodename port" help:"脚本"`
|
||||
list string `name:"list space auto" help:"设备监控"`
|
||||
}
|
||||
|
||||
func (s monitor) List(m *ice.Message, arg ...string) {
|
||||
func (s Monitor) Inputs(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case ice.DEV:
|
||||
m.SpaceListServer().Table(func(value ice.Maps) {
|
||||
m.Push(arg[0], value[mdb.TEXT])
|
||||
})
|
||||
case web.SPACE:
|
||||
m.Cmd("", s.Foreach).Table(func(value ice.Maps) {
|
||||
m.Push(arg[0], value[web.SPACE])
|
||||
})
|
||||
}
|
||||
}
|
||||
func (s Monitor) Foreach(m *ice.Message, arg ...string) {
|
||||
s.Travel.Foreach(m, arg...)
|
||||
stats := map[string]int{}
|
||||
m.Table(func(value ice.Maps) {
|
||||
kit.For([]string{"Thread", "Used", "Available", "DiskUsed", "DiskFree"}, func(key string) { stats[key] += kit.Int(value[key]) })
|
||||
})
|
||||
list := []string{}
|
||||
kit.For(stats, func(key string, value int) { list = append(list, key, kit.FmtSize(value)) })
|
||||
m.StatusTimeCount(list)
|
||||
}
|
||||
func (s Monitor) Script(m *ice.Message, arg ...string) {
|
||||
m.Option(cli.CTX_ARG, kit.JoinCmdArgs(
|
||||
ice.DEV, m.OptionDefault(ice.DEV, m.Option(ice.MSG_USERHOST)),
|
||||
tcp.NODENAME, m.OptionDefault(tcp.NODENAME, "$(hostname)-machine"),
|
||||
tcp.PORT, m.OptionDefault(tcp.PORT, "9031"),
|
||||
))
|
||||
m.Cmdy(code.PUBLISH, nfs.CONTEXTS, nfs.BINARY)
|
||||
}
|
||||
func (s Monitor) List(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
c, _ := cpu.Info()
|
||||
v, _ := mem.VirtualMemory()
|
||||
@ -79,6 +111,10 @@ func (s monitor) List(m *ice.Message, arg ...string) {
|
||||
m.Push(field, kit.FmtSize(n[0].PacketsRecv))
|
||||
case "PacketsSent":
|
||||
m.Push(field, kit.FmtSize(n[0].PacketsSent))
|
||||
case aaa.IP:
|
||||
m.Push(field, m.Cmd(tcp.HOST).Append(aaa.IP))
|
||||
case tcp.HOSTNAME:
|
||||
m.Push(field, ice.Info.NodeName)
|
||||
case nfs.VERSION:
|
||||
m.Push(field, ice.Info.Make.Version)
|
||||
case mdb.TIME:
|
||||
@ -87,22 +123,10 @@ func (s monitor) List(m *ice.Message, arg ...string) {
|
||||
m.Push(field, "")
|
||||
}
|
||||
})
|
||||
m.Action(s.Foreach)
|
||||
m.Option(cli.CTX_ARG, kit.JoinCmdArgs(tcp.NODENAME, m.Option(ice.MSG_USERPOD)))
|
||||
m.Cmdy(code.PUBLISH, nfs.CONTEXTS, ice.APP)
|
||||
m.Action(s.Foreach, s.Script)
|
||||
} else {
|
||||
m.Cmdy(web.SPACE, arg[0], m.PrefixKey())
|
||||
}
|
||||
}
|
||||
func (s monitor) Foreach(m *ice.Message, arg ...string) {
|
||||
s.Travel.Foreach(m, arg...)
|
||||
stats := map[string]int{}
|
||||
m.Table(func(value ice.Maps) {
|
||||
kit.For([]string{"Thread", "Used", "Available", "DiskUsed", "DiskFree"}, func(key string) { stats[key] += kit.Int(value[key]) })
|
||||
})
|
||||
list := []string{}
|
||||
kit.For(stats, func(key string, value int) { list = append(list, key, kit.FmtSize(value)) })
|
||||
m.StatusTimeCount(list)
|
||||
}
|
||||
|
||||
func init() { ice.Cmd("web.chat.dev.machine.monitor", monitor{}) }
|
||||
func init() { ice.Cmd("web.chat.dev.machine.monitor", Monitor{}) }
|
||||
|
103
src/monitor/process.go
Normal file
103
src/monitor/process.go
Normal file
@ -0,0 +1,103 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"shylinux.com/x/ice"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
|
||||
"github.com/shirou/gopsutil/v4/mem"
|
||||
"github.com/shirou/gopsutil/v4/process"
|
||||
)
|
||||
|
||||
type Process struct {
|
||||
Monitor
|
||||
list string `name:"list name auto" help:"进程监控"`
|
||||
kill string `name:"kill signal" help:"结束进程" icon:"bi bi-stop-circle"`
|
||||
}
|
||||
|
||||
func (s Process) Weight(m *ice.Message, arg ...string) {
|
||||
stat := map[string]int{}
|
||||
v, _ := mem.VirtualMemory()
|
||||
s.getList(func(p *process.Process, cmd string) {
|
||||
name, _ := p.Name()
|
||||
mem, _ := p.MemoryInfo()
|
||||
stat[name] += int(mem.RSS)
|
||||
})
|
||||
kit.For(stat, func(key string, value int) {
|
||||
m.Push("name", key).Push("rss", kit.FmtSize(value))
|
||||
})
|
||||
m.DisplayStoryWeight().SortIntR("rss").Action(s.Weight)
|
||||
m.Push("name", "rest").Push("rss", kit.FmtSize(v.Available))
|
||||
}
|
||||
func (s Process) List(m *ice.Message, arg ...string) {
|
||||
stat := map[string]int{}
|
||||
s.getList(func(p *process.Process, cmd string) {
|
||||
if len(arg) > 0 && !strings.Contains(cmd, arg[0]) {
|
||||
return
|
||||
}
|
||||
t, _ := p.CreateTime()
|
||||
ts, _ := p.NumThreads()
|
||||
cpu, _ := p.CPUPercent()
|
||||
mem, _ := p.MemoryInfo()
|
||||
conn, _ := p.Connections()
|
||||
fd, _ := p.NumFDs()
|
||||
user, _ := p.Username()
|
||||
name, _ := p.Name()
|
||||
m.Push("time", strings.TrimSuffix(time.Unix(t/1000, t%1000).Format(ice.MOD_TIME), ".000"))
|
||||
m.Push("pid", p.Pid)
|
||||
m.Push("ts", ts)
|
||||
m.Push("cpu", kit.Format("%.2f", cpu))
|
||||
m.Push("rss", kit.FmtSize(mem.RSS))
|
||||
m.Push("vms", kit.FmtSize(mem.VMS))
|
||||
m.Push("cs", len(conn))
|
||||
m.Push("fs", fd)
|
||||
m.Push("user", user)
|
||||
m.Push("name", name)
|
||||
m.Push("cmd", kit.Select(name, cmd))
|
||||
stat["ts"] += int(ts)
|
||||
stat["cs"] += len(conn)
|
||||
stat["fs"] += int(fd)
|
||||
stat["rss"] += int(mem.RSS)
|
||||
if strings.Contains(cmd, "bin/ice.bin") {
|
||||
stat["ice.bin"] += int(mem.RSS)
|
||||
stat["ice.num"]++
|
||||
if strings.Contains(cmd, "-bash -c") {
|
||||
return
|
||||
}
|
||||
kit.If(strings.Contains(cmd, "bin/ice.bin space"), func() { stat["ice.space"]++ })
|
||||
kit.If(strings.Contains(cmd, "bin/ice.bin serve"), func() { stat["ice.serve"]++ })
|
||||
}
|
||||
})
|
||||
stats := map[string]string{}
|
||||
kit.For(stat, func(key string, value int) {
|
||||
if kit.IsIn(key, "rss", "ice.bin") {
|
||||
stats[key] = kit.FmtSize(value)
|
||||
} else {
|
||||
stats[key] = kit.Format(value)
|
||||
}
|
||||
})
|
||||
m.PushAction(s.Kill).Action(s.Foreach, s.Weight)
|
||||
m.StatusTimeCount(stats).SortIntR("rss")
|
||||
}
|
||||
func (s Process) Kill(m *ice.Message, arg ...string) {
|
||||
if p, e := os.FindProcess(kit.Int(m.Option("pid"))); e == nil {
|
||||
p.Signal(syscall.Signal(kit.Int(kit.Select("9", m.Option("signal")))))
|
||||
}
|
||||
}
|
||||
|
||||
func init() { ice.Cmd("web.chat.dev.machine.process", Process{}) }
|
||||
|
||||
func (s Process) getList(cb func(p *process.Process, cmd string)) {
|
||||
ps, _ := process.Processes()
|
||||
for _, p := range ps {
|
||||
cmd, _ := p.Cmdline()
|
||||
if cmd == "" {
|
||||
continue
|
||||
}
|
||||
cb(p, cmd)
|
||||
}
|
||||
}
|
1
src/template/web.code.publish/binary.sh
Normal file
1
src/template/web.code.publish/binary.sh
Normal file
@ -0,0 +1 @@
|
||||
export ctx_dev={{.Option "domain"}}{{.Option "ctx_env"}}; {{.Option "ctx_cli"}} binary {{.Option "ctx_arg"}}
|
Loading…
x
Reference in New Issue
Block a user