2024-03-17 06:10:04 +00:00
|
|
|
package view
|
|
|
|
|
|
|
|
import (
|
2024-03-19 04:38:28 +00:00
|
|
|
"fmt"
|
2024-03-17 06:10:04 +00:00
|
|
|
"git.staur.ca/stobbsm/clustvirt/lib/host"
|
|
|
|
"git.staur.ca/stobbsm/clustvirt/view/components"
|
|
|
|
"git.staur.ca/stobbsm/clustvirt/view/layouts"
|
|
|
|
)
|
|
|
|
|
2024-03-19 04:38:28 +00:00
|
|
|
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
|
|
|
|
}],
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-03-17 06:10:04 +00:00
|
|
|
// MemChart get's the memory pi chart from the host
|
|
|
|
templ MemChart(h *host.Host) {
|
|
|
|
<div class={ "flex" , "flex-row" }>
|
2024-03-19 04:38:28 +00:00
|
|
|
<div class={ "size-40" , "md:size-80" }>
|
|
|
|
<canvas id="memchart" class={ "size-40" , "md:size-80" }></canvas>
|
2024-03-17 06:10:04 +00:00
|
|
|
</div>
|
|
|
|
<ul>
|
2024-03-19 04:38:28 +00:00
|
|
|
<li>Free: <span id="memfree">{ fmt.Sprintf("%d Gi", h.NodeMemory.Free/1024/1024) }</span></li>
|
|
|
|
<li>Cached: <span id="memcach">{ fmt.Sprintf("%d Gi", h.NodeMemory.Cached/1024/1024) }</span></li>
|
|
|
|
<li>Buffers: <span id="membuf">{ fmt.Sprintf("%d Gi", h.NodeMemory.Buffers/1024/1024) }</span></li>
|
|
|
|
<li>Total: <span id="memtot">{ fmt.Sprintf("%d Gi", h.NodeMemory.Total/1024/1024) }</span></li>
|
2024-03-17 06:10:04 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
2024-03-19 04:38:28 +00:00
|
|
|
@memchart(h.NodeMemory.Total-h.NodeMemory.Free-h.NodeMemory.Buffers-h.NodeMemory.Cached, h.NodeMemory.Free,
|
|
|
|
h.NodeMemory.Buffers, h.NodeMemory.Cached)
|
|
|
|
}
|
|
|
|
|
|
|
|
templ hostButton(hostname string) {
|
|
|
|
<button
|
|
|
|
hx-target="#sysContent"
|
|
|
|
hx-get={ fmt.Sprintf("/htmx/host/%s", hostname) }
|
|
|
|
class={ "rounded",
|
|
|
|
"border",
|
|
|
|
"border-solid",
|
|
|
|
"border-uiblue-700",
|
|
|
|
"text-uigrey-200",
|
|
|
|
"bg-uiblue-800",
|
|
|
|
"hover:border-uipurple-400",
|
|
|
|
"hover:text-ui-grey-800",
|
|
|
|
"hover:bg-uipurple-600",
|
|
|
|
"gap-2",
|
|
|
|
"p-1",
|
|
|
|
"my-1",
|
|
|
|
"w-full",
|
|
|
|
"flex",
|
|
|
|
"flex-row",
|
|
|
|
"justify-between" }
|
|
|
|
>
|
|
|
|
<span class={ "px-2" }>{ hostname }</span>
|
|
|
|
<img class={ "htmx-indicator" , "inline-block" , "h-6" , "px-2" } src="/static/images/bars.svg"/>
|
|
|
|
</button>
|
2024-03-17 06:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// HostConnect is the page that allows us to select a host to get information from
|
|
|
|
templ HostMain(navBarItems []components.NavItem) {
|
|
|
|
@layouts.Manager("ClustVirt", "Cluster Manager", navBarItems) {
|
2024-03-19 04:38:28 +00:00
|
|
|
<div class={ "flex" , "flex-row" , "h-full" , "mt-2" }>
|
|
|
|
<div id="sysNavBar" class={ "w-1/6" , "border-uigrey-600" , "border" , "rounded" , "border-dotted" , "p-2" }>
|
2024-03-17 06:10:04 +00:00
|
|
|
<ul>
|
2024-03-19 04:38:28 +00:00
|
|
|
<li>
|
|
|
|
@hostButton("venus.staur.ca")
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
@hostButton("earth.staur.ca")
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
@hostButton("mars.staur.ca")
|
|
|
|
</li>
|
2024-03-17 06:10:04 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div id="sysContent" class={ "w-3/4" , "px-2" }>
|
|
|
|
<p>This is where you can see a system overview of all available hosts</p>
|
|
|
|
<p>
|
|
|
|
For now, there is just this simple box to choose a host to connect to
|
|
|
|
and push the button to load the system information via HTMX
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// HostInfo is meant to be an HTMX response
|
|
|
|
templ HostInfo(h *host.Host) {
|
2024-03-19 04:38:28 +00:00
|
|
|
<div class={ "flex" , "flex-col" }>
|
|
|
|
<div
|
|
|
|
class={ "flex" , "flex-row" , "justify-start" , "px-2" }
|
|
|
|
hx-trigger="every 30s"
|
|
|
|
hx-get={ fmt.Sprintf("/htmx/host/%s/stats", h.HostName) }
|
|
|
|
hx-target="#sysInfo"
|
|
|
|
>
|
|
|
|
<h3>{ h.HostName }</h3>
|
|
|
|
<img class={ "h-6" , "px-2" , "htmx-indicator" , "inline-block" } src="/static/images/grid.svg"/>
|
|
|
|
</div>
|
|
|
|
<div class={ "flex" , "flex-row" , "flex-wrap" } id="sysInfo">
|
|
|
|
@SysInfo(h)
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
|
|
|
|
templ SysInfo(h *host.Host) {
|
2024-03-17 06:10:04 +00:00
|
|
|
@MemChart(h)
|
|
|
|
}
|