Rename SystemMetrics to SystemInfo

There are more pieces of information about a system than just its CPU,
Memory and disk metrics.  To avoid having to build a separate collection
and subscription for metrics and system info, rename the existing system
metrics to system info in anticipation of providing additonal static
system information such as CPU model in it.
This commit is contained in:
Hornwitser committed 2024-01-16 21:27:02 +01:00
1 parent 5f25aad273
commit 4e36fa1b4e
14 files changed
+128 -128

No files matched your search

+10 -10
View File
@@ -204,7 +204,7 @@ export class LogMessageEvent {
}
}
export class SystemMetrics {
export class SystemInfo {
constructor(
/**
* Id of the host these metrics originate from, or the string
@@ -278,31 +278,31 @@ export class SystemMetrics {
}
}
export class SystemMetricsRequest {
declare ["constructor"]: typeof SystemMetricsRequest;
export class SystemInfoRequest {
declare ["constructor"]: typeof SystemInfoRequest;
static type = "request" as const;
static src = "controller" as const;
static dst = "host" as const;
static Response = SystemMetrics;
static Response = SystemInfo;
}
export class SystemMetricsUpdateEvent {
declare ["constructor"]: typeof SystemMetricsUpdateEvent;
export class SystemInfoUpdateEvent {
declare ["constructor"]: typeof SystemInfoUpdateEvent;
static type = "event" as const;
static src = "controller" as const;
static dst = "control" as const;
static permission = "core.system_metrics.subscribe" as const;
static permission = "core.system.subscribe" as const;
constructor(
public updates: SystemMetrics[],
public updates: SystemInfo[],
) { }
static jsonSchema = Type.Object({
"updates": Type.Array(SystemMetrics.jsonSchema),
"updates": Type.Array(SystemInfo.jsonSchema),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.updates.map(update => SystemMetrics.fromJSON(update)));
return new this(json.updates.map(update => SystemInfo.fromJSON(update)));
}
}
+2 -2
View File
@@ -25,8 +25,8 @@ export const dataClasses: (RequestClass<unknown, unknown> | EventClass<unknown>)
controller.LogSetSubscriptionsRequest,
controller.LogQueryRequest,
controller.LogMessageEvent,
controller.SystemMetricsRequest,
controller.SystemMetricsUpdateEvent,
controller.SystemInfoRequest,
controller.SystemInfoUpdateEvent,
controller.DebugDumpWsRequest,
controller.DebugWsMessageEvent,
+4 -4
View File
@@ -130,11 +130,11 @@ definePermission({
description: "Modify the controller config or entries of the controller config.",
});
definePermission({
name: "core.system_metrics.subscribe",
title: "Subscribe to system metrics updates",
name: "core.system.subscribe",
title: "Subscribe to system updates",
description:
"Subscribe to be notified when the system metrics detailing cpu, memory and disk usage for the " +
"controller and hosts are updated.",
"Subscribe to be notified when the system info detailing system specific information along with metrics " +
"such as cpu, memory and disk usage for the controller and hosts are updated.",
});
definePermission({
name: "core.host.get_config",
+3 -3
View File
@@ -2,7 +2,7 @@ import fs from "fs-extra";
import os from "os";
import util from "util";
import { Gauge } from "./prometheus";
import { SystemMetrics } from "./data";
import { SystemInfo } from "./data";
function cpuModel() {
const model = os.cpus()[0].model;
@@ -133,7 +133,7 @@ function minZip<T>(a: T[], b: T[]): [T, T][] {
let previousTotalCpuMs: number[] = [];
let previousIdleCpuMs: number[] = [];
export async function gatherSystemMetrics(id: SystemMetrics["id"]) {
export async function gatherSystemInfo(id: SystemInfo["id"]) {
const cpus = os.cpus();
const currentTotalCpuMs = cpus.map(({ times }) => times.user + times.idle + times.irq + times.nice + times.sys);
const currentIdleCpuMs = cpus.map(({ times }) => times.idle);
@@ -151,7 +151,7 @@ export async function gatherSystemMetrics(id: SystemMetrics["id"]) {
diskAvailable = stats.bavail * stats.bsize;
}
return new SystemMetrics(
return new SystemInfo(
id,
cpuUsage,
os.totalmem(),