Skip to content

Commit

Permalink
feat: add disk space to hosts tab in phēnix UI
Browse files Browse the repository at this point in the history
  • Loading branch information
glattercj authored and activeshadow committed May 10, 2024
1 parent 527477b commit 7335a03
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 16 deletions.
57 changes: 56 additions & 1 deletion src/go/util/mm/minimega.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ func (this Minimega) GetVMCaptures(opts ...Option) []Capture {
return keep
}

func (Minimega) GetClusterHosts(schedOnly bool) (Hosts, error) {
func (this Minimega) GetClusterHosts(schedOnly bool) (Hosts, error) {
// Get headnode details
hosts, err := processNamespaceHosts("minimega")
if err != nil {
Expand Down Expand Up @@ -729,13 +729,21 @@ func (Minimega) GetClusterHosts(schedOnly bool) (Hosts, error) {
// This will happen if the headnode is included as a compute node
// (ie. when there's only one node in the cluster).
if host.Name == head.Name {
// Add disk info
head.DiskUsage.Phenix = this.getDiskUsage(head.Name, common.PhenixBase)
head.DiskUsage.Minimega = this.getDiskUsage(head.Name, common.MinimegaBase)

head.Schedulable = true
continue
}

host.Name = common.TrimHostnameSuffixes(host.Name)
host.Schedulable = true

// Add disk info
host.DiskUsage.Phenix = this.getDiskUsage(host.Name, common.PhenixBase)
host.DiskUsage.Minimega = this.getDiskUsage(host.Name, common.MinimegaBase)

cluster = append(cluster, host)
}

Expand All @@ -745,6 +753,10 @@ func (Minimega) GetClusterHosts(schedOnly bool) (Hosts, error) {

head.Name = common.TrimHostnameSuffixes(head.Name)

// Add disk info
head.DiskUsage.Phenix = this.getDiskUsage(head.Name, common.PhenixBase)
head.DiskUsage.Minimega = this.getDiskUsage(head.Name, common.MinimegaBase)

cluster = append(cluster, head)

return cluster, nil
Expand Down Expand Up @@ -1147,6 +1159,33 @@ func (Minimega) MeshShell(host, command string) error {
return nil
}

func (Minimega) MeshShellResponse(host, command string) (string, error) {
cmd := mmcli.NewCommand()

if host == "" {
host = Headnode()
}

if IsHeadnode(host) {
cmd.Command = fmt.Sprintf("shell %s", command)
} else {
cmd.Command = fmt.Sprintf("mesh send %s shell %s", host, command)
}

for resps := range mmcli.Run(cmd) {
for _, resp := range resps.Resp {
if resp.Error != "" {
plog.Warn("error running shell command: ", "cmd", cmd)
continue
}

return strings.TrimSpace(resp.Response), nil
}
}

return "", fmt.Errorf("error running MeshShellResponse()")
}

func (Minimega) MeshSend(ns, host, command string) error {
var cmd *mmcli.Command

Expand Down Expand Up @@ -1320,3 +1359,19 @@ func processNamespaceHosts(namespace string) (Hosts, error) {

return hosts, nil
}

// Run shell command to get disk usage for `path` on `host`
func (this Minimega) getDiskUsage(host string, path string) float64 {
diskUsage := 0.0

cmd := fmt.Sprintf(`bash -c "echo $(df %s | awk '{print $(NF-1)}' | tail -1)"`, path)
resp, err := this.MeshShellResponse(host, cmd)

if (resp == "") || (err != nil) {
return diskUsage
}

diskUsage, _ = strconv.ParseFloat(strings.TrimSuffix(resp, "%"), 64)

return diskUsage
}
36 changes: 21 additions & 15 deletions src/go/util/mm/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,27 @@ type Cluster struct {
}

type Host struct {
Name string `json:"name"`
CPUs int `json:"cpus"`
CPUCommit int `json:"cpucommit"`
Load []string `json:"load"`
MemUsed int `json:"memused"`
MemTotal int `json:"memtotal"`
MemCommit int `json:"memcommit"`
Tx float64 `json:"tx"`
Rx float64 `json:"rx"`
Bandwidth string `json:"bandwidth"`
NetCommit int `json:"netcommit"`
VMs int `json:"vms"`
Uptime float64 `json:"uptime"`
Schedulable bool `json:"schedulable"`
Headnode bool `json:"headnode"`
Name string `json:"name"`
CPUs int `json:"cpus"`
CPUCommit int `json:"cpucommit"`
Load []string `json:"load"`
MemUsed int `json:"memused"`
MemTotal int `json:"memtotal"`
MemCommit int `json:"memcommit"`
Tx float64 `json:"tx"`
Rx float64 `json:"rx"`
Bandwidth string `json:"bandwidth"`
DiskUsage DiskUsage `json:"diskusage"`
NetCommit int `json:"netcommit"`
VMs int `json:"vms"`
Uptime float64 `json:"uptime"`
Schedulable bool `json:"schedulable"`
Headnode bool `json:"headnode"`
}

type DiskUsage struct {
Phenix float64 `json:"diskphenix"`
Minimega float64 `json:"diskminimega"`
}

type VMs []VM
Expand Down
9 changes: 9 additions & 0 deletions src/js/src/components/Hosts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ available for experiments, the number of VMs, and host uptime.
<b-table-column field="mem_total" label="RAM Total" width="100" centered v-slot="props">
{{ props.row.memtotal | ram }}
</b-table-column>
<b-table-column field="disk_used" label="Disk Used (% phenix/minimega base)" width="200" centered v-slot="props">
<span class="tag" :class="decorator(props.row.diskusage.diskphenix, 100.0)">
{{ props.row.diskusage.diskphenix }}
</span>
/
<span class="tag" :class="decorator(props.row.diskusage.diskminimega, 100.0)">
{{ props.row.diskusage.diskminimega }}
</span>
</b-table-column>
<b-table-column field="bandwidth" label="Bandwidth (MB/sec)" width="200" centered v-slot="props">
{{ props.row.bandwidth }}
</b-table-column>
Expand Down

0 comments on commit 7335a03

Please sign in to comment.