Skip to content

Commit

Permalink
show quota
Browse files Browse the repository at this point in the history
  • Loading branch information
nexustar committed Aug 9, 2022
1 parent b6e842c commit 069e3ec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
28 changes: 16 additions & 12 deletions pkg/cluster/manager/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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(),
Expand Down
8 changes: 4 additions & 4 deletions pkg/cluster/operation/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/cluster/spec/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type Instance interface {
ComponentName() string
InstanceName() string
ServiceName() string
ResourceControl() meta.ResourceControl
GetHost() string
GetPort() int
GetSSHPort() int
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 069e3ec

Please sign in to comment.