diff --git a/go.mod b/go.mod index 7e22f54..a212c05 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,8 @@ module 2025-dev.shylinux.com/x/20250213-machine go 1.13 require ( + github.com/shirou/gopsutil/v4 v4.25.1 shylinux.com/x/ice v1.5.60 shylinux.com/x/icebergs v1.9.62 + shylinux.com/x/toolkits v1.0.16 ) diff --git a/go.sum b/go.sum index 48cd924..13c353a 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,48 @@ +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= +github.com/ebitengine/purego v0.8.2 h1:jPPGWs2sZ1UgOSgD2bClL0MJIqu58nOmIcBuXr62z1I= +github.com/ebitengine/purego v0.8.2/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= +github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= +github.com/shirou/gopsutil/v4 v4.25.1 h1:QSWkTc+fu9LTAWfkZwZ6j8MSUk4A2LV7rbH0ZqmLjXs= +github.com/shirou/gopsutil/v4 v4.25.1/go.mod h1:RoUCUpndaJFtT+2zsZzzmhvbfGoDCJ7nFXKJf8GqJbI= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= +github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= +github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 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= diff --git a/src/main.go b/src/main.go index 5addb64..832d7ed 100644 --- a/src/main.go +++ b/src/main.go @@ -1,5 +1,6 @@ package main import "shylinux.com/x/ice" +import _ "2025-dev.shylinux.com/x/20250213-machine/src/monitor" func main() { print(ice.Run()) } \ No newline at end of file diff --git a/src/main.shy b/src/main.shy index b1fd7da..25f956d 100644 --- a/src/main.shy +++ b/src/main.shy @@ -1,25 +1,6 @@ -title "ContextOS 研发平台" +title "machine" refer ` -网址 https://dev.shylinux.com -` - -chapter "容器服务" -refer ` -官网 https://cloud.tencent.com/product/tke -文档 https://cloud.tencent.com/document/product/457 -后台 https://console.cloud.tencent.com/tke2/overview -网络 https://console.cloud.tencent.com/vpc/subnet -安全 https://console.cloud.tencent.com/vpc/security-group -密钥 https://console.cloud.tencent.com/cvm/sshkey/index -域名 https://console.cloud.tencent.com/cns -` - -chapter "K8S" -refer ` -官网 https://kubernetes.io/ -文档 https://kubernetes.io/docs/home/ -源码 https://github.com/kubernetes/kubernetes -` -spark shell ` -cd /root; export ctx_cluster=guangzhou-1 ctx_pool=pool-1 ctx_dev=https://2025-dev.shylinux.com ctx_pod=20250211-cluster; temp=$(mktemp); if curl -h &>/dev/null; then curl -o $temp -fsSL $ctx_dev; else wget -O $temp -q $ctx_dev; fi; source $temp app dev dev username shy usernick "IT 老营长" language zh-cn & +源码 https://github.com/shirou/gopsutil +https://zhuanlan.zhihu.com/p/126362239 +https://huangzhongde.cn/post/2020-03-06-golang_introduce_gopsutil/ ` \ No newline at end of file diff --git a/src/monitor/monitor.go b/src/monitor/monitor.go new file mode 100644 index 0000000..c33e1ef --- /dev/null +++ b/src/monitor/monitor.go @@ -0,0 +1,83 @@ +package monitor + +import ( + "time" + + "shylinux.com/x/ice" + "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/web" + kit "shylinux.com/x/toolkits" + + "github.com/shirou/gopsutil/v4/cpu" + "github.com/shirou/gopsutil/v4/disk" + "github.com/shirou/gopsutil/v4/mem" + "github.com/shirou/gopsutil/v4/net" +) + +type monitor struct { + fields string `data:"ModelName,Mhz,Core,Thread,CorePercent,ThreadPercent,Total,Free,Available,Used,UsedPercent,DiskTotal,DiskFree,DiskUsed,DiskUsedPercent,BytesRecv,BytesSent,PacketsRecv,PacketsSent"` + list string `name:"list hash auto" help:"monitor"` +} + +func (s monitor) List(m *ice.Message, arg ...string) { + m.Cmd(web.SPACE, ice.OPS, web.DREAM, web.SERVER).Table(func(value ice.Maps) { + m.PushRecord(value) + }) + return + c, _ := cpu.Info() + v, _ := mem.VirtualMemory() + d, _ := disk.Usage(kit.Pwd()) + n, _ := net.IOCounters(false) + kit.For(kit.Split(m.OptionDefault(mdb.FIELDS, m.Config(mdb.FIELDS))), func(field string) { + switch field { + case "ModelName": + m.Push(field, c[0].ModelName) + case "Mhz": + list := []string{} + for _, v := range c { + list = append(list, kit.Format("%.2f", v.Mhz)) + } + m.Push(field, kit.Join(list, ",")) + case "Core", "Thread": + n, _ := cpu.Counts(field == "Thread") + m.Push(field, n) + case "CorePercent", "ThreadPercent": + p, _ := cpu.Percent(3*time.Second, field == "ThreadPercent") + list := []string{} + for _, v := range p { + list = append(list, kit.Format("%.2f", v)) + } + m.Push(field, kit.Join(list, ",")) + case "Total": + m.Push(field, kit.FmtSize(v.Total)) + case "Free": + m.Push(field, kit.FmtSize(v.Free)) + case "Available": + m.Push(field, kit.FmtSize(v.Available)) + case "Used": + m.Push(field, kit.FmtSize(v.Used)) + case "UsedPercent": + m.Push(field, kit.Format("%.2f%%", v.UsedPercent)) + case "DiskTotal": + m.Push(field, kit.FmtSize(d.Total)) + case "DiskFree": + m.Push(field, kit.FmtSize(d.Free)) + case "DiskUsed": + m.Push(field, kit.FmtSize(d.Used)) + case "DiskUsedPercent": + m.Push(field, kit.Format("%.2f%%", d.UsedPercent)) + case "BytesRecv": + m.Push(field, kit.FmtSize(n[0].BytesRecv)) + case "BytesSent": + m.Push(field, kit.FmtSize(n[0].BytesSent)) + case "PacketsRecv": + m.Push(field, kit.FmtSize(n[0].PacketsRecv)) + case "PacketsSent": + m.Push(field, kit.FmtSize(n[0].PacketsSent)) + default: + m.Push(field, "") + } + }) +} + +func init() { ice.Cmd("web.chat.dev.machine.monitor", monitor{}) }