1
0
mirror of https://shylinux.com/x/icebergs synced 2025-06-27 02:37:31 +08:00
This commit is contained in:
IT 老营长 @云轩领航-创始人 2022-09-12 08:31:09 +08:00
parent fcdc05ca0c
commit ef8367a7af
4 changed files with 56 additions and 6 deletions

View File

@ -183,7 +183,7 @@ const RUNTIME = "runtime"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
RUNTIME: {Name: "runtime info=ifconfig,hostinfo,hostname,userinfo,procinfo,diskinfo,bootinfo,api,cli,cmd,env auto", Help: "运行环境", Actions: ice.Actions{ RUNTIME: {Name: "runtime info=ifconfig,hostinfo,hostname,userinfo,procinfo,diskinfo,meminfo,bootinfo,api,cli,cmd,env auto", Help: "运行环境", Actions: ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
cs := m.Target().Configs cs := m.Target().Configs
if _, ok := cs[RUNTIME]; !ok { if _, ok := cs[RUNTIME]; !ok {
@ -207,8 +207,9 @@ func init() {
m.Split(m.Cmdx(SYSTEM, "who"), "user term time") m.Split(m.Cmdx(SYSTEM, "who"), "user term time")
}}, }},
PROCINFO: {Name: "procinfo", Help: "进程信息", Hand: func(m *ice.Message, arg ...string) { PROCINFO: {Name: "procinfo", Help: "进程信息", Hand: func(m *ice.Message, arg ...string) {
m.Split(m.Cmdx(SYSTEM, "ps", "u")).PushAction(PROCKILL) msg := m.Cmd("", HOSTINFO)
m.StatusTimeCount() m.Split(m.Cmdx(SYSTEM, "ps", "u")).PushAction(PROCKILL).SortIntR("RSS")
m.StatusTimeCount("nCPU", msg.Append("nCPU"), "MemTotal", msg.Append("MemTotal"), "MemFree", msg.Append("MemFree"))
}}, }},
PROCKILL: {Name: "prockill", Help: "结束进程", Hand: func(m *ice.Message, arg ...string) { PROCKILL: {Name: "prockill", Help: "结束进程", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(gdb.SIGNAL, gdb.STOP, m.Option("PID")) m.Cmdy(gdb.SIGNAL, gdb.STOP, m.Option("PID"))
@ -249,6 +250,16 @@ func init() {
} }
m.StatusTimeCount() m.StatusTimeCount()
}}, }},
"stats": {Name: "stats", Help: "环境变量", Hand: func(m *ice.Message, arg ...string) {
var ms runtime.MemStats
runtime.ReadMemStats(&ms)
m.Echo("what %#v", ms)
m.Echo("what %#v", kit.FmtSize(int64(ms.Alloc)))
m.Echo("what %#v", kit.FmtSize(int64(ms.TotalAlloc)))
m.Echo("what %#v", kit.FmtSize(int64(ms.Sys)))
m.Echo("what %#v", kit.FmtSize(int64(ms.HeapAlloc)))
m.Echo("what %#v", kit.FmtSize(int64(ms.HeapSys)))
}},
MAKE_DOMAIN: {Name: "make.domain", Help: "编译主机", Hand: func(m *ice.Message, arg ...string) { MAKE_DOMAIN: {Name: "make.domain", Help: "编译主机", Hand: func(m *ice.Message, arg ...string) {
if os.Getenv(CTX_DEV) == "" || os.Getenv(CTX_POD) == "" { if os.Getenv(CTX_DEV) == "" || os.Getenv(CTX_POD) == "" {
m.Echo(m.Conf(RUNTIME, MAKE_DOMAIN)) m.Echo(m.Conf(RUNTIME, MAKE_DOMAIN))

View File

@ -91,7 +91,7 @@ func _system_exec(m *ice.Message, cmd *exec.Cmd) {
defer func() { defer func() {
m.Push(CMD_OUT, out.String()) m.Push(CMD_OUT, out.String())
m.Push(CMD_ERR, err.String()) m.Push(CMD_ERR, err.String())
if m.Echo(strings.TrimSpace(kit.Select(out.String(), err.String()))); IsSuccess(m) && out.String() == "" { if m.Echo(kit.Select(out.String(), err.String())); IsSuccess(m) && out.String() == "" {
m.SetAppend() m.SetAppend()
} }
}() }()

View File

@ -3,6 +3,7 @@ package web
import ( import (
"math/rand" "math/rand"
"net" "net"
"strconv"
"strings" "strings"
"time" "time"
@ -321,6 +322,32 @@ func init() {
DOMAIN: {Name: "domain", Help: "域名", Hand: func(m *ice.Message, arg ...string) { DOMAIN: {Name: "domain", Help: "域名", Hand: func(m *ice.Message, arg ...string) {
m.Echo(_space_domain(m)) m.Echo(_space_domain(m))
}}, }},
"hostinfo": {Name: "hostinfo", Help: "域名", Hand: func(m *ice.Message, arg ...string) {
ncpu := 0
nmem := 0.0
m.Cmd("").Tables(func(value ice.Maps) {
if value[mdb.TYPE] == SERVER {
msg := m.Cmd("", value[mdb.NAME], cli.RUNTIME, cli.HOSTINFO)
if msg.Append("nCPU") != "" {
ncpu += kit.Int(msg.Append("nCPU"))
m.Push("nCPU", msg.Append("nCPU"))
m.Push("MemTotal", msg.Append("MemTotal"))
m.Push("name", value[mdb.NAME])
base, raw := 1.0, ""
if strings.HasSuffix(msg.Append("MemTotal"), "M") {
raw = strings.TrimSuffix(msg.Append("MemTotal"), "M")
} else if strings.HasSuffix(msg.Append("MemTotal"), "G") {
base, raw = 1000, strings.TrimSuffix(msg.Append("MemTotal"), "G")
}
n, e := strconv.ParseFloat(raw, 32)
m.Debug("what %v", e)
nmem += n * base
}
}
})
m.StatusTimeCount("nCPU", ncpu, "nmem", kit.Format("%.2fG", nmem/1000.0))
m.Debug("what %v", m.FormatMeta())
}},
}, mdb.HashCloseAction()), Hand: func(m *ice.Message, arg ...string) { }, mdb.HashCloseAction()), Hand: func(m *ice.Message, arg ...string) {
if len(arg) < 2 { // 节点列表 if len(arg) < 2 { // 节点列表
if mdb.HashSelect(m, arg...); len(arg) == 0 { if mdb.HashSelect(m, arg...); len(arg) == 0 {

16
misc.go
View File

@ -23,8 +23,16 @@ func (m *Message) Split(str string, arg ...string) *Message { // field sp nl
} }
if i == 0 && (field == "" || field == INDEX) { // 表头行 if i == 0 && (field == "" || field == INDEX) { // 表头行
if fields = kit.Split(l, sp, sp); field == INDEX { if fields = kit.Split(l, sp, sp); field == INDEX {
for _, v := range fields { if strings.HasPrefix(l, SP) || strings.HasPrefix(l, TB) {
indexs = append(indexs, strings.Index(l, v)) indexs = append(indexs, 0)
for _, v := range fields {
indexs = append(indexs, strings.Index(l, v)+len(v))
}
indexs = indexs[0 : len(indexs)-1]
} else {
for _, v := range fields {
indexs = append(indexs, strings.Index(l, v))
}
} }
} }
continue continue
@ -32,6 +40,10 @@ func (m *Message) Split(str string, arg ...string) *Message { // field sp nl
if len(indexs) > 0 { // 按位切分 if len(indexs) > 0 { // 按位切分
for i, v := range indexs { for i, v := range indexs {
if v >= len(l) {
m.Push(strings.TrimSpace(kit.Select(SP, fields, i)), "")
continue
}
if i == len(indexs)-1 { if i == len(indexs)-1 {
m.Push(strings.TrimSpace(kit.Select(SP, fields, i)), strings.TrimSpace(l[v:])) m.Push(strings.TrimSpace(kit.Select(SP, fields, i)), strings.TrimSpace(l[v:]))
} else { } else {