@livedesk/client 0.1.14 → 0.1.15
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/bin/livedesk-client-node.js +46 -3
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ import net from 'net';
|
|
|
4
4
|
import os from 'os';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import crypto from 'crypto';
|
|
7
|
-
import { promises as fs } from 'fs';
|
|
7
|
+
import { promises as fs, statfsSync } from 'fs';
|
|
8
8
|
|
|
9
9
|
const AGENT_VERSION = '0.1.15-livedesk.1';
|
|
10
10
|
const DEFAULT_MANAGER = '127.0.0.1:5197';
|
|
@@ -230,17 +230,60 @@ async function getDeviceId(explicitDeviceId = '') {
|
|
|
230
230
|
return deviceId;
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
+
function getRootDiskStatus() {
|
|
234
|
+
const root = path.parse(os.homedir()).root || '/';
|
|
235
|
+
try {
|
|
236
|
+
const stats = statfsSync(root);
|
|
237
|
+
const totalBytes = Number(stats.blocks) * Number(stats.bsize);
|
|
238
|
+
const freeBytes = Number(stats.bavail) * Number(stats.bsize);
|
|
239
|
+
return {
|
|
240
|
+
root,
|
|
241
|
+
totalBytes,
|
|
242
|
+
freeBytes,
|
|
243
|
+
usedRatio: totalBytes > 0 ? Number(((totalBytes - freeBytes) / totalBytes).toFixed(4)) : 0
|
|
244
|
+
};
|
|
245
|
+
} catch {
|
|
246
|
+
return { root, totalBytes: 0, freeBytes: 0, usedRatio: 0 };
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
233
250
|
function getStatus(options = {}) {
|
|
234
251
|
const totalMem = os.totalmem();
|
|
235
252
|
const freeMem = os.freemem();
|
|
253
|
+
const cpus = os.cpus();
|
|
254
|
+
const loadavg = os.loadavg();
|
|
255
|
+
const cpuCores = Math.max(1, cpus.length || os.availableParallelism?.() || 1);
|
|
256
|
+
const cpuUsageRatio = loadavg[0] > 0
|
|
257
|
+
? Number(Math.min(1, loadavg[0] / cpuCores).toFixed(4))
|
|
258
|
+
: 0;
|
|
259
|
+
const usedMemRatio = totalMem > 0 ? Number(((totalMem - freeMem) / totalMem).toFixed(4)) : 0;
|
|
236
260
|
const status = {
|
|
237
261
|
uptimeSec: Math.round(os.uptime()),
|
|
238
|
-
loadavg
|
|
262
|
+
loadavg,
|
|
239
263
|
totalMem,
|
|
240
264
|
freeMem,
|
|
241
|
-
usedMemRatio
|
|
265
|
+
usedMemRatio,
|
|
242
266
|
platform: os.platform(),
|
|
243
267
|
release: os.release(),
|
|
268
|
+
role: options.aiEnabled ? 'Agent worker' : options.taskEnabled ? 'Task worker' : 'Local machine',
|
|
269
|
+
cpu: {
|
|
270
|
+
cores: cpuCores,
|
|
271
|
+
model: cpus[0]?.model || '',
|
|
272
|
+
speedMHz: cpus[0]?.speed || 0,
|
|
273
|
+
usageRatio: cpuUsageRatio,
|
|
274
|
+
load1: loadavg[0] || 0
|
|
275
|
+
},
|
|
276
|
+
memory: {
|
|
277
|
+
totalBytes: totalMem,
|
|
278
|
+
freeBytes: freeMem,
|
|
279
|
+
usedRatio: usedMemRatio
|
|
280
|
+
},
|
|
281
|
+
disk: getRootDiskStatus(),
|
|
282
|
+
workload: {
|
|
283
|
+
role: options.aiEnabled ? 'Agent worker' : options.taskEnabled ? 'Task worker' : 'Local machine',
|
|
284
|
+
status: 'idle',
|
|
285
|
+
title: 'idle'
|
|
286
|
+
},
|
|
244
287
|
timestamp: new Date().toISOString()
|
|
245
288
|
};
|
|
246
289
|
if (options.slotNumber) {
|