@ceon-oy/monitor-sdk 1.5.0 → 1.5.2

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/index.d.mts CHANGED
@@ -217,6 +217,7 @@ declare class MonitorClient {
217
217
  private lastScanTime;
218
218
  private lastKnownScanRequestedAt;
219
219
  private lastKnownTechScanRequestedAt;
220
+ private currentAuditIntervalHours;
220
221
  private versionCheckEnabled;
221
222
  private auditTimeoutMs;
222
223
  private registryTimeoutMs;
@@ -269,6 +270,7 @@ declare class MonitorClient {
269
270
  private startSdkErrorFlushTimer;
270
271
  private stopSdkErrorFlushTimer;
271
272
  private flushSdkErrors;
273
+ private clearAuditIntervalTimer;
272
274
  private stopAuditIntervalTimer;
273
275
  /**
274
276
  * Fetch project settings from the monitoring server.
@@ -292,6 +294,12 @@ declare class MonitorClient {
292
294
  * Also sets up polling for on-demand scan requests from the server.
293
295
  */
294
296
  private setupAutoAudit;
297
+ /**
298
+ * (Re)configure the recurring audit timer for the given interval, replacing
299
+ * whichever timer is currently running (if any). intervalHours <= 0 leaves
300
+ * scanning disabled.
301
+ */
302
+ private setAuditInterval;
295
303
  /**
296
304
  * Run a vulnerability scan and track the time it was run.
297
305
  * Uses auditMultiplePaths() if auditPaths is configured, otherwise runs single audit.
@@ -512,7 +520,8 @@ declare class MonitorClient {
512
520
  /**
513
521
  * Measure CPU utilization by sampling cpus() twice with a 3s gap.
514
522
  * The cumulative counters make this the average utilization over the
515
- * window, across all cores of the host. Returns a percentage (0–100).
523
+ * window, across all cores of the host. Returns a percentage (0–100)
524
+ * plus the CPU model, read off the same samples at zero extra cost.
516
525
  */
517
526
  private measureCpuPercent;
518
527
  /**
@@ -531,6 +540,7 @@ declare class MonitorClient {
531
540
  submitSystemMetric(metric: {
532
541
  hostname: string;
533
542
  cpuPercent: number;
543
+ cpuModel?: string | null;
534
544
  memoryTotal: number;
535
545
  memoryUsed: number;
536
546
  memoryPercent: number;
package/dist/index.d.ts CHANGED
@@ -217,6 +217,7 @@ declare class MonitorClient {
217
217
  private lastScanTime;
218
218
  private lastKnownScanRequestedAt;
219
219
  private lastKnownTechScanRequestedAt;
220
+ private currentAuditIntervalHours;
220
221
  private versionCheckEnabled;
221
222
  private auditTimeoutMs;
222
223
  private registryTimeoutMs;
@@ -269,6 +270,7 @@ declare class MonitorClient {
269
270
  private startSdkErrorFlushTimer;
270
271
  private stopSdkErrorFlushTimer;
271
272
  private flushSdkErrors;
273
+ private clearAuditIntervalTimer;
272
274
  private stopAuditIntervalTimer;
273
275
  /**
274
276
  * Fetch project settings from the monitoring server.
@@ -292,6 +294,12 @@ declare class MonitorClient {
292
294
  * Also sets up polling for on-demand scan requests from the server.
293
295
  */
294
296
  private setupAutoAudit;
297
+ /**
298
+ * (Re)configure the recurring audit timer for the given interval, replacing
299
+ * whichever timer is currently running (if any). intervalHours <= 0 leaves
300
+ * scanning disabled.
301
+ */
302
+ private setAuditInterval;
295
303
  /**
296
304
  * Run a vulnerability scan and track the time it was run.
297
305
  * Uses auditMultiplePaths() if auditPaths is configured, otherwise runs single audit.
@@ -512,7 +520,8 @@ declare class MonitorClient {
512
520
  /**
513
521
  * Measure CPU utilization by sampling cpus() twice with a 3s gap.
514
522
  * The cumulative counters make this the average utilization over the
515
- * window, across all cores of the host. Returns a percentage (0–100).
523
+ * window, across all cores of the host. Returns a percentage (0–100)
524
+ * plus the CPU model, read off the same samples at zero extra cost.
516
525
  */
517
526
  private measureCpuPercent;
518
527
  /**
@@ -531,6 +540,7 @@ declare class MonitorClient {
531
540
  submitSystemMetric(metric: {
532
541
  hostname: string;
533
542
  cpuPercent: number;
543
+ cpuModel?: string | null;
534
544
  memoryTotal: number;
535
545
  memoryUsed: number;
536
546
  memoryPercent: number;
package/dist/index.js CHANGED
@@ -90,6 +90,9 @@ var MonitorClient = class {
90
90
  this.lastScanTime = null;
91
91
  this.lastKnownScanRequestedAt = null;
92
92
  this.lastKnownTechScanRequestedAt = null;
93
+ // Interval (in hours) the currently-running auditIntervalTimer was configured with,
94
+ // so checkForScanRequest() can detect server-side changes and reconfigure it.
95
+ this.currentAuditIntervalHours = null;
93
96
  this.healthCheckFetchTimer = null;
94
97
  this.healthCheckTimers = /* @__PURE__ */ new Map();
95
98
  this.healthCheckResultsQueue = [];
@@ -393,11 +396,14 @@ var MonitorClient = class {
393
396
  console.warn("[MonitorClient] Failed to flush SDK errors to server:", err instanceof Error ? err.message : String(err));
394
397
  }
395
398
  }
396
- stopAuditIntervalTimer() {
399
+ clearAuditIntervalTimer() {
397
400
  if (this.auditIntervalTimer) {
398
401
  clearInterval(this.auditIntervalTimer);
399
402
  this.auditIntervalTimer = null;
400
403
  }
404
+ }
405
+ stopAuditIntervalTimer() {
406
+ this.clearAuditIntervalTimer();
401
407
  if (this.settingsPollingTimer) {
402
408
  clearInterval(this.settingsPollingTimer);
403
409
  this.settingsPollingTimer = null;
@@ -447,15 +453,11 @@ var MonitorClient = class {
447
453
  const intervalHours = settings.vulnerabilityScanIntervalHours;
448
454
  if (intervalHours <= 0) {
449
455
  console.log("[MonitorClient] Scheduled vulnerability scanning disabled by server configuration");
456
+ this.currentAuditIntervalHours = intervalHours;
450
457
  } else {
451
458
  console.log(`[MonitorClient] Auto vulnerability scanning enabled (every ${intervalHours} hours)`);
452
459
  await this.runScanAndTrackTime();
453
- const intervalMs = intervalHours * 60 * 60 * 1e3;
454
- this.auditIntervalTimer = setInterval(() => {
455
- this.runScanAndTrackTime().catch((err) => {
456
- this.reportError("AUDIT_SCAN", "Auto audit scan failed", err);
457
- });
458
- }, intervalMs);
460
+ this.setAuditInterval(intervalHours);
459
461
  }
460
462
  console.log("[MonitorClient] Polling for scan requests enabled (every 5 minutes)");
461
463
  this.settingsPollingTimer = setInterval(() => {
@@ -464,6 +466,24 @@ var MonitorClient = class {
464
466
  });
465
467
  }, CONFIG_LIMITS.SETTINGS_POLL_INTERVAL_MS);
466
468
  }
469
+ /**
470
+ * (Re)configure the recurring audit timer for the given interval, replacing
471
+ * whichever timer is currently running (if any). intervalHours <= 0 leaves
472
+ * scanning disabled.
473
+ */
474
+ setAuditInterval(intervalHours) {
475
+ this.clearAuditIntervalTimer();
476
+ this.currentAuditIntervalHours = intervalHours;
477
+ if (intervalHours <= 0) {
478
+ return;
479
+ }
480
+ const intervalMs = intervalHours * 60 * 60 * 1e3;
481
+ this.auditIntervalTimer = setInterval(() => {
482
+ this.runScanAndTrackTime().catch((err) => {
483
+ this.reportError("AUDIT_SCAN", "Auto audit scan failed", err);
484
+ });
485
+ }, intervalMs);
486
+ }
467
487
  /**
468
488
  * Run a vulnerability scan and track the time it was run.
469
489
  * Uses auditMultiplePaths() if auditPaths is configured, otherwise runs single audit.
@@ -507,6 +527,12 @@ var MonitorClient = class {
507
527
  await this.syncDependencies();
508
528
  }
509
529
  }
530
+ if (settings.vulnerabilityScanIntervalHours !== this.currentAuditIntervalHours) {
531
+ console.log(
532
+ `[MonitorClient] Auto scan interval changed (${this.currentAuditIntervalHours ?? "unset"} \u2192 ${settings.vulnerabilityScanIntervalHours} hours), reconfiguring`
533
+ );
534
+ this.setAuditInterval(settings.vulnerabilityScanIntervalHours);
535
+ }
510
536
  } catch (err) {
511
537
  this.reportError("SETTINGS_POLL", "Failed to check for scan request", err);
512
538
  }
@@ -959,7 +985,7 @@ var MonitorClient = class {
959
985
  "child_process"
960
986
  );
961
987
  const { spawn } = childProcess;
962
- return new Promise((resolve) => {
988
+ return new Promise((resolve, reject) => {
963
989
  const proc = spawn(command, args, {
964
990
  cwd: options.cwd,
965
991
  stdio: ["pipe", "pipe", "pipe"],
@@ -968,10 +994,8 @@ var MonitorClient = class {
968
994
  let stdout = "";
969
995
  let stderr = "";
970
996
  let timedOut = false;
971
- let killed = false;
972
997
  const timeoutId = setTimeout(() => {
973
998
  timedOut = true;
974
- killed = true;
975
999
  proc.kill("SIGTERM");
976
1000
  setTimeout(() => {
977
1001
  if (!proc.killed) {
@@ -993,9 +1017,9 @@ var MonitorClient = class {
993
1017
  clearTimeout(timeoutId);
994
1018
  resolve({ stdout, timedOut });
995
1019
  });
996
- proc.on("error", () => {
1020
+ proc.on("error", (err) => {
997
1021
  clearTimeout(timeoutId);
998
- resolve({ stdout, timedOut: killed });
1022
+ reject(err);
999
1023
  });
1000
1024
  });
1001
1025
  }
@@ -1594,7 +1618,7 @@ var MonitorClient = class {
1594
1618
  }
1595
1619
  try {
1596
1620
  const hostname = os.hostname();
1597
- const cpuPercent = await this.measureCpuPercent(os);
1621
+ const { percent: cpuPercent, model: cpuModel } = await this.measureCpuPercent(os);
1598
1622
  const memoryTotal = os.totalmem();
1599
1623
  const memoryAvailable = await this.getAvailableMemoryBytes(os, fs);
1600
1624
  const memoryUsed = memoryTotal - memoryAvailable;
@@ -1603,6 +1627,7 @@ var MonitorClient = class {
1603
1627
  await this.submitSystemMetric({
1604
1628
  hostname,
1605
1629
  cpuPercent,
1630
+ cpuModel,
1606
1631
  memoryTotal,
1607
1632
  memoryUsed,
1608
1633
  memoryPercent,
@@ -1615,12 +1640,14 @@ var MonitorClient = class {
1615
1640
  /**
1616
1641
  * Measure CPU utilization by sampling cpus() twice with a 3s gap.
1617
1642
  * The cumulative counters make this the average utilization over the
1618
- * window, across all cores of the host. Returns a percentage (0–100).
1643
+ * window, across all cores of the host. Returns a percentage (0–100)
1644
+ * plus the CPU model, read off the same samples at zero extra cost.
1619
1645
  */
1620
1646
  async measureCpuPercent(os) {
1621
1647
  const sample1 = os.cpus();
1622
1648
  await new Promise((resolve) => setTimeout(resolve, 3e3));
1623
1649
  const sample2 = os.cpus();
1650
+ const model = sample1[0]?.model ?? null;
1624
1651
  let totalIdle = 0;
1625
1652
  let totalTick = 0;
1626
1653
  for (let i = 0; i < sample2.length; i++) {
@@ -1632,10 +1659,10 @@ var MonitorClient = class {
1632
1659
  totalIdle += curr.times.idle - prev.times.idle;
1633
1660
  }
1634
1661
  if (totalTick <= 0) {
1635
- return 0;
1662
+ return { percent: 0, model };
1636
1663
  }
1637
1664
  const idlePercent = totalIdle / totalTick * 100;
1638
- return Math.max(0, Math.min(100, 100 - idlePercent));
1665
+ return { percent: Math.max(0, Math.min(100, 100 - idlePercent)), model };
1639
1666
  }
1640
1667
  /**
1641
1668
  * Get reclaimable memory in bytes. On Linux, reads MemAvailable from
package/dist/index.mjs CHANGED
@@ -54,6 +54,9 @@ var MonitorClient = class {
54
54
  this.lastScanTime = null;
55
55
  this.lastKnownScanRequestedAt = null;
56
56
  this.lastKnownTechScanRequestedAt = null;
57
+ // Interval (in hours) the currently-running auditIntervalTimer was configured with,
58
+ // so checkForScanRequest() can detect server-side changes and reconfigure it.
59
+ this.currentAuditIntervalHours = null;
57
60
  this.healthCheckFetchTimer = null;
58
61
  this.healthCheckTimers = /* @__PURE__ */ new Map();
59
62
  this.healthCheckResultsQueue = [];
@@ -357,11 +360,14 @@ var MonitorClient = class {
357
360
  console.warn("[MonitorClient] Failed to flush SDK errors to server:", err instanceof Error ? err.message : String(err));
358
361
  }
359
362
  }
360
- stopAuditIntervalTimer() {
363
+ clearAuditIntervalTimer() {
361
364
  if (this.auditIntervalTimer) {
362
365
  clearInterval(this.auditIntervalTimer);
363
366
  this.auditIntervalTimer = null;
364
367
  }
368
+ }
369
+ stopAuditIntervalTimer() {
370
+ this.clearAuditIntervalTimer();
365
371
  if (this.settingsPollingTimer) {
366
372
  clearInterval(this.settingsPollingTimer);
367
373
  this.settingsPollingTimer = null;
@@ -411,15 +417,11 @@ var MonitorClient = class {
411
417
  const intervalHours = settings.vulnerabilityScanIntervalHours;
412
418
  if (intervalHours <= 0) {
413
419
  console.log("[MonitorClient] Scheduled vulnerability scanning disabled by server configuration");
420
+ this.currentAuditIntervalHours = intervalHours;
414
421
  } else {
415
422
  console.log(`[MonitorClient] Auto vulnerability scanning enabled (every ${intervalHours} hours)`);
416
423
  await this.runScanAndTrackTime();
417
- const intervalMs = intervalHours * 60 * 60 * 1e3;
418
- this.auditIntervalTimer = setInterval(() => {
419
- this.runScanAndTrackTime().catch((err) => {
420
- this.reportError("AUDIT_SCAN", "Auto audit scan failed", err);
421
- });
422
- }, intervalMs);
424
+ this.setAuditInterval(intervalHours);
423
425
  }
424
426
  console.log("[MonitorClient] Polling for scan requests enabled (every 5 minutes)");
425
427
  this.settingsPollingTimer = setInterval(() => {
@@ -428,6 +430,24 @@ var MonitorClient = class {
428
430
  });
429
431
  }, CONFIG_LIMITS.SETTINGS_POLL_INTERVAL_MS);
430
432
  }
433
+ /**
434
+ * (Re)configure the recurring audit timer for the given interval, replacing
435
+ * whichever timer is currently running (if any). intervalHours <= 0 leaves
436
+ * scanning disabled.
437
+ */
438
+ setAuditInterval(intervalHours) {
439
+ this.clearAuditIntervalTimer();
440
+ this.currentAuditIntervalHours = intervalHours;
441
+ if (intervalHours <= 0) {
442
+ return;
443
+ }
444
+ const intervalMs = intervalHours * 60 * 60 * 1e3;
445
+ this.auditIntervalTimer = setInterval(() => {
446
+ this.runScanAndTrackTime().catch((err) => {
447
+ this.reportError("AUDIT_SCAN", "Auto audit scan failed", err);
448
+ });
449
+ }, intervalMs);
450
+ }
431
451
  /**
432
452
  * Run a vulnerability scan and track the time it was run.
433
453
  * Uses auditMultiplePaths() if auditPaths is configured, otherwise runs single audit.
@@ -471,6 +491,12 @@ var MonitorClient = class {
471
491
  await this.syncDependencies();
472
492
  }
473
493
  }
494
+ if (settings.vulnerabilityScanIntervalHours !== this.currentAuditIntervalHours) {
495
+ console.log(
496
+ `[MonitorClient] Auto scan interval changed (${this.currentAuditIntervalHours ?? "unset"} \u2192 ${settings.vulnerabilityScanIntervalHours} hours), reconfiguring`
497
+ );
498
+ this.setAuditInterval(settings.vulnerabilityScanIntervalHours);
499
+ }
474
500
  } catch (err) {
475
501
  this.reportError("SETTINGS_POLL", "Failed to check for scan request", err);
476
502
  }
@@ -923,7 +949,7 @@ var MonitorClient = class {
923
949
  "child_process"
924
950
  );
925
951
  const { spawn } = childProcess;
926
- return new Promise((resolve) => {
952
+ return new Promise((resolve, reject) => {
927
953
  const proc = spawn(command, args, {
928
954
  cwd: options.cwd,
929
955
  stdio: ["pipe", "pipe", "pipe"],
@@ -932,10 +958,8 @@ var MonitorClient = class {
932
958
  let stdout = "";
933
959
  let stderr = "";
934
960
  let timedOut = false;
935
- let killed = false;
936
961
  const timeoutId = setTimeout(() => {
937
962
  timedOut = true;
938
- killed = true;
939
963
  proc.kill("SIGTERM");
940
964
  setTimeout(() => {
941
965
  if (!proc.killed) {
@@ -957,9 +981,9 @@ var MonitorClient = class {
957
981
  clearTimeout(timeoutId);
958
982
  resolve({ stdout, timedOut });
959
983
  });
960
- proc.on("error", () => {
984
+ proc.on("error", (err) => {
961
985
  clearTimeout(timeoutId);
962
- resolve({ stdout, timedOut: killed });
986
+ reject(err);
963
987
  });
964
988
  });
965
989
  }
@@ -1558,7 +1582,7 @@ var MonitorClient = class {
1558
1582
  }
1559
1583
  try {
1560
1584
  const hostname = os.hostname();
1561
- const cpuPercent = await this.measureCpuPercent(os);
1585
+ const { percent: cpuPercent, model: cpuModel } = await this.measureCpuPercent(os);
1562
1586
  const memoryTotal = os.totalmem();
1563
1587
  const memoryAvailable = await this.getAvailableMemoryBytes(os, fs);
1564
1588
  const memoryUsed = memoryTotal - memoryAvailable;
@@ -1567,6 +1591,7 @@ var MonitorClient = class {
1567
1591
  await this.submitSystemMetric({
1568
1592
  hostname,
1569
1593
  cpuPercent,
1594
+ cpuModel,
1570
1595
  memoryTotal,
1571
1596
  memoryUsed,
1572
1597
  memoryPercent,
@@ -1579,12 +1604,14 @@ var MonitorClient = class {
1579
1604
  /**
1580
1605
  * Measure CPU utilization by sampling cpus() twice with a 3s gap.
1581
1606
  * The cumulative counters make this the average utilization over the
1582
- * window, across all cores of the host. Returns a percentage (0–100).
1607
+ * window, across all cores of the host. Returns a percentage (0–100)
1608
+ * plus the CPU model, read off the same samples at zero extra cost.
1583
1609
  */
1584
1610
  async measureCpuPercent(os) {
1585
1611
  const sample1 = os.cpus();
1586
1612
  await new Promise((resolve) => setTimeout(resolve, 3e3));
1587
1613
  const sample2 = os.cpus();
1614
+ const model = sample1[0]?.model ?? null;
1588
1615
  let totalIdle = 0;
1589
1616
  let totalTick = 0;
1590
1617
  for (let i = 0; i < sample2.length; i++) {
@@ -1596,10 +1623,10 @@ var MonitorClient = class {
1596
1623
  totalIdle += curr.times.idle - prev.times.idle;
1597
1624
  }
1598
1625
  if (totalTick <= 0) {
1599
- return 0;
1626
+ return { percent: 0, model };
1600
1627
  }
1601
1628
  const idlePercent = totalIdle / totalTick * 100;
1602
- return Math.max(0, Math.min(100, 100 - idlePercent));
1629
+ return { percent: Math.max(0, Math.min(100, 100 - idlePercent)), model };
1603
1630
  }
1604
1631
  /**
1605
1632
  * Get reclaimable memory in bytes. On Linux, reads MemAvailable from
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ceon-oy/monitor-sdk",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "Client SDK for Ceon Monitor - Error tracking, health monitoring, security events, and vulnerability scanning",
5
5
  "author": "Ceon",
6
6
  "license": "MIT",