Initial commit: host metrics dashboard (React/TS/Chakra, VictoriaMetrics)

This commit is contained in:
2026-09-19 07:43:43 +00:00
commit cb62525863
16 changed files with 3523 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
node_modules/
dist/
*.log
+11
View File
@@ -0,0 +1,11 @@
# syntax=docker/dockerfile:1
FROM docker.io/library/node:22-alpine AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM docker.io/library/busybox:stable
COPY --from=build /app/dist / usr/share/html
CMD ["httpd", "-f", "-p", "80", "-h", "/usr/share/html"]
+28
View File
@@ -0,0 +1,28 @@
# homelab-dashboard
Host metrics dashboard for the homelab fleet, rendered from VictoriaMetrics
(single-node on jupiter) in the HyprChrome design language.
## Stack
- React 19 + TypeScript + Vite
- Chakra UI v3 (theming only — layout/meters are custom FUI components)
- DepartureMono, industrial-cyberpunk palette (#0a0a0a / #e8722a / #ff6b4a)
## Data
- Browser queries VictoriaMetrics directly at http://jupiter.orbit.sol:8428 (CORS open)
- Hosts scraped by node_exporter: jupiter, mars, neptun, terra, mercury (mercury on a 15s job)
## Run in the homelab
Build and deploy per the mars hosting contract:
```sh
podman build -t localhost/homelab-dashboard .
podman run --restart=always -p 127.0.0.1:20002:80 localhost/homelab-dashboard
# register {"port": 20002} in the sites registry
```
Live at http://mars.sol/hostmetrics/
## Dev
```sh
npm install
npm run dev
```
+19
View File
@@ -0,0 +1,19 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>HOSTMETRICS</title>
<style>
@font-face {
font-family: 'DepartureMono';
src: url('https://cdn.jsdelivr.net/gh/slavstanoslav/departure-mono@main/fonts/web/DepartureMono-Regular.woff2') format('woff2');
font-display: swap;
}
</style>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
+3025
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -0,0 +1 @@
{"name":"hostmetrics","private":true,"version":"0.1.0","type":"module","scripts":{"dev":"vite","build":"tsc -b && vite build"},"dependencies":{"@chakra-ui/react":"^3.37.0","@emotion/react":"^11.14.0","@types/react":"^19.3.0","@types/react-dom":"^19.3.0","@vitejs/plugin-react":"^6.1.1","react":"^19.3.0","react-dom":"^19.3.0","typescript":"^7.0.2","vite":"^8.3.0"}}
+77
View File
@@ -0,0 +1,77 @@
import { useEffect, useState } from 'react'
import { Box, HStack, Text } from '@chakra-ui/react'
import { fetchAllHosts, type HostMetrics } from './api'
import { theme } from './theme'
import { MetricRow } from './components/MetricRow'
const POLL_MS = 5000
export function App() {
const [hosts, setHosts] = useState<HostMetrics[]>([])
const [ts, setTs] = useState(0)
const [err, setErr] = useState<string | null>(null)
useEffect(() => {
let alive = true
async function tick() {
try {
const data = await fetchAllHosts()
if (!alive) return
setHosts(data)
setTs(Date.now())
setErr(null)
} catch (e) {
if (alive) setErr(e instanceof Error ? e.message : String(e))
}
}
tick()
const iv = setInterval(tick, POLL_MS)
return () => {
alive = false
clearInterval(iv)
}
}, [])
const upCount = hosts.filter((h) => h.up).length
return (
<Box minH="100vh" p={5} bg={theme.surface}>
{/* header */}
<HStack
justify="space-between"
pb={3}
mb={4}
borderBottom={`1px solid ${theme.hair}`}
wrap="wrap"
gap={2}
>
<HStack gap={3}>
<Text fontSize="18px" fontWeight="bold" color={theme.accent} letterSpacing="0.2em">
HOSTMETRICS
</Text>
<Text fontSize="11px" color={theme.muted} textTransform="uppercase" letterSpacing="0.1em">
fleet · node_exporter via victoria metrics
</Text>
</HStack>
<HStack gap={4}>
<Text fontSize="11px" color={theme.muted} textTransform="uppercase">
hosts up <span style={{ color: theme.text }}>{upCount}/{hosts.length || '—'}</span>
</Text>
<Text fontSize="11px" color={err ? theme.hot : theme.accent} textTransform="uppercase">
{err ? `LINK ERR: ${err}` : 'LINK OK'}
</Text>
</HStack>
</HStack>
{hosts.length === 0 && !err && (
<Text color={theme.muted} fontSize="13px">scanning fleet…</Text>
)}
<Box display="grid" gridTemplateColumns={{ base: '1fr', lg: '1fr 1fr' }} gap={4}>
{hosts.map((h) => (
<MetricRow key={h.host} m={h} ts={ts} />
))}
</Box>
</Box>
)
}
+125
View File
@@ -0,0 +1,125 @@
// VictoriaMetrics API client — direct browser fetch, VM serves Allow-Origin: *
const VM_BASE = import.meta.env.VITE_VM_URL ?? 'http://jupiter.orbit.sol:8428'
export interface VMResult {
metric: Record<string, string>
value: [number, string]
}
export interface VMResponse {
status: string
data: { resultType: string; result: VMResult[] }
}
export async function query(q: string): Promise<VMResult[]> {
const url = `${VM_BASE}/api/v1/query?query=${encodeURIComponent(q)}`
const res = await fetch(url)
if (!res.ok) throw new Error(`VM returned ${res.status}`)
const json: VMResponse = await res.json()
if (json.status !== 'success') throw new Error(`VM query failed: ${json.status}`)
return json.data.result
}
export interface HostMetrics {
host: string
up: boolean
cpuPct: number | null
load1: number | null
cores: number | null
memUsedPct: number | null
memTotal: number | null
diskUsedPct: number | null
diskTotal: number | null
tempC: number | null
}
function num(v: VMResult[]): Map<string, number> {
const m = new Map<string, number>()
for (const r of v) {
const host = r.metric.host
const val = parseFloat(r.value[1])
if (host && Number.isFinite(val)) m.set(host, val)
}
return m
}
function sum(v: VMResult[]): Map<string, number> {
const m = new Map<string, number>()
for (const r of v) {
const host = r.metric.host
const val = parseFloat(r.value[1])
if (!host || !Number.isFinite(val)) continue
m.set(host, (m.get(host) ?? 0) + val)
}
return m
}
function max(v: VMResult[]): Map<string, number> {
const m = new Map<string, number>()
for (const r of v) {
const host = r.metric.host
const val = parseFloat(r.value[1])
if (!host || !Number.isFinite(val)) continue
m.set(host, Math.max(m.get(host) ?? -Infinity, val))
}
return m
}
async function one(q: string): Promise<Map<string, number>> {
return num(await query(q))
}
export async function fetchAllHosts(): Promise<HostMetrics[]> {
const [up, memTotal, memAvail, diskTotal, diskAvail, temp, loadM] = await Promise.all([
one('up{job=~"node-exporter.*"}'),
one('node_memory_MemTotal_bytes'),
one('node_memory_MemAvailable_bytes'),
one('node_filesystem_size_bytes{fstype="ext4",mountpoint!~"/boot.*"}'),
one('node_filesystem_avail_bytes{fstype="ext4",mountpoint!~"/boot.*"}'),
max(await query('node_hwmon_temp_celsius')),
one('node_load1'),
])
// CPU busy%: average idle rate per core over a 1m window
const idleAvg = new Map<string, number>()
const idleSum = new Map<string, number>()
const coreCount = new Map<string, number>()
for (const r of await query('rate(node_cpu_seconds_total{mode="idle"}[1m]) * 100')) {
const host = r.metric.host
const val = parseFloat(r.value[1])
if (!host || !Number.isFinite(val)) continue
idleSum.set(host, (idleSum.get(host) ?? 0) + val)
coreCount.set(host, (coreCount.get(host) ?? 0) + 1)
}
for (const [host, s] of idleSum) {
const cores = coreCount.get(host) ?? 1
idleAvg.set(host, s / cores)
}
const hosts = new Set<string>([...up.keys(), ...coreCount.keys()])
hosts.delete('jupiter') // dedupe: keep the node-exporter job one
hosts.add('jupiter')
const out: HostMetrics[] = []
for (const host of hosts) {
const isUp = up.get(host) === 1
const mt = memTotal.get(host)
const ma = memAvail.get(host)
const dt = diskTotal.get(host) ?? 0
const da = diskAvail.get(host) ?? 0
const idle = idleAvg.get(host)
out.push({
host,
up: isUp,
cpuPct: isUp && idle !== undefined ? 100 - idle : null,
load1: loadM.get(host) ?? null,
cores: coreCount.get(host) ?? null,
memUsedPct: mt && ma !== undefined ? ((mt - ma) / mt) * 100 : null,
memTotal: mt ?? null,
diskUsedPct: dt && da ? ((dt - da) / dt) * 100 : null,
diskTotal: dt || null,
tempC: temp.get(host) ?? null,
})
}
return out.sort((a, b) => a.host.localeCompare(b.host))
}
+127
View File
@@ -0,0 +1,127 @@
import { HStack, Text, Box } from '@chakra-ui/react'
import { SegmentMeter } from './SegmentMeter'
import { theme } from '../theme'
import type { HostMetrics } from '../api'
function fmtBytes(n: number | null): string {
if (n == null) return '—'
const units = ['B', 'K', 'M', 'G', 'T']
let v = n
let u = 0
while (v >= 1024 && u < units.length - 1) {
v /= 1024
u++
}
return `${v.toFixed(v >= 100 || u === 0 ? 0 : 1)}${units[u]}`
}
function pct(v: number | null): string {
return v == null ? '—' : `${v.toFixed(1)}%`
}
const cell = {
border: `1px solid ${theme.hair}`,
bg: 'rgba(222,222,222,0.02)',
p: 2,
minW: 0,
} as const
export function MetricRow({ m, ts }: { m: HostMetrics; ts: number }) {
const up = m.up
const statusColor = up ? theme.accent : theme.hot
const load = m.load1 != null ? m.load1.toFixed(2) : '—'
return (
<Box
position="relative"
border={`1px solid ${theme.hair}`}
bg={theme.surface}
p={4}
minW={0}
_before={{
content: '""',
position: 'absolute',
top: '-1px',
right: '-1px',
width: '18px',
height: '18px',
background: `linear-gradient(135deg, ${theme.surface} 45%, transparent 45%)`,
borderLeft: `1px solid ${theme.hair}`,
borderBottom: `1px solid ${theme.hair}`,
}}
>
{/* header line */}
<HStack justify="space-between" mb={3}>
<HStack gap={3} minW={0}>
<Box w="8px" h="8px" bg={statusColor} flexShrink={0} />
<Text
fontSize="15px"
fontWeight="bold"
color={up ? theme.text : theme.muted}
letterSpacing="0.08em"
textTransform="uppercase"
>
{m.host}
</Text>
<Text fontSize="11px" color={theme.muted} textTransform="uppercase">
{up ? `online · ${m.cores ?? '?'} cores` : 'offline'}
</Text>
</HStack>
<Text fontSize="11px" color={theme.muted} flexShrink={0}>
{ts ? new Date(ts).toLocaleTimeString('en-GB') : ''}
</Text>
</HStack>
{/* meters */}
<HStack gap={4} align="stretch" wrap="wrap">
<Box {...cell} flex="1" minW="220px">
<HStack justify="space-between" mb={1}>
<Text fontSize="11px" color={theme.muted} textTransform="uppercase" letterSpacing="0.1em">CPU</Text>
<Text fontSize="13px" color={(m.cpuPct ?? 0) >= 85 && up ? theme.hot : theme.text} fontWeight="bold">
{up ? pct(m.cpuPct) : '—'}
</Text>
</HStack>
<SegmentMeter value={m.cpuPct ?? 0} ready={up} />
</Box>
<Box {...cell} flex="1" minW="220px">
<HStack justify="space-between" mb={1}>
<Text fontSize="11px" color={theme.muted} textTransform="uppercase" letterSpacing="0.1em">MEM</Text>
<Text fontSize="13px" color={(m.memUsedPct ?? 0) >= 85 && up ? theme.hot : theme.text} fontWeight="bold">
{up ? pct(m.memUsedPct) : '—'}
</Text>
</HStack>
<SegmentMeter value={m.memUsedPct ?? 0} ready={up} />
<Text fontSize="10px" color={theme.muted} mt={1}>
{up ? `${fmtBytes(m.memTotal != null && m.memUsedPct != null ? m.memTotal * (1 - m.memUsedPct / 100) : null)} free / ${fmtBytes(m.memTotal)}` : ''}
</Text>
</Box>
<Box {...cell} flex="1" minW="220px">
<HStack justify="space-between" mb={1}>
<Text fontSize="11px" color={theme.muted} textTransform="uppercase" letterSpacing="0.1em">DISK</Text>
<Text fontSize="13px" color={(m.diskUsedPct ?? 0) >= 85 && up ? theme.hot : theme.text} fontWeight="bold">
{up ? pct(m.diskUsedPct) : '—'}
</Text>
</HStack>
<SegmentMeter value={m.diskUsedPct ?? 0} ready={up} />
<Text fontSize="10px" color={theme.muted} mt={1}>
{up ? `${fmtBytes(m.diskTotal != null && m.diskUsedPct != null ? m.diskTotal * (m.diskUsedPct / 100) : null)} / ${fmtBytes(m.diskTotal)}` : ''}
</Text>
</Box>
<Box {...cell} minW="150px">
<Text fontSize="11px" color={theme.muted} textTransform="uppercase" letterSpacing="0.1em">LOAD1</Text>
<Text fontSize="18px" color={up ? theme.text : theme.muted} fontWeight="bold">{load}</Text>
</Box>
<Box {...cell} minW="110px">
<Text fontSize="11px" color={theme.muted} textTransform="uppercase" letterSpacing="0.1em">TEMP</Text>
<Text fontSize="18px" color={(m.tempC ?? 0) >= 75 ? theme.hot : theme.text} fontWeight="bold">
{up && m.tempC != null ? `${m.tempC.toFixed(0)}°C` : '—'}
</Text>
</Box>
</HStack>
</Box>
)
}
+45
View File
@@ -0,0 +1,45 @@
import { HStack, Text } from '@chakra-ui/react'
import { theme } from '../theme'
interface Props {
value: number // 0..100
ready: boolean
warn?: number // % at which cells go hot (default 85)
}
const SEGMENTS = 16
export function SegmentMeter({ value, ready, warn = 85 }: Props) {
const frac = Math.max(0, Math.min(1, ready ? value / 100 : 0))
const hot = ready && frac * 100 >= warn
const litColor = hot ? theme.hot : theme.accent
const litCount = Math.round(frac * SEGMENTS)
return (
<HStack gap="2px" h="14px" w="full">
{Array.from({ length: SEGMENTS }, (_, i) => {
const lit = ready && i < litCount
return (
<div
key={i}
style={{
flex: 1,
height: 12,
background: lit ? litColor : 'rgba(222,222,222,0.06)',
border: `1px solid ${lit ? litColor : 'rgba(222,222,222,0.18)'}`,
}}
/>
)
})}
</HStack>
)
}
export function Readout({ label, value }: { label: string; value: string }) {
return (
<HStack gap={1.5}>
<Text color={theme.accent} fontSize="13px">{label}</Text>
<Text color={theme.text} fontSize="13px" fontWeight="bold">{value}</Text>
</HStack>
)
}
+22
View File
@@ -0,0 +1,22 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import { ChakraProvider, createSystem, defineConfig, defaultConfig } from '@chakra-ui/react'
import { App } from './App'
import { theme } from './theme'
const config = defineConfig({
globalCss: {
html: { backgroundColor: theme.surface, colorScheme: 'dark' },
body: { backgroundColor: theme.surface, color: theme.text, fontFamily: "'DepartureMono', monospace" },
},
})
const system = createSystem(defaultConfig, config)
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<ChakraProvider value={system}>
<App />
</ChakraProvider>
</React.StrictMode>,
)
+12
View File
@@ -0,0 +1,12 @@
// HyprChrome palette — mirrored from dotfiles/quickshell/HyprChrome/Theme/Theme.qml
export const theme = {
accent: '#e8722a',
text: '#dedede',
muted: '#858585',
surface: '#0a0a0a',
hot: '#ff6b4a',
selection: '#1a1c1f',
raised: '#292c30',
disabled: '#3a3d42',
hair: 'rgba(222,222,222,0.28)',
}
+1
View File
@@ -0,0 +1 @@
/// <reference types="vite/client" />
+18
View File
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2023", "DOM", "DOM.Iterable"],
"module": "ESNext",
"moduleResolution": "bundler",
"types": ["vite/client"],
"jsx": "react-jsx",
"strict": true,
"noEmit": true,
"isolatedModules": true,
"skipLibCheck": true,
"useDefineForClassFields": true,
"noUnusedLocals": false,
"noUnusedParameters": false
},
"include": ["src", "vite.config.ts"]
}
File diff suppressed because one or more lines are too long
+8
View File
@@ -0,0 +1,8 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
base: './',
plugins: [react()],
build: { target: 'es2022' },
})