fix: 表结构更新,修复前端新增数据库端口号为string问题

This commit is contained in:
meilin.huang
2021-11-18 14:40:12 +08:00
parent 8fcdde3711
commit e8d04413f6
11 changed files with 665 additions and 465 deletions

View File

@@ -3,45 +3,41 @@ package machine
import (
"io/ioutil"
"mayfly-go/base/biz"
"mayfly-go/base/global"
"mayfly-go/base/utils"
"mayfly-go/server/devops/domain/entity"
"time"
)
const BasePath = "./machine/shell/"
const BasePath = "./devops/infrastructure/machine/shell/"
const MonitorTemp = "cpuRate:{cpuRate}%,memRate:{memRate}%,sysLoad:{sysLoad}\n"
// 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) 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) 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)
// 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
}
// 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 {
@@ -49,6 +45,7 @@ func getShellContent(name string) string {
if cacheShell != "" {
return cacheShell
}
bytes, err := ioutil.ReadFile(BasePath + name + ".sh")
biz.ErrIsNil(err, "获取shell文件失败")
shellStr := string(bytes)