From de4798952771b87c5b94e8d2dbc9256776919fc8 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Tue, 16 Jan 2024 18:12:30 +0100 Subject: [PATCH] Add system info to SystemInfo Provide the kernel, machine, CPU Model, hostname, and Node.js version fields to SystemInfo and display them in the Web UI. These were added as metrics exposed to prometheus in b46efeb. --- packages/lib/src/data/messages_controller.ts | 15 +++++++++++++++ packages/lib/src/system_collectors.ts | 10 ++++++++-- .../web_ui/src/components/ControllerPage.tsx | 7 +++++++ packages/web_ui/src/components/HostViewPage.tsx | 6 ++++++ packages/web_ui/src/components/HostsPage.tsx | 12 ++++++++++++ test/lib/data/SystemInfo.js | 16 +++++++++++++++- 6 files changed, 63 insertions(+), 3 deletions(-) diff --git a/packages/lib/src/data/messages_controller.ts b/packages/lib/src/data/messages_controller.ts index 77393fe0..2a755b0e 100644 --- a/packages/lib/src/data/messages_controller.ts +++ b/packages/lib/src/data/messages_controller.ts @@ -211,6 +211,11 @@ export class SystemInfo { * "controller" if these metrics are for the controller. */ public id: number | "controller", + public hostname: string, + public node: string, + public kernel: string, + public machine: string, + public cpuModel: string, public coreRatios: number[], public memoryCapacity: number, public memoryAvailable: number, @@ -223,6 +228,11 @@ export class SystemInfo { static jsonSchema = Type.Object({ "id": Type.Union([Type.Number(), Type.Literal("controller")]), + "hostname": Type.String(), + "node": Type.String(), + "kernel": Type.String(), + "machine": Type.String(), + "cpuModel": Type.String(), "coreRatios": Type.Array(Type.Number()), "memoryCapacity": Type.Number(), "memoryAvailable": Type.Number(), @@ -235,6 +245,11 @@ export class SystemInfo { static fromJSON(json: Static) { return new this( json.id, + json.hostname, + json.node, + json.kernel, + json.machine, + json.cpuModel, json.coreRatios, json.memoryCapacity, json.memoryAvailable, diff --git a/packages/lib/src/system_collectors.ts b/packages/lib/src/system_collectors.ts index be0c64f7..98d92397 100644 --- a/packages/lib/src/system_collectors.ts +++ b/packages/lib/src/system_collectors.ts @@ -4,7 +4,7 @@ import util from "util"; import { Gauge } from "./prometheus"; import { SystemInfo } from "./data"; -function cpuModel() { +function filterCpuModel() { const model = os.cpus()[0].model; // Remove irelevant clutter return model @@ -16,6 +16,7 @@ function cpuModel() { .trim() // AMD CPUs may have trailing spaces in the model. ; } +const cpuModel = filterCpuModel(); export const systemInfo = new Gauge( "system_info", @@ -27,7 +28,7 @@ export const systemInfo = new Gauge( systemInfo.labels({ "kernel": os.type(), "machine": os.machine(), - "cpu_model": cpuModel(), + "cpu_model": cpuModel, "hostname": os.hostname(), "node": process.version, }).set(1); @@ -153,6 +154,11 @@ export async function gatherSystemInfo(id: SystemInfo["id"]) { return new SystemInfo( id, + os.hostname(), + process.version, + os.type(), + os.machine(), + cpuModel, cpuUsage, os.totalmem(), os.freemem(), diff --git a/packages/web_ui/src/components/ControllerPage.tsx b/packages/web_ui/src/components/ControllerPage.tsx index 5cea6eda..7e49d233 100644 --- a/packages/web_ui/src/components/ControllerPage.tsx +++ b/packages/web_ui/src/components/ControllerPage.tsx @@ -11,6 +11,7 @@ import { useAccount } from "../model/account"; import { useSystems } from "../model/system"; import ControllerConfigTree from "./ControllerConfigTree"; import PageLayout from "./PageLayout"; +import webUiPackage from "../../package.json"; const { Title } = Typography; @@ -23,6 +24,12 @@ export default function ControllerPage() { return

Controller

+ {webUiPackage.version} + {system?.node} + {system?.kernel} + {system?.machine} + {system?.hostname} + {system?.cpuModel} diff --git a/packages/web_ui/src/components/HostViewPage.tsx b/packages/web_ui/src/components/HostViewPage.tsx index bac762f0..7963a619 100644 --- a/packages/web_ui/src/components/HostViewPage.tsx +++ b/packages/web_ui/src/components/HostViewPage.tsx @@ -78,6 +78,12 @@ export default function HostViewPage() { {host["connected"] ? "Connected" : "Disconnected"} + {host.version} + {system?.node} + {system?.kernel} + {system?.machine} + {system?.hostname} + {system?.cpuModel} diff --git a/packages/web_ui/src/components/HostsPage.tsx b/packages/web_ui/src/components/HostsPage.tsx index 58cddfaf..a1bcc0fb 100644 --- a/packages/web_ui/src/components/HostsPage.tsx +++ b/packages/web_ui/src/components/HostsPage.tsx @@ -192,6 +192,7 @@ export default function HostsPage() { const [systems] = useSystems(); const [showRatios, setShowRatios] = useState(true); const [showNumbers, setShowNumbers] = useState(false); + const [showCpuModel, setShowCpuModel] = useState(false); return strcmp(a.name, b.name), }, + { + title: "CPU Model", + dataIndex: "cpuModel", + sorter: (a, b) => strcmp(systems.get(a.id)?.cpuModel ?? "", systems.get(b.id)?.cpuModel ?? ""), + render: (_, host) => systems.get(host.id)?.cpuModel, + hidden: !showCpuModel, + }, { title: "CPU%", sorter: (a, b) => (systems.get(a.id)?.cpuRatio ?? 0) - (systems.get(b.id)?.cpuRatio ?? 0), @@ -290,6 +298,10 @@ export default function HostsPage() { Show metric numbers: { setShowNumbers(checked); }} /> + ; diff --git a/test/lib/data/SystemInfo.js b/test/lib/data/SystemInfo.js index 030ddf24..b84b9c34 100644 --- a/test/lib/data/SystemInfo.js +++ b/test/lib/data/SystemInfo.js @@ -8,7 +8,21 @@ const { SystemInfo } = lib; describe("lib/data/ModPack", function() { describe("class SystemInfo", function() { it("correctly calculates derived metrics", function() { - const system = new SystemInfo("controller", [0.5, 0.25, 0, 1], 1024, 768, 2048, 512, 0, false); + const system = new SystemInfo( + "controller", + "server", + "v18.0.0", + "Linux", + "x86_64", + "x86 CPU", + [0.5, 0.25, 0, 1], + 1024, + 768, + 2048, + 512, + 0, + false + ); assert.equal(system.cpuCapacity, 4); assert.equal(system.cpuUsed, 1.75); assert.equal(system.cpuAvailable, 2.25);