mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-04-30 16:15:26 +08:00
fix: shell脚本文件用字符串替换
This commit is contained in:
@@ -1,54 +1,19 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"mayfly-go/base/biz"
|
||||
)
|
||||
|
||||
const BasePath = "./devops/infrastructure/machine/shell/"
|
||||
|
||||
// const MonitorTemp = "cpuRate:{cpuRate}%,memRate:{memRate}%,sysLoad:{sysLoad}\n"
|
||||
|
||||
// shell文件内容缓存,避免每次读取文件
|
||||
var shellCache = make(map[string]string)
|
||||
|
||||
// func (c *Cli) GetProcessByName(name string) (*string, error) {
|
||||
// return c.Run(getShellContent("sys_info"))
|
||||
// }
|
||||
|
||||
// func (c *Cli) GetSystemInfo() (*string, error) {
|
||||
// return c.Run(getShellContent("system_info"))
|
||||
// }
|
||||
|
||||
// func (c *Cli) GetMonitorInfo() *entity.MachineMonitor {
|
||||
// mm := new(entity.MachineMonitor)
|
||||
// res, _ := c.Run(getShellContent("monitor"))
|
||||
// if res == nil {
|
||||
// return nil
|
||||
// }
|
||||
// resMap := make(map[string]interface{})
|
||||
// utils.ReverStrTemplate(MonitorTemp, *res, resMap)
|
||||
|
||||
// err := utils.Map2Struct(resMap, mm)
|
||||
// if err != nil {
|
||||
// global.Log.Error("解析machine monitor: %s", err.Error())
|
||||
// return nil
|
||||
// }
|
||||
// mm.MachineId = c.machine.Id
|
||||
// mm.CreateTime = time.Now()
|
||||
// return mm
|
||||
// }
|
||||
|
||||
// 获取shell内容
|
||||
func getShellContent(name string) string {
|
||||
cacheShell := shellCache[name]
|
||||
if cacheShell != "" {
|
||||
return cacheShell
|
||||
}
|
||||
|
||||
bytes, err := ioutil.ReadFile(BasePath + name + ".sh")
|
||||
biz.ErrIsNil(err, "获取shell文件失败")
|
||||
shellStr := string(bytes)
|
||||
shellCache[name] = shellStr
|
||||
return shellStr
|
||||
}
|
||||
const StatsShell = `
|
||||
cat /proc/uptime
|
||||
echo '-----'
|
||||
/bin/hostname -f
|
||||
echo '-----'
|
||||
cat /proc/loadavg
|
||||
echo '-----'
|
||||
cat /proc/meminfo
|
||||
echo '-----'
|
||||
df -B1
|
||||
echo '-----'
|
||||
/sbin/ip -o addr
|
||||
echo '-----'
|
||||
/bin/cat /proc/net/dev
|
||||
echo '-----'
|
||||
top -b -n 1 | grep Cpu
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user