From 99d61a0193db4c48a540822d37d9409888357fef Mon Sep 17 00:00:00 2001 From: henrygd Date: Tue, 8 Jul 2025 18:21:14 -0400 Subject: [PATCH] update makefile and other tiny refactoring - remove goccy/json dep - add explicit types in gpu.go --- beszel/Makefile | 2 +- beszel/internal/agent/agent_cache_test.go | 3 +++ beszel/internal/agent/gpu.go | 22 +++++++++---------- beszel/internal/alerts/alerts_system.go | 2 +- beszel/site/src/components/router.tsx | 11 ++++++++-- .../systems-table/systems-table.tsx | 2 +- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/beszel/Makefile b/beszel/Makefile index 46e3b1a..b995d85 100644 --- a/beszel/Makefile +++ b/beszel/Makefile @@ -56,7 +56,7 @@ dev-hub: export ENV=dev dev-hub: mkdir -p ./site/dist && touch ./site/dist/index.html @if command -v entr >/dev/null 2>&1; then \ - find ./cmd/hub/*.go ./internal/{alerts,hub,records,users}/*.go | entr -r -s "cd ./cmd/hub && go run . serve --http 0.0.0.0:8090"; \ + find ./cmd/hub ./internal/{alerts,hub,records,users} -name "*.go" | entr -r -s "cd ./cmd/hub && go run . serve"; \ else \ cd ./cmd/hub && go run . serve --http 0.0.0.0:8090; \ fi diff --git a/beszel/internal/agent/agent_cache_test.go b/beszel/internal/agent/agent_cache_test.go index 81b284d..7f6ae11 100644 --- a/beszel/internal/agent/agent_cache_test.go +++ b/beszel/internal/agent/agent_cache_test.go @@ -1,3 +1,6 @@ +//go:build testing +// +build testing + package agent import ( diff --git a/beszel/internal/agent/gpu.go b/beszel/internal/agent/gpu.go index 7bf1091..26850c7 100644 --- a/beszel/internal/agent/gpu.go +++ b/beszel/internal/agent/gpu.go @@ -18,24 +18,24 @@ import ( const ( // Commands - nvidiaSmiCmd = "nvidia-smi" - rocmSmiCmd = "rocm-smi" - tegraStatsCmd = "tegrastats" + nvidiaSmiCmd string = "nvidia-smi" + rocmSmiCmd string = "rocm-smi" + tegraStatsCmd string = "tegrastats" // Polling intervals - nvidiaSmiInterval = "4" // in seconds - tegraStatsInterval = "3700" // in milliseconds - rocmSmiInterval = 4300 * time.Millisecond + nvidiaSmiInterval string = "4" // in seconds + tegraStatsInterval string = "3700" // in milliseconds + rocmSmiInterval time.Duration = 4300 * time.Millisecond // Command retry and timeout constants - retryWaitTime = 5 * time.Second - maxFailureRetries = 5 + retryWaitTime time.Duration = 5 * time.Second + maxFailureRetries int = 5 - cmdBufferSize = 10 * 1024 + cmdBufferSize uint16 = 10 * 1024 // Unit Conversions - mebibytesInAMegabyte = 1.024 // nvidia-smi reports memory in MiB - milliwattsInAWatt = 1000.0 // tegrastats reports power in mW + mebibytesInAMegabyte float64 = 1.024 // nvidia-smi reports memory in MiB + milliwattsInAWatt float64 = 1000.0 // tegrastats reports power in mW ) // GPUManager manages data collection for GPUs (either Nvidia or AMD) diff --git a/beszel/internal/alerts/alerts_system.go b/beszel/internal/alerts/alerts_system.go index fa53969..144bd9d 100644 --- a/beszel/internal/alerts/alerts_system.go +++ b/beszel/internal/alerts/alerts_system.go @@ -2,11 +2,11 @@ package alerts import ( "beszel/internal/entities/system" + "encoding/json" "fmt" "strings" "time" - "github.com/goccy/go-json" "github.com/pocketbase/dbx" "github.com/pocketbase/pocketbase/core" "github.com/pocketbase/pocketbase/tools/types" diff --git a/beszel/site/src/components/router.tsx b/beszel/site/src/components/router.tsx index 2138348..52f98f4 100644 --- a/beszel/site/src/components/router.tsx +++ b/beszel/site/src/components/router.tsx @@ -11,7 +11,7 @@ const routes = { * The base path of the application. * This is used to prepend the base path to all routes. */ -export const basePath = globalThis.BESZEL.BASE_PATH || "" +export const basePath = BESZEL?.BASE_PATH || "" /** * Prepends the base path to the given path. @@ -41,5 +41,12 @@ function onClick(e: React.MouseEvent) { } export const Link = (props: React.AnchorHTMLAttributes) => { - return + let clickFn = onClick + if (props.onClick) { + clickFn = (e) => { + onClick(e) + props.onClick?.(e) + } + } + return } diff --git a/beszel/site/src/components/systems-table/systems-table.tsx b/beszel/site/src/components/systems-table/systems-table.tsx index 6403b78..c7c580e 100644 --- a/beszel/site/src/components/systems-table/systems-table.tsx +++ b/beszel/site/src/components/systems-table/systems-table.tsx @@ -293,7 +293,7 @@ export default function SystemsTable() { "bg-yellow-500" } /> - {info.getValue() as string} + {info.getValue() as string} ) },