mirror of
https://2025-dev.shylinux.com/x/20250213-machine
synced 2025-04-25 04:28:04 +08:00
opt some
This commit is contained in:
parent
d28e211359
commit
20f7311c13
8
go.mod
8
go.mod
@ -2,12 +2,12 @@ module 2025-dev.shylinux.com/x/20250213-machine
|
|||||||
|
|
||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require 2025-dev.shylinux.com/x/20250215-cluster v0.0.4
|
require 2025-dev.shylinux.com/x/20250215-cluster v0.0.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
shylinux.com/x/ice v1.5.68
|
shylinux.com/x/ice v1.5.71
|
||||||
shylinux.com/x/icebergs v1.9.70
|
shylinux.com/x/icebergs v1.9.72
|
||||||
shylinux.com/x/toolkits v1.0.18
|
shylinux.com/x/toolkits v1.0.19
|
||||||
)
|
)
|
||||||
|
|
||||||
require github.com/shirou/gopsutil/v4 v4.25.1
|
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.5 h1:vZDKGh+RFMRDWNuPkRvIsO2iTvEa5lM5IDq0Tp+Nt4k=
|
||||||
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.5/go.mod h1:a/cnjm6D6vkzZ2rvK8uvU3lSsWUs/NWOWl1uBb+LXLM=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
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-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 h1:RMo+Vidbgq3HatLBj7DDXcTbTLFUwzis5K7TqBkD38U=
|
||||||
shylinux.com/x/go-qrcode v0.0.3/go.mod h1:KAbtU+KwiiABMZ/CJ0zh9PI2AX82Uf9rRYcQ4ODm4po=
|
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.71 h1:5yrs+9uj3xNjsQuuLed/3lfF10syjbHhUT8LJAJqClo=
|
||||||
shylinux.com/x/ice v1.5.68/go.mod h1:LjHSkg3o+kT3k6lSFJVreez6qiI9ghpnr9Ql94k3+Iw=
|
shylinux.com/x/ice v1.5.71/go.mod h1:2KKKi+Jridkkg+NWUrSX9S7Pe5zuwihBaVJ0nNY/FmY=
|
||||||
shylinux.com/x/icebergs v1.9.70 h1:NyoMrTX1Dtf0HosB7GNAO8NODZabdcNw1ZZLSfbhUDw=
|
shylinux.com/x/icebergs v1.9.72 h1:y3oVuMZtsI6hX0HLdfgzeDZNSbyoLrVSWl81JQcV+fA=
|
||||||
shylinux.com/x/icebergs v1.9.70/go.mod h1:+4bl7yJRMFtlTQRDLd+xh6b0hwXkqWaHLmx63Jeewwk=
|
shylinux.com/x/icebergs v1.9.72/go.mod h1:3Bdp3tjzw+hUKJF+kR8pfsrbjAf72DVZmCaE8/MPFtk=
|
||||||
shylinux.com/x/toolkits v0.7.10/go.mod h1:CHDJarGlDkg60kVsvMLYL/a5hAnRLEOShiEsMOuEp0Q=
|
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.19 h1:Nrx0xYRc5ph1WS66EZ1hJUCe+2FdSWQ4QP6tBlguikQ=
|
||||||
shylinux.com/x/toolkits v1.0.18/go.mod h1:CHDJarGlDkg60kVsvMLYL/a5hAnRLEOShiEsMOuEp0Q=
|
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 h1:AJpwblePoOpiE6C8NrvgNYpKTotXMLrDDX2chTvx44Q=
|
||||||
shylinux.com/x/websocket v0.0.4/go.mod h1:3UGWkjTu3ie5NAZen7J+uLPBrO7DFeKloj6Jxo13Oiw=
|
shylinux.com/x/websocket v0.0.4/go.mod h1:3UGWkjTu3ie5NAZen7J+uLPBrO7DFeKloj6Jxo13Oiw=
|
||||||
|
@ -5,6 +5,7 @@ refer `
|
|||||||
后台 https://dev.shylinux.com/s/20250213-machine
|
后台 https://dev.shylinux.com/s/20250213-machine
|
||||||
`
|
`
|
||||||
field web.chat.dev.machine.monitor
|
field web.chat.dev.machine.monitor
|
||||||
|
field web.chat.dev.machine.process
|
||||||
|
|
||||||
section "gopsutil"
|
section "gopsutil"
|
||||||
refer `
|
refer `
|
||||||
|
@ -20,13 +20,44 @@ import (
|
|||||||
"github.com/shirou/gopsutil/v4/net"
|
"github.com/shirou/gopsutil/v4/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
type monitor struct {
|
type Monitor struct {
|
||||||
travel.Travel
|
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,version,time"`
|
||||||
|
script string `name:"script dev nodename port" help:"脚本"`
|
||||||
list string `name:"list space auto" 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 {
|
if len(arg) == 0 {
|
||||||
c, _ := cpu.Info()
|
c, _ := cpu.Info()
|
||||||
v, _ := mem.VirtualMemory()
|
v, _ := mem.VirtualMemory()
|
||||||
@ -87,22 +118,11 @@ func (s monitor) List(m *ice.Message, arg ...string) {
|
|||||||
m.Push(field, "")
|
m.Push(field, "")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
m.Action(s.Foreach)
|
m.Action(s.Foreach, s.Script)
|
||||||
m.Option(cli.CTX_ARG, kit.JoinCmdArgs(tcp.NODENAME, m.Option(ice.MSG_USERPOD)))
|
m.Cmdy("", s.Script)
|
||||||
m.Cmdy(code.PUBLISH, nfs.CONTEXTS, ice.APP)
|
|
||||||
} else {
|
} else {
|
||||||
m.Cmdy(web.SPACE, arg[0], m.PrefixKey())
|
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{}) }
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package monitor
|
package monitor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"shylinux.com/x/ice"
|
"shylinux.com/x/ice"
|
||||||
@ -12,7 +14,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Process struct {
|
type Process struct {
|
||||||
list string `name:"list name auto" help:"进程"`
|
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) {
|
func (s Process) Weight(m *ice.Message, arg ...string) {
|
||||||
@ -26,7 +30,7 @@ func (s Process) Weight(m *ice.Message, arg ...string) {
|
|||||||
kit.For(stat, func(key string, value int) {
|
kit.For(stat, func(key string, value int) {
|
||||||
m.Push("name", key).Push("rss", kit.FmtSize(value))
|
m.Push("name", key).Push("rss", kit.FmtSize(value))
|
||||||
})
|
})
|
||||||
m.DisplayStoryPie().SortIntR("rss").Action(s.Weight)
|
m.DisplayStoryWeight().SortIntR("rss").Action(s.Weight)
|
||||||
m.Push("name", "rest").Push("rss", kit.FmtSize(v.Available))
|
m.Push("name", "rest").Push("rss", kit.FmtSize(v.Available))
|
||||||
}
|
}
|
||||||
func (s Process) List(m *ice.Message, arg ...string) {
|
func (s Process) List(m *ice.Message, arg ...string) {
|
||||||
@ -41,7 +45,6 @@ func (s Process) List(m *ice.Message, arg ...string) {
|
|||||||
mem, _ := p.MemoryInfo()
|
mem, _ := p.MemoryInfo()
|
||||||
conn, _ := p.Connections()
|
conn, _ := p.Connections()
|
||||||
fd, _ := p.NumFDs()
|
fd, _ := p.NumFDs()
|
||||||
rw, _ := p.IOCounters()
|
|
||||||
user, _ := p.Username()
|
user, _ := p.Username()
|
||||||
name, _ := p.Name()
|
name, _ := p.Name()
|
||||||
m.Push("time", strings.TrimSuffix(time.Unix(t/1000, t%1000).Format(ice.MOD_TIME), ".000"))
|
m.Push("time", strings.TrimSuffix(time.Unix(t/1000, t%1000).Format(ice.MOD_TIME), ".000"))
|
||||||
@ -52,10 +55,6 @@ func (s Process) List(m *ice.Message, arg ...string) {
|
|||||||
m.Push("vms", kit.FmtSize(mem.VMS))
|
m.Push("vms", kit.FmtSize(mem.VMS))
|
||||||
m.Push("cs", len(conn))
|
m.Push("cs", len(conn))
|
||||||
m.Push("fs", fd)
|
m.Push("fs", fd)
|
||||||
if rw != nil {
|
|
||||||
m.Push("reads", kit.FmtSize(rw.ReadBytes))
|
|
||||||
m.Push("writes", kit.FmtSize(rw.WriteBytes))
|
|
||||||
}
|
|
||||||
m.Push("user", user)
|
m.Push("user", user)
|
||||||
m.Push("name", name)
|
m.Push("name", name)
|
||||||
m.Push("cmd", kit.Select(name, cmd))
|
m.Push("cmd", kit.Select(name, cmd))
|
||||||
@ -81,7 +80,13 @@ func (s Process) List(m *ice.Message, arg ...string) {
|
|||||||
stats[key] = kit.Format(value)
|
stats[key] = kit.Format(value)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
m.StatusTimeCount(stats).SortIntR("rss").Action(s.Weight)
|
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 init() { ice.Cmd("web.chat.dev.machine.process", Process{}) }
|
||||||
|
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