package view
import (
"fmt"
"git.staur.ca/stobbsm/clustvirt/lib/host"
)
script memchart(used uint64, free uint64, buf uint64, cache uint64) {
ctx = document.getElementById('memchart');
new Chart(ctx, {
type: 'pie',
data: {
labels: [
'Used',
'Free',
'Cached',
'Buffered'
],
datasets: [{
label: 'Memory Usage',
data: [
used,
free,
cache,
buf,
],
backgroundColor: [
'rgb(255,0,0)',
'rgb(0,255,0)',
'rgb(128,128,0)',
'rgb(0,0,255)'
],
hoverOffset: 4
}],
}
});
}
// MemChart get's the memory pi chart from the host
templ MemChart(h *host.Host) {
- Free: { fmt.Sprintf("%d Gi", h.NodeMemory.Free/1024/1024) }
- Cached: { fmt.Sprintf("%d Gi", h.NodeMemory.Cached/1024/1024) }
- Buffers: { fmt.Sprintf("%d Gi", h.NodeMemory.Buffers/1024/1024) }
- Total: { fmt.Sprintf("%d Gi", h.NodeMemory.Total/1024/1024) }
@memchart(h.NodeMemory.Total-h.NodeMemory.Free-h.NodeMemory.Buffers-h.NodeMemory.Cached, h.NodeMemory.Free,
h.NodeMemory.Buffers, h.NodeMemory.Cached)
}
// HostConnect is the page that allows us to select a host to get information from
templ HostMain() {
}
// HostInfo is meant to be an HTMX response
templ HostInfo(h *host.Host) {
{ h.HostName }
@HostStats(h)
}
templ HostStats(h *host.Host) {
@MemChart(h)
}