mirror of
https://shylinux.com/x/icebergs
synced 2025-06-26 18:37:29 +08:00
opt some
This commit is contained in:
parent
fcdc05ca0c
commit
ef8367a7af
@ -183,7 +183,7 @@ const RUNTIME = "runtime"
|
||||
|
||||
func init() {
|
||||
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) {
|
||||
cs := m.Target().Configs
|
||||
if _, ok := cs[RUNTIME]; !ok {
|
||||
@ -207,8 +207,9 @@ func init() {
|
||||
m.Split(m.Cmdx(SYSTEM, "who"), "user term time")
|
||||
}},
|
||||
PROCINFO: {Name: "procinfo", Help: "进程信息", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Split(m.Cmdx(SYSTEM, "ps", "u")).PushAction(PROCKILL)
|
||||
m.StatusTimeCount()
|
||||
msg := m.Cmd("", HOSTINFO)
|
||||
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) {
|
||||
m.Cmdy(gdb.SIGNAL, gdb.STOP, m.Option("PID"))
|
||||
@ -249,6 +250,16 @@ func init() {
|
||||
}
|
||||
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) {
|
||||
if os.Getenv(CTX_DEV) == "" || os.Getenv(CTX_POD) == "" {
|
||||
m.Echo(m.Conf(RUNTIME, MAKE_DOMAIN))
|
||||
|
@ -91,7 +91,7 @@ func _system_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
defer func() {
|
||||
m.Push(CMD_OUT, out.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()
|
||||
}
|
||||
}()
|
||||
|
@ -3,6 +3,7 @@ package web
|
||||
import (
|
||||
"math/rand"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -321,6 +322,32 @@ func init() {
|
||||
DOMAIN: {Name: "domain", Help: "域名", Hand: func(m *ice.Message, arg ...string) {
|
||||
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) {
|
||||
if len(arg) < 2 { // 节点列表
|
||||
if mdb.HashSelect(m, arg...); len(arg) == 0 {
|
||||
|
16
misc.go
16
misc.go
@ -23,8 +23,16 @@ func (m *Message) Split(str string, arg ...string) *Message { // field sp nl
|
||||
}
|
||||
if i == 0 && (field == "" || field == INDEX) { // 表头行
|
||||
if fields = kit.Split(l, sp, sp); field == INDEX {
|
||||
for _, v := range fields {
|
||||
indexs = append(indexs, strings.Index(l, v))
|
||||
if strings.HasPrefix(l, SP) || strings.HasPrefix(l, TB) {
|
||||
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
|
||||
@ -32,6 +40,10 @@ func (m *Message) Split(str string, arg ...string) *Message { // field sp nl
|
||||
|
||||
if len(indexs) > 0 { // 按位切分
|
||||
for i, v := range indexs {
|
||||
if v >= len(l) {
|
||||
m.Push(strings.TrimSpace(kit.Select(SP, fields, i)), "")
|
||||
continue
|
||||
}
|
||||
if i == len(indexs)-1 {
|
||||
m.Push(strings.TrimSpace(kit.Select(SP, fields, i)), strings.TrimSpace(l[v:]))
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user