add hardware metric key types
This commit is contained in:
1 parent
3586ac9437
commit
21fb320f3a
4 files changed
+21
-16
No files matched your search
@@ -240,3 +240,8 @@ export type GamesMap = Record<string, Game>;
|
|||||||
export type MonitorScheduleFields = Pick<Monitor, "id" | "type" | "isActive" | "interval" | "geoCheckEnabled" | "geoCheckInterval">;
|
export type MonitorScheduleFields = Pick<Monitor, "id" | "type" | "isActive" | "interval" | "geoCheckEnabled" | "geoCheckInterval">;
|
||||||
|
|
||||||
export type DockerContainerLogsResult = DockerLogPage;
|
export type DockerContainerLogsResult = DockerLogPage;
|
||||||
|
|
||||||
|
export const HardwareMetricKeys = ["cpu", "memory", "disk", "temp"] as const;
|
||||||
|
export type HardwareMetricKey = (typeof HardwareMetricKeys)[number];
|
||||||
|
export type HardwareBreaches = Record<HardwareMetricKey, boolean>;
|
||||||
|
export type HardwareCounters = Record<HardwareMetricKey, number>;
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { HardwareMetricKey } from "@/domain/monitors/monitor.type.js";
|
||||||
|
|
||||||
export const NotificationChannels = [
|
export const NotificationChannels = [
|
||||||
"email",
|
"email",
|
||||||
"slack",
|
"slack",
|
||||||
@@ -85,7 +87,7 @@ export interface MonitorInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ThresholdBreach {
|
export interface ThresholdBreach {
|
||||||
metric: "cpu" | "memory" | "disk" | "temp";
|
metric: HardwareMetricKey;
|
||||||
currentValue: number;
|
currentValue: number;
|
||||||
threshold: number;
|
threshold: number;
|
||||||
unit: string;
|
unit: string;
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
import { IMonitorStatsRepository } from "@/domain/monitor-stats/monitor-stats.repository.interface.js";
|
import { IMonitorStatsRepository } from "@/domain/monitor-stats/monitor-stats.repository.interface.js";
|
||||||
import { IMonitorsRepository } from "@/domain/monitors/monitor.repository.interface.js";
|
import { IMonitorsRepository } from "@/domain/monitors/monitor.repository.interface.js";
|
||||||
import type { Check, CheckDiskInfo } from "@/domain/checks/check.type.js";
|
import type { Check, CheckDiskInfo } from "@/domain/checks/check.type.js";
|
||||||
import { MonitorStatuses, type Monitor, type MonitorStatus } from "@/domain/monitors/monitor.type.js";
|
import {
|
||||||
|
HardwareBreaches,
|
||||||
|
HardwareCounters,
|
||||||
|
HardwareMetricKeys,
|
||||||
|
MonitorStatuses,
|
||||||
|
type Monitor,
|
||||||
|
type MonitorStatus,
|
||||||
|
} from "@/domain/monitors/monitor.type.js";
|
||||||
import type { StatusChangeResult } from "@/types/network.js";
|
import type { StatusChangeResult } from "@/types/network.js";
|
||||||
import { AppError } from "@/utils/AppError.js";
|
import { AppError } from "@/utils/AppError.js";
|
||||||
import { ILogger } from "@/utils/logger.js";
|
import { ILogger } from "@/utils/logger.js";
|
||||||
@@ -12,10 +19,6 @@ import { findContainerBreaches } from "@/domain/docker/docker-alert.js";
|
|||||||
|
|
||||||
const SERVICE_NAME = "StatusService";
|
const SERVICE_NAME = "StatusService";
|
||||||
const HARDWARE_ALERT_COUNTER_START = 5;
|
const HARDWARE_ALERT_COUNTER_START = 5;
|
||||||
const HARDWARE_METRIC_KEYS = ["cpu", "memory", "disk", "temp"] as const;
|
|
||||||
type HardwareMetricKey = (typeof HARDWARE_METRIC_KEYS)[number];
|
|
||||||
type HardwareBreaches = Record<HardwareMetricKey, boolean>;
|
|
||||||
type HardwareCounters = Record<HardwareMetricKey, number>;
|
|
||||||
|
|
||||||
export interface IStatusService {
|
export interface IStatusService {
|
||||||
updateRunningStats(check: Check, monitor: Monitor): Promise<boolean>;
|
updateRunningStats(check: Check, monitor: Monitor): Promise<boolean>;
|
||||||
@@ -111,7 +114,7 @@ export class StatusService implements IStatusService {
|
|||||||
|
|
||||||
// Update counters: decrement (floored at 0) if breached, reset to start otherwise.
|
// Update counters: decrement (floored at 0) if breached, reset to start otherwise.
|
||||||
const nextCounters = { ...counters };
|
const nextCounters = { ...counters };
|
||||||
for (const key of HARDWARE_METRIC_KEYS) {
|
for (const key of HardwareMetricKeys) {
|
||||||
nextCounters[key] = breaches[key] ? Math.max(0, counters[key] - 1) : HARDWARE_ALERT_COUNTER_START;
|
nextCounters[key] = breaches[key] ? Math.max(0, counters[key] - 1) : HARDWARE_ALERT_COUNTER_START;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,8 +126,8 @@ export class StatusService implements IStatusService {
|
|||||||
if (!reachabilityDown) {
|
if (!reachabilityDown) {
|
||||||
// A counter can only reach zero via the decrement path, which only runs when that
|
// A counter can only reach zero via the decrement path, which only runs when that
|
||||||
// metric is currently breaching — so anyCounterZero already implies anyBreached.
|
// metric is currently breaching — so anyCounterZero already implies anyBreached.
|
||||||
const anyCounterZero = HARDWARE_METRIC_KEYS.some((k) => nextCounters[k] === 0);
|
const anyCounterZero = HardwareMetricKeys.some((k) => nextCounters[k] === 0);
|
||||||
const allNormal = HARDWARE_METRIC_KEYS.every((k) => !breaches[k]);
|
const allNormal = HardwareMetricKeys.every((k) => !breaches[k]);
|
||||||
|
|
||||||
if (anyCounterZero && currentStatus !== "breached") {
|
if (anyCounterZero && currentStatus !== "breached") {
|
||||||
nextStatus = "breached";
|
nextStatus = "breached";
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import type {
|
|||||||
ILighthouseAudit,
|
ILighthouseAudit,
|
||||||
} from "@/domain/checks/check.type.js";
|
} from "@/domain/checks/check.type.js";
|
||||||
import { DockerContainerInfo, DockerContainerLogs, DockerContainerSummary } from "@/domain/docker/docker.type.js";
|
import { DockerContainerInfo, DockerContainerLogs, DockerContainerSummary } from "@/domain/docker/docker.type.js";
|
||||||
import type { DnsRecordType, Monitor, MonitorMatchMethod, MonitorStatus, MonitorType } from "@/domain/monitors/monitor.type.js";
|
import type { DnsRecordType, HardwareBreaches, Monitor, MonitorMatchMethod, MonitorStatus, MonitorType } from "@/domain/monitors/monitor.type.js";
|
||||||
|
|
||||||
import type { QueryResult } from "gamedig";
|
import type { QueryResult } from "gamedig";
|
||||||
|
|
||||||
@@ -184,12 +184,7 @@ export type StatusChangeResult = {
|
|||||||
prevStatus: MonitorStatus;
|
prevStatus: MonitorStatus;
|
||||||
code: number;
|
code: number;
|
||||||
timestamp: number;
|
timestamp: number;
|
||||||
thresholdBreaches?: {
|
thresholdBreaches?: HardwareBreaches;
|
||||||
cpu: boolean;
|
|
||||||
memory: boolean;
|
|
||||||
disk: boolean;
|
|
||||||
temp: boolean;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type MonitorStatusResponseOverrides<T> = Partial<Omit<MonitorStatusResponse<T>, "monitorId" | "teamId" | "type">>;
|
export type MonitorStatusResponseOverrides<T> = Partial<Omit<MonitorStatusResponse<T>, "monitorId" | "teamId" | "type">>;
|
||||||
|
|||||||
Reference in new issue
Block a user