bm2 1.0.23 → 1.0.24
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/package.json +3 -1
- package/src/process-container.ts +31 -33
- package/src/process-table.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bm2",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.24",
|
|
4
4
|
"description": "A blazing-fast, full-featured process manager built entirely on Bun native APIs. The modern PM2 replacement — zero Node.js dependencies, pure Bun performance.",
|
|
5
5
|
"main": "src/api.ts",
|
|
6
6
|
"module": "src/api.ts",
|
|
@@ -65,10 +65,12 @@
|
|
|
65
65
|
],
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"cli-table3": "^0.6.5",
|
|
68
|
+
"pidusage": "^4.0.1",
|
|
68
69
|
"ws": "^8.19.0"
|
|
69
70
|
},
|
|
70
71
|
"devDependencies": {
|
|
71
72
|
"@types/bun": "^1.3.9",
|
|
73
|
+
"@types/pidusage": "^2.0.5",
|
|
72
74
|
"@types/ws": "^8.18.1",
|
|
73
75
|
"bun-types": "latest",
|
|
74
76
|
"typescript": "^5.9.3"
|
package/src/process-container.ts
CHANGED
|
@@ -32,6 +32,9 @@ import {
|
|
|
32
32
|
DEFAULT_LOG_MAX_SIZE,
|
|
33
33
|
DEFAULT_LOG_RETAIN,
|
|
34
34
|
} from "./constants";
|
|
35
|
+
import pidusage from "pidusage";
|
|
36
|
+
import { readdir } from "node:fs/promises";
|
|
37
|
+
|
|
35
38
|
|
|
36
39
|
export class ProcessContainer {
|
|
37
40
|
public id: number;
|
|
@@ -238,42 +241,37 @@ export class ProcessContainer {
|
|
|
238
241
|
} catch {}
|
|
239
242
|
}
|
|
240
243
|
|
|
244
|
+
|
|
241
245
|
private startMonitoring() {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
246
|
+
this.monitorInterval = setInterval(async () => {
|
|
247
|
+
|
|
248
|
+
if (!this.pid || this.status !== "online") return;
|
|
249
|
+
|
|
250
|
+
try {
|
|
251
|
+
|
|
252
|
+
// 1. Fetch cross-platform CPU and Memory usage
|
|
253
|
+
const stats = await pidusage(this.pid);
|
|
254
|
+
|
|
255
|
+
// pidusage returns memory directly in bytes and cpu as a percentage
|
|
256
|
+
this.memory = stats.memory;
|
|
257
|
+
this.cpu = stats.cpu;
|
|
258
|
+
|
|
259
|
+
// 2. Track file descriptors (handles) on Linux
|
|
260
|
+
// (pidusage does not provide this metric, so we keep the original logic)
|
|
261
|
+
if (process.platform === "linux") {
|
|
262
|
+
try {
|
|
263
|
+
this.handles = (await readdir(`/proc/${this.pid}/fd`)).length;
|
|
264
|
+
} catch {}
|
|
252
265
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
this.
|
|
257
|
-
|
|
258
|
-
} else {
|
|
259
|
-
const ps = Bun.spawn(["ps", "-o", "rss=,pcpu=", "-p", String(this.pid)], {
|
|
260
|
-
stdout: "pipe", stderr: "pipe",
|
|
261
|
-
});
|
|
262
|
-
const output = await new Response(ps.stdout).text();
|
|
263
|
-
const parts = output.trim().split(/\s+/);
|
|
264
|
-
if (parts.length >= 2) {
|
|
265
|
-
this.memory = parseInt(parts[0]!) * 1024;
|
|
266
|
-
this.cpu = parseFloat(parts[1]!);
|
|
266
|
+
|
|
267
|
+
// 3. Max memory restart
|
|
268
|
+
if (this.config.maxMemoryRestart && this.memory > this.config.maxMemoryRestart) {
|
|
269
|
+
console.log(`[bm2] ${this.name} exceeded memory limit (${this.memory} > ${this.config.maxMemoryRestart}), restarting...`);
|
|
270
|
+
await this.restart();
|
|
267
271
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
if (this.config.maxMemoryRestart && this.memory > this.config.maxMemoryRestart) {
|
|
272
|
-
console.log(`[bm2] ${this.name} exceeded memory limit (${this.memory} > ${this.config.maxMemoryRestart}), restarting...`);
|
|
273
|
-
await this.restart();
|
|
274
|
-
}
|
|
275
|
-
} catch {}
|
|
276
|
-
}, MONITOR_INTERVAL);
|
|
272
|
+
|
|
273
|
+
} catch {}
|
|
274
|
+
}, MONITOR_INTERVAL);
|
|
277
275
|
}
|
|
278
276
|
|
|
279
277
|
private startLogRotation(logPaths: { outFile: string; errFile: string }) {
|
package/src/process-table.ts
CHANGED
|
@@ -106,6 +106,8 @@ export function printProcessTable(processes: ProcessState[]) {
|
|
|
106
106
|
style: { border: ["dim"] },
|
|
107
107
|
chars: minimalBorders(),
|
|
108
108
|
});
|
|
109
|
+
|
|
110
|
+
//console.log("processes===>", processes)
|
|
109
111
|
|
|
110
112
|
for (const p of processes) {
|
|
111
113
|
const cpu = p.monit?.cpu ?? 0;
|
|
@@ -158,6 +160,7 @@ export function liveWatchProcess(processes: ProcessState[], interval = 5_000) {
|
|
|
158
160
|
// Render table
|
|
159
161
|
const render = () => {
|
|
160
162
|
clear();
|
|
163
|
+
|
|
161
164
|
printProcessTable(getSortedProcesses());
|
|
162
165
|
|
|
163
166
|
console.log(color("─".repeat(50), "dim"));
|