nomoreide 0.1.93 → 0.1.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/host-metrics.d.ts +41 -0
- package/dist/core/host-metrics.js +93 -0
- package/dist/core/host-metrics.js.map +1 -0
- package/dist/core/metrics-store.d.ts +28 -1
- package/dist/core/metrics-store.js +58 -3
- package/dist/core/metrics-store.js.map +1 -1
- package/dist/web/client/assets/{code-editor-C9RcL5cM.js → code-editor-C2_ukSan.js} +1 -1
- package/dist/web/client/assets/index-CKHDI1ud.js +242 -0
- package/dist/web/client/assets/index-DVHKZVqv.css +1 -0
- package/dist/web/client/index.html +2 -2
- package/dist/web/routes/metrics-routes.d.ts +1 -1
- package/dist/web/routes/metrics-routes.js +5 -2
- package/dist/web/routes/metrics-routes.js.map +1 -1
- package/dist/web/routes/shell-routes.js +2 -0
- package/dist/web/routes/shell-routes.js.map +1 -1
- package/dist/web/server.js +2 -2
- package/dist/web/server.js.map +1 -1
- package/package.json +2 -1
- package/dist/web/client/assets/index-94L5mFZd.js +0 -228
- package/dist/web/client/assets/index-DpqkI74n.css +0 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type CpuInfo } from "node:os";
|
|
2
|
+
export interface CpuTimes {
|
|
3
|
+
idle: number;
|
|
4
|
+
total: number;
|
|
5
|
+
}
|
|
6
|
+
export interface DiskUsage {
|
|
7
|
+
path: string;
|
|
8
|
+
totalBytes: number;
|
|
9
|
+
usedBytes: number;
|
|
10
|
+
availableBytes: number;
|
|
11
|
+
usedPercent: number;
|
|
12
|
+
}
|
|
13
|
+
export interface HostMetricSample {
|
|
14
|
+
t: number;
|
|
15
|
+
cpuPercent: number | null;
|
|
16
|
+
memoryUsedBytes: number;
|
|
17
|
+
memoryTotalBytes: number;
|
|
18
|
+
memoryUsedPercent: number;
|
|
19
|
+
loadAverage: [number, number, number] | null;
|
|
20
|
+
uptimeSeconds: number;
|
|
21
|
+
logicalCpuCount: number;
|
|
22
|
+
disk: DiskUsage | null;
|
|
23
|
+
}
|
|
24
|
+
export interface HostMetricsReader {
|
|
25
|
+
cpuInfo(): CpuInfo[];
|
|
26
|
+
diskUsage(path: string): Promise<DiskUsage>;
|
|
27
|
+
freeMemoryBytes(): number;
|
|
28
|
+
loadAverage(): [number, number, number] | null;
|
|
29
|
+
totalMemoryBytes(): number;
|
|
30
|
+
uptimeSeconds(): number;
|
|
31
|
+
}
|
|
32
|
+
export declare class HostMetricsCollector {
|
|
33
|
+
private readonly path;
|
|
34
|
+
private readonly reader;
|
|
35
|
+
private previousCpu?;
|
|
36
|
+
constructor(path: string, reader?: HostMetricsReader);
|
|
37
|
+
sample(now?: number): Promise<HostMetricSample>;
|
|
38
|
+
}
|
|
39
|
+
export declare function summarizeCpuTimes(cpuInfo: CpuInfo[]): CpuTimes;
|
|
40
|
+
export declare function calculateCpuPercent(previous: CpuTimes | undefined, current: CpuTimes): number | null;
|
|
41
|
+
export declare function readDiskUsage(path: string): Promise<DiskUsage>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { statfs } from "node:fs/promises";
|
|
2
|
+
import { cpus, freemem, loadavg, platform, totalmem, uptime, } from "node:os";
|
|
3
|
+
export class HostMetricsCollector {
|
|
4
|
+
path;
|
|
5
|
+
reader;
|
|
6
|
+
previousCpu;
|
|
7
|
+
constructor(path, reader = defaultHostMetricsReader) {
|
|
8
|
+
this.path = path;
|
|
9
|
+
this.reader = reader;
|
|
10
|
+
}
|
|
11
|
+
async sample(now = Date.now()) {
|
|
12
|
+
const cpuInfo = this.reader.cpuInfo();
|
|
13
|
+
const currentCpu = summarizeCpuTimes(cpuInfo);
|
|
14
|
+
const cpuPercent = calculateCpuPercent(this.previousCpu, currentCpu);
|
|
15
|
+
this.previousCpu = currentCpu;
|
|
16
|
+
const memoryTotalBytes = Math.max(0, this.reader.totalMemoryBytes());
|
|
17
|
+
const memoryFreeBytes = clamp(this.reader.freeMemoryBytes(), 0, memoryTotalBytes);
|
|
18
|
+
const memoryUsedBytes = Math.max(0, memoryTotalBytes - memoryFreeBytes);
|
|
19
|
+
const disk = await this.reader.diskUsage(this.path).catch(() => null);
|
|
20
|
+
return {
|
|
21
|
+
t: now,
|
|
22
|
+
cpuPercent,
|
|
23
|
+
memoryUsedBytes,
|
|
24
|
+
memoryTotalBytes,
|
|
25
|
+
memoryUsedPercent: percent(memoryUsedBytes, memoryTotalBytes),
|
|
26
|
+
loadAverage: this.reader.loadAverage(),
|
|
27
|
+
uptimeSeconds: Math.max(0, this.reader.uptimeSeconds()),
|
|
28
|
+
logicalCpuCount: cpuInfo.length,
|
|
29
|
+
disk,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function summarizeCpuTimes(cpuInfo) {
|
|
34
|
+
return cpuInfo.reduce((summary, cpu) => {
|
|
35
|
+
const total = cpu.times.user +
|
|
36
|
+
cpu.times.nice +
|
|
37
|
+
cpu.times.sys +
|
|
38
|
+
cpu.times.idle +
|
|
39
|
+
cpu.times.irq;
|
|
40
|
+
return {
|
|
41
|
+
idle: summary.idle + cpu.times.idle,
|
|
42
|
+
total: summary.total + total,
|
|
43
|
+
};
|
|
44
|
+
}, { idle: 0, total: 0 });
|
|
45
|
+
}
|
|
46
|
+
export function calculateCpuPercent(previous, current) {
|
|
47
|
+
if (!previous)
|
|
48
|
+
return null;
|
|
49
|
+
const totalDelta = current.total - previous.total;
|
|
50
|
+
const idleDelta = current.idle - previous.idle;
|
|
51
|
+
if (totalDelta <= 0)
|
|
52
|
+
return null;
|
|
53
|
+
return roundOne(clamp((1 - idleDelta / totalDelta) * 100, 0, 100));
|
|
54
|
+
}
|
|
55
|
+
export async function readDiskUsage(path) {
|
|
56
|
+
const stats = await statfs(path);
|
|
57
|
+
const blockSize = Number(stats.bsize);
|
|
58
|
+
const totalBytes = blockSize * Number(stats.blocks);
|
|
59
|
+
const availableBytes = blockSize * Number(stats.bavail);
|
|
60
|
+
const usedBytes = Math.max(0, totalBytes - blockSize * Number(stats.bfree));
|
|
61
|
+
return {
|
|
62
|
+
path,
|
|
63
|
+
totalBytes,
|
|
64
|
+
usedBytes,
|
|
65
|
+
availableBytes,
|
|
66
|
+
usedPercent: percent(usedBytes, totalBytes),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const defaultHostMetricsReader = {
|
|
70
|
+
cpuInfo: cpus,
|
|
71
|
+
diskUsage: readDiskUsage,
|
|
72
|
+
freeMemoryBytes: freemem,
|
|
73
|
+
loadAverage: () => {
|
|
74
|
+
if (platform() === "win32")
|
|
75
|
+
return null;
|
|
76
|
+
const [one, five, fifteen] = loadavg();
|
|
77
|
+
return [one ?? 0, five ?? 0, fifteen ?? 0];
|
|
78
|
+
},
|
|
79
|
+
totalMemoryBytes: totalmem,
|
|
80
|
+
uptimeSeconds: uptime,
|
|
81
|
+
};
|
|
82
|
+
function percent(value, total) {
|
|
83
|
+
if (total <= 0)
|
|
84
|
+
return 0;
|
|
85
|
+
return roundOne(clamp((value / total) * 100, 0, 100));
|
|
86
|
+
}
|
|
87
|
+
function clamp(value, minimum, maximum) {
|
|
88
|
+
return Math.min(maximum, Math.max(minimum, value));
|
|
89
|
+
}
|
|
90
|
+
function roundOne(value) {
|
|
91
|
+
return Math.round(value * 10) / 10;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=host-metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-metrics.js","sourceRoot":"","sources":["../../src/core/host-metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EACL,IAAI,EACJ,OAAO,EACP,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,GAEP,MAAM,SAAS,CAAC;AAoCjB,MAAM,OAAO,oBAAoB;IAIZ;IACA;IAJX,WAAW,CAAY;IAE/B,YACmB,IAAY,EACZ,SAA4B,wBAAwB;QADpD,SAAI,GAA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KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ProcessManager } from "./process-manager.js";
|
|
2
|
+
import { HostMetricsCollector, type HostMetricSample } from "./host-metrics.js";
|
|
3
|
+
import { type ProcessTreeSummary } from "./process-tree.js";
|
|
2
4
|
export interface MetricSample {
|
|
3
5
|
t: number;
|
|
4
6
|
cpu: number;
|
|
@@ -10,12 +12,32 @@ export interface MetricsSeries {
|
|
|
10
12
|
sampleIntervalMs: number;
|
|
11
13
|
samples: MetricSample[];
|
|
12
14
|
}
|
|
15
|
+
export interface ServiceActivityMetric {
|
|
16
|
+
service: string;
|
|
17
|
+
startedAt?: string;
|
|
18
|
+
sampledAt: number;
|
|
19
|
+
cpuPercent: number;
|
|
20
|
+
rssMb: number;
|
|
21
|
+
processCount: number;
|
|
22
|
+
}
|
|
23
|
+
export interface ActivityMetrics {
|
|
24
|
+
sampleIntervalMs: number;
|
|
25
|
+
host: {
|
|
26
|
+
current: HostMetricSample | null;
|
|
27
|
+
samples: HostMetricSample[];
|
|
28
|
+
};
|
|
29
|
+
services: Record<string, ServiceActivityMetric>;
|
|
30
|
+
}
|
|
13
31
|
export interface MetricsStoreOptions {
|
|
14
32
|
manager: ProcessManager;
|
|
15
33
|
/** Seconds between samples. */
|
|
16
34
|
intervalMs?: number;
|
|
17
35
|
/** Max samples kept per service (ring buffer). */
|
|
18
36
|
capacity?: number;
|
|
37
|
+
cwd?: string;
|
|
38
|
+
hostCollector?: Pick<HostMetricsCollector, "sample">;
|
|
39
|
+
processTreeReader?: (rootPid: number) => Promise<ProcessTreeSummary>;
|
|
40
|
+
now?: () => number;
|
|
19
41
|
}
|
|
20
42
|
/**
|
|
21
43
|
* In-memory CPU/RSS time series for managed services. Polls process trees on a
|
|
@@ -26,12 +48,17 @@ export declare class MetricsStore {
|
|
|
26
48
|
private readonly manager;
|
|
27
49
|
private readonly intervalMs;
|
|
28
50
|
private readonly capacity;
|
|
51
|
+
private readonly hostCollector;
|
|
52
|
+
private readonly processTreeReader;
|
|
53
|
+
private readonly now;
|
|
29
54
|
private readonly buffers;
|
|
55
|
+
private readonly hostSamples;
|
|
30
56
|
private timer?;
|
|
31
57
|
private sampling;
|
|
32
58
|
constructor(options: MetricsStoreOptions);
|
|
33
59
|
start(): void;
|
|
34
60
|
stop(): void;
|
|
35
61
|
read(service: string): MetricsSeries;
|
|
36
|
-
|
|
62
|
+
readActivity(): ActivityMetrics;
|
|
63
|
+
sampleOnce(): Promise<void>;
|
|
37
64
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HostMetricsCollector, } from "./host-metrics.js";
|
|
2
|
+
import { readProcessTree, } from "./process-tree.js";
|
|
2
3
|
/**
|
|
3
4
|
* In-memory CPU/RSS time series for managed services. Polls process trees on a
|
|
4
5
|
* fixed cadence; PIDs that disappear are kept in the buffer so the chart can
|
|
@@ -8,13 +9,21 @@ export class MetricsStore {
|
|
|
8
9
|
manager;
|
|
9
10
|
intervalMs;
|
|
10
11
|
capacity;
|
|
12
|
+
hostCollector;
|
|
13
|
+
processTreeReader;
|
|
14
|
+
now;
|
|
11
15
|
buffers = new Map();
|
|
16
|
+
hostSamples = [];
|
|
12
17
|
timer;
|
|
13
18
|
sampling = false;
|
|
14
19
|
constructor(options) {
|
|
15
20
|
this.manager = options.manager;
|
|
16
21
|
this.intervalMs = options.intervalMs ?? 3000;
|
|
17
22
|
this.capacity = options.capacity ?? 600;
|
|
23
|
+
this.hostCollector =
|
|
24
|
+
options.hostCollector ?? new HostMetricsCollector(options.cwd ?? process.cwd());
|
|
25
|
+
this.processTreeReader = options.processTreeReader ?? readProcessTree;
|
|
26
|
+
this.now = options.now ?? Date.now;
|
|
18
27
|
}
|
|
19
28
|
start() {
|
|
20
29
|
if (this.timer)
|
|
@@ -22,6 +31,7 @@ export class MetricsStore {
|
|
|
22
31
|
this.timer = setInterval(() => void this.sampleOnce(), this.intervalMs);
|
|
23
32
|
if (typeof this.timer.unref === "function")
|
|
24
33
|
this.timer.unref();
|
|
34
|
+
void this.sampleOnce();
|
|
25
35
|
}
|
|
26
36
|
stop() {
|
|
27
37
|
if (this.timer) {
|
|
@@ -38,13 +48,43 @@ export class MetricsStore {
|
|
|
38
48
|
samples: buffer ? [...buffer.samples] : [],
|
|
39
49
|
};
|
|
40
50
|
}
|
|
51
|
+
readActivity() {
|
|
52
|
+
const statuses = this.manager.status().services;
|
|
53
|
+
const services = {};
|
|
54
|
+
const currentHostSample = this.hostSamples.at(-1);
|
|
55
|
+
for (const [name, buffer] of this.buffers) {
|
|
56
|
+
const status = statuses[name];
|
|
57
|
+
if (status?.state !== "running" ||
|
|
58
|
+
!buffer.latest ||
|
|
59
|
+
buffer.startedAt !== status.startedAt) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
services[name] = {
|
|
63
|
+
service: name,
|
|
64
|
+
startedAt: buffer.startedAt,
|
|
65
|
+
sampledAt: buffer.latest.sampledAt,
|
|
66
|
+
cpuPercent: buffer.latest.tree.cpuPercent,
|
|
67
|
+
rssMb: buffer.latest.tree.rssMb,
|
|
68
|
+
processCount: buffer.latest.tree.processCount,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
sampleIntervalMs: this.intervalMs,
|
|
73
|
+
host: {
|
|
74
|
+
current: currentHostSample ? cloneHostSample(currentHostSample) : null,
|
|
75
|
+
samples: this.hostSamples.map(cloneHostSample),
|
|
76
|
+
},
|
|
77
|
+
services,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
41
80
|
async sampleOnce() {
|
|
42
81
|
if (this.sampling)
|
|
43
82
|
return;
|
|
44
83
|
this.sampling = true;
|
|
45
84
|
try {
|
|
46
85
|
const { services } = this.manager.status();
|
|
47
|
-
const now =
|
|
86
|
+
const now = this.now();
|
|
87
|
+
const hostSample = this.hostCollector.sample(now).catch(() => undefined);
|
|
48
88
|
await Promise.all(Object.values(services).map(async (status) => {
|
|
49
89
|
if (status.state !== "running" || !status.pid)
|
|
50
90
|
return;
|
|
@@ -55,8 +95,9 @@ export class MetricsStore {
|
|
|
55
95
|
this.buffers.set(status.name, buffer);
|
|
56
96
|
}
|
|
57
97
|
try {
|
|
58
|
-
const tree = await
|
|
98
|
+
const tree = await this.processTreeReader(status.pid);
|
|
59
99
|
buffer.samples.push({ t: now, cpu: tree.cpuPercent, rss: tree.rssMb });
|
|
100
|
+
buffer.latest = { sampledAt: now, tree };
|
|
60
101
|
if (buffer.samples.length > this.capacity) {
|
|
61
102
|
buffer.samples.splice(0, buffer.samples.length - this.capacity);
|
|
62
103
|
}
|
|
@@ -65,10 +106,24 @@ export class MetricsStore {
|
|
|
65
106
|
// ps may briefly fail right after spawn / during exit — skip this tick.
|
|
66
107
|
}
|
|
67
108
|
}));
|
|
109
|
+
const nextHostSample = await hostSample;
|
|
110
|
+
if (nextHostSample) {
|
|
111
|
+
this.hostSamples.push(nextHostSample);
|
|
112
|
+
if (this.hostSamples.length > this.capacity) {
|
|
113
|
+
this.hostSamples.splice(0, this.hostSamples.length - this.capacity);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
68
116
|
}
|
|
69
117
|
finally {
|
|
70
118
|
this.sampling = false;
|
|
71
119
|
}
|
|
72
120
|
}
|
|
73
121
|
}
|
|
122
|
+
function cloneHostSample(sample) {
|
|
123
|
+
return {
|
|
124
|
+
...sample,
|
|
125
|
+
loadAverage: sample.loadAverage ? [...sample.loadAverage] : null,
|
|
126
|
+
disk: sample.disk ? { ...sample.disk } : null,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
74
129
|
//# sourceMappingURL=metrics-store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics-store.js","sourceRoot":"","sources":["../../src/core/metrics-store.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"metrics-store.js","sourceRoot":"","sources":["../../src/core/met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