diff --git a/pkg/cluster/manager/display.go b/pkg/cluster/manager/display.go index 793307984f..503b9071b7 100644 --- a/pkg/cluster/manager/display.go +++ b/pkg/cluster/manager/display.go @@ -54,16 +54,18 @@ type DisplayOption struct { // InstInfo represents an instance info type InstInfo struct { - ID string `json:"id"` - Role string `json:"role"` - Host string `json:"host"` - Ports string `json:"ports"` - OsArch string `json:"os_arch"` - Status string `json:"status"` - Memory string `json:"memory"` - Since string `json:"since"` - DataDir string `json:"data_dir"` - DeployDir string `json:"deploy_dir"` + ID string `json:"id"` + Role string `json:"role"` + Host string `json:"host"` + Ports string `json:"ports"` + OsArch string `json:"os_arch"` + Status string `json:"status"` + Memory string `json:"memory"` + MemoryLimit string `json:"memory_limit"` + CPUquota string `json:"cpu_quota"` + Since string `json:"since"` + DataDir string `json:"data_dir"` + DeployDir string `json:"deploy_dir"` ComponentName string Port int @@ -172,7 +174,7 @@ func (m *Manager) Display(dopt DisplayOption, opt operator.Options) error { var clusterTable [][]string rowHead := []string{"ID", "Role", "Host", "Ports", "OS/Arch", "Status"} if dopt.ShowProcess { - rowHead = append(rowHead, "Memory") + rowHead = append(rowHead, "Memory", "Memory Limit", "CPU Quota") } if dopt.ShowUptime { rowHead = append(rowHead, "Since") @@ -191,7 +193,7 @@ func (m *Manager) Display(dopt DisplayOption, opt operator.Options) error { formatInstanceStatus(v.Status), } if dopt.ShowProcess { - row = append(row, v.Memory) + row = append(row, v.Memory, v.MemoryLimit, v.CPUquota) } if dopt.ShowUptime { row = append(row, v.Since) @@ -598,6 +600,8 @@ func (m *Manager) GetClusterTopology(dopt DisplayOption, opt operator.Options) ( OsArch: tui.OsArch(ins.OS(), ins.Arch()), Status: status, Memory: memory, + MemoryLimit: ins.ResourceControl().MemoryLimit, + CPUquota: ins.ResourceControl().CPUQuota, DataDir: dataDir, DeployDir: deployDir, ComponentName: ins.ComponentName(), diff --git a/pkg/cluster/operation/systemd.go b/pkg/cluster/operation/systemd.go index 1968454892..7c3cd661af 100644 --- a/pkg/cluster/operation/systemd.go +++ b/pkg/cluster/operation/systemd.go @@ -46,13 +46,13 @@ func GetServiceStatus(ctx context.Context, e ctxt.Executor, name string) (active } lines := strings.Split(string(stdout), "\n") for _, line := range lines { - words := strings.Split(strings.TrimSpace(line), ":") + words := strings.Split(strings.TrimSpace(line), " ") if len(words) >= 2 { switch words[0] { - case "Active": + case "Active:": active = words[1] - case "Memory": - memory = strings.Join(words[1:], "") + case "Memory:": + memory = words[1] } } } diff --git a/pkg/cluster/spec/instance.go b/pkg/cluster/spec/instance.go index 1956e003e3..225d0548f8 100644 --- a/pkg/cluster/spec/instance.go +++ b/pkg/cluster/spec/instance.go @@ -88,6 +88,7 @@ type Instance interface { ComponentName() string InstanceName() string ServiceName() string + ResourceControl() meta.ResourceControl GetHost() string GetPort() int GetSSHPort() int @@ -165,7 +166,7 @@ func (i *BaseInstance) InitConfig(ctx context.Context, e ctxt.Executor, opt Glob return nil } - resource := MergeResourceControl(opt.ResourceControl, i.resourceControl()) + resource := MergeResourceControl(opt.ResourceControl, i.ResourceControl()) systemCfg := system.NewConfig(comp, user, paths.Deploy). WithMemoryLimit(resource.MemoryLimit). WithCPUQuota(resource.CPUQuota). @@ -441,7 +442,7 @@ func MergeResourceControl(lhs, rhs meta.ResourceControl) meta.ResourceControl { return lhs } -func (i *BaseInstance) resourceControl() meta.ResourceControl { +func (i *BaseInstance) ResourceControl() meta.ResourceControl { if v := reflect.Indirect(reflect.ValueOf(i.InstanceSpec)).FieldByName("ResourceControl"); v.IsValid() { return v.Interface().(meta.ResourceControl) }