Skip to content

Commit

Permalink
node uptime in UI (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
LexLuthr authored Oct 4, 2024
1 parent 2bd5865 commit aa07266
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions web/api/webrpc/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type MachineSummary struct {
RamHumanized string
Gpu int
Layers string
Uptime string
}

func (a *WebRPC) ClusterMachines(ctx context.Context) ([]MachineSummary, error) {
Expand All @@ -34,7 +35,8 @@ func (a *WebRPC) ClusterMachines(ctx context.Context) ([]MachineSummary, error)
hm.gpu,
hmd.machine_name,
hmd.tasks,
hmd.layers
hmd.layers,
hmd.startup_time
FROM
harmony_machines hm
LEFT JOIN
Expand All @@ -51,12 +53,14 @@ func (a *WebRPC) ClusterMachines(ctx context.Context) ([]MachineSummary, error)
var m MachineSummary
var lastContact time.Duration
var ram int64
var uptime time.Time

if err := rows.Scan(&m.ID, &m.Address, &lastContact, &m.Cpu, &ram, &m.Gpu, &m.Name, &m.Tasks, &m.Layers); err != nil {
if err := rows.Scan(&m.ID, &m.Address, &lastContact, &m.Cpu, &ram, &m.Gpu, &m.Name, &m.Tasks, &m.Layers, &uptime); err != nil {
return nil, err // Handle error
}
m.SinceContact = lastContact.Round(time.Second).String()
m.RamHumanized = humanize.Bytes(uint64(ram))
m.Uptime = humanize.Time(uptime)
m.Tasks = strings.TrimSuffix(strings.TrimPrefix(m.Tasks, ","), ",")
m.Layers = strings.TrimSuffix(strings.TrimPrefix(m.Layers, ","), ",")

Expand Down
2 changes: 2 additions & 0 deletions web/static/cluster-machines.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ customElements.define('cluster-machines', class ClusterMachines extends LitEleme
<th>RAM</th>
<th>GPUs</th>
<th>Last Contact</th>
<th>Uptime</th>
<th>Tasks Supported</th>
<th>Layers Enabled</th>
</tr>
Expand All @@ -46,6 +47,7 @@ customElements.define('cluster-machines', class ClusterMachines extends LitEleme
<td>${item.RamHumanized}</td>
<td>${item.Gpu}</td>
<td>${item.SinceContact}</td>
<td>${item.Uptime}</td>
<td>${item.Tasks.split(',').map((item) => html`<a href="/task/?name=${item}">${item}</a> `)}</td>
<td>${item.Layers.split(',').map((item) => html`<a href="/config/edit.html?layer=${item}">${item}</a> `)}</td>
</tr>
Expand Down

0 comments on commit aa07266

Please sign in to comment.