@ceon-oy/monitor-sdk 1.4.2 → 1.5.1
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 +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +29 -7
- package/dist/index.mjs +29 -7
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -505,15 +505,22 @@ declare class MonitorClient {
|
|
|
505
505
|
* Collect system metrics (CPU, RAM, disk) using built-in Node.js modules
|
|
506
506
|
* and submit to the monitoring server.
|
|
507
507
|
*
|
|
508
|
-
* Uses: os.cpus(), os.totalmem(), os.freemem(), os.hostname(), fs.statfs()
|
|
508
|
+
* Uses: os.cpus(), os.totalmem(), /proc/meminfo (or os.freemem()), os.hostname(), fs.statfs()
|
|
509
509
|
* Zero dependencies — all built-in Node.js 18.15+
|
|
510
510
|
*/
|
|
511
511
|
private collectAndSubmitMetrics;
|
|
512
512
|
/**
|
|
513
|
-
* Measure CPU utilization by sampling cpus() twice with a
|
|
514
|
-
*
|
|
513
|
+
* Measure CPU utilization by sampling cpus() twice with a 3s gap.
|
|
514
|
+
* The cumulative counters make this the average utilization over the
|
|
515
|
+
* window, across all cores of the host. Returns a percentage (0–100).
|
|
515
516
|
*/
|
|
516
517
|
private measureCpuPercent;
|
|
518
|
+
/**
|
|
519
|
+
* Get reclaimable memory in bytes. On Linux, reads MemAvailable from
|
|
520
|
+
* /proc/meminfo so buffers/cache are not counted as used; falls back to
|
|
521
|
+
* os.freemem() (MemFree) on other platforms or if parsing fails.
|
|
522
|
+
*/
|
|
523
|
+
private getAvailableMemoryBytes;
|
|
517
524
|
/**
|
|
518
525
|
* Collect disk usage for each configured path using fs.statfs() (Node 18.15+).
|
|
519
526
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -505,15 +505,22 @@ declare class MonitorClient {
|
|
|
505
505
|
* Collect system metrics (CPU, RAM, disk) using built-in Node.js modules
|
|
506
506
|
* and submit to the monitoring server.
|
|
507
507
|
*
|
|
508
|
-
* Uses: os.cpus(), os.totalmem(), os.freemem(), os.hostname(), fs.statfs()
|
|
508
|
+
* Uses: os.cpus(), os.totalmem(), /proc/meminfo (or os.freemem()), os.hostname(), fs.statfs()
|
|
509
509
|
* Zero dependencies — all built-in Node.js 18.15+
|
|
510
510
|
*/
|
|
511
511
|
private collectAndSubmitMetrics;
|
|
512
512
|
/**
|
|
513
|
-
* Measure CPU utilization by sampling cpus() twice with a
|
|
514
|
-
*
|
|
513
|
+
* Measure CPU utilization by sampling cpus() twice with a 3s gap.
|
|
514
|
+
* The cumulative counters make this the average utilization over the
|
|
515
|
+
* window, across all cores of the host. Returns a percentage (0–100).
|
|
515
516
|
*/
|
|
516
517
|
private measureCpuPercent;
|
|
518
|
+
/**
|
|
519
|
+
* Get reclaimable memory in bytes. On Linux, reads MemAvailable from
|
|
520
|
+
* /proc/meminfo so buffers/cache are not counted as used; falls back to
|
|
521
|
+
* os.freemem() (MemFree) on other platforms or if parsing fails.
|
|
522
|
+
*/
|
|
523
|
+
private getAvailableMemoryBytes;
|
|
517
524
|
/**
|
|
518
525
|
* Collect disk usage for each configured path using fs.statfs() (Node 18.15+).
|
|
519
526
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1568,7 +1568,7 @@ var MonitorClient = class {
|
|
|
1568
1568
|
* Collect system metrics (CPU, RAM, disk) using built-in Node.js modules
|
|
1569
1569
|
* and submit to the monitoring server.
|
|
1570
1570
|
*
|
|
1571
|
-
* Uses: os.cpus(), os.totalmem(), os.freemem(), os.hostname(), fs.statfs()
|
|
1571
|
+
* Uses: os.cpus(), os.totalmem(), /proc/meminfo (or os.freemem()), os.hostname(), fs.statfs()
|
|
1572
1572
|
* Zero dependencies — all built-in Node.js 18.15+
|
|
1573
1573
|
*/
|
|
1574
1574
|
async collectAndSubmitMetrics(diskPaths) {
|
|
@@ -1596,8 +1596,8 @@ var MonitorClient = class {
|
|
|
1596
1596
|
const hostname = os.hostname();
|
|
1597
1597
|
const cpuPercent = await this.measureCpuPercent(os);
|
|
1598
1598
|
const memoryTotal = os.totalmem();
|
|
1599
|
-
const
|
|
1600
|
-
const memoryUsed = memoryTotal -
|
|
1599
|
+
const memoryAvailable = await this.getAvailableMemoryBytes(os, fs);
|
|
1600
|
+
const memoryUsed = memoryTotal - memoryAvailable;
|
|
1601
1601
|
const memoryPercent = memoryTotal > 0 ? memoryUsed / memoryTotal * 100 : 0;
|
|
1602
1602
|
const disks = await this.collectDiskMetrics(diskPaths, fs);
|
|
1603
1603
|
await this.submitSystemMetric({
|
|
@@ -1613,12 +1613,13 @@ var MonitorClient = class {
|
|
|
1613
1613
|
}
|
|
1614
1614
|
}
|
|
1615
1615
|
/**
|
|
1616
|
-
* Measure CPU utilization by sampling cpus() twice with a
|
|
1617
|
-
*
|
|
1616
|
+
* Measure CPU utilization by sampling cpus() twice with a 3s gap.
|
|
1617
|
+
* The cumulative counters make this the average utilization over the
|
|
1618
|
+
* window, across all cores of the host. Returns a percentage (0–100).
|
|
1618
1619
|
*/
|
|
1619
1620
|
async measureCpuPercent(os) {
|
|
1620
1621
|
const sample1 = os.cpus();
|
|
1621
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
1622
|
+
await new Promise((resolve) => setTimeout(resolve, 3e3));
|
|
1622
1623
|
const sample2 = os.cpus();
|
|
1623
1624
|
let totalIdle = 0;
|
|
1624
1625
|
let totalTick = 0;
|
|
@@ -1630,9 +1631,30 @@ var MonitorClient = class {
|
|
|
1630
1631
|
totalTick += currTotal - prevTotal;
|
|
1631
1632
|
totalIdle += curr.times.idle - prev.times.idle;
|
|
1632
1633
|
}
|
|
1633
|
-
|
|
1634
|
+
if (totalTick <= 0) {
|
|
1635
|
+
return 0;
|
|
1636
|
+
}
|
|
1637
|
+
const idlePercent = totalIdle / totalTick * 100;
|
|
1634
1638
|
return Math.max(0, Math.min(100, 100 - idlePercent));
|
|
1635
1639
|
}
|
|
1640
|
+
/**
|
|
1641
|
+
* Get reclaimable memory in bytes. On Linux, reads MemAvailable from
|
|
1642
|
+
* /proc/meminfo so buffers/cache are not counted as used; falls back to
|
|
1643
|
+
* os.freemem() (MemFree) on other platforms or if parsing fails.
|
|
1644
|
+
*/
|
|
1645
|
+
async getAvailableMemoryBytes(os, fs) {
|
|
1646
|
+
if (os.platform() === "linux") {
|
|
1647
|
+
try {
|
|
1648
|
+
const meminfo = await fs.readFile("/proc/meminfo", "utf8");
|
|
1649
|
+
const match = meminfo.match(/^MemAvailable:\s+(\d+)\s*kB$/m);
|
|
1650
|
+
if (match) {
|
|
1651
|
+
return Number(match[1]) * 1024;
|
|
1652
|
+
}
|
|
1653
|
+
} catch {
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
return os.freemem();
|
|
1657
|
+
}
|
|
1636
1658
|
/**
|
|
1637
1659
|
* Collect disk usage for each configured path using fs.statfs() (Node 18.15+).
|
|
1638
1660
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -1532,7 +1532,7 @@ var MonitorClient = class {
|
|
|
1532
1532
|
* Collect system metrics (CPU, RAM, disk) using built-in Node.js modules
|
|
1533
1533
|
* and submit to the monitoring server.
|
|
1534
1534
|
*
|
|
1535
|
-
* Uses: os.cpus(), os.totalmem(), os.freemem(), os.hostname(), fs.statfs()
|
|
1535
|
+
* Uses: os.cpus(), os.totalmem(), /proc/meminfo (or os.freemem()), os.hostname(), fs.statfs()
|
|
1536
1536
|
* Zero dependencies — all built-in Node.js 18.15+
|
|
1537
1537
|
*/
|
|
1538
1538
|
async collectAndSubmitMetrics(diskPaths) {
|
|
@@ -1560,8 +1560,8 @@ var MonitorClient = class {
|
|
|
1560
1560
|
const hostname = os.hostname();
|
|
1561
1561
|
const cpuPercent = await this.measureCpuPercent(os);
|
|
1562
1562
|
const memoryTotal = os.totalmem();
|
|
1563
|
-
const
|
|
1564
|
-
const memoryUsed = memoryTotal -
|
|
1563
|
+
const memoryAvailable = await this.getAvailableMemoryBytes(os, fs);
|
|
1564
|
+
const memoryUsed = memoryTotal - memoryAvailable;
|
|
1565
1565
|
const memoryPercent = memoryTotal > 0 ? memoryUsed / memoryTotal * 100 : 0;
|
|
1566
1566
|
const disks = await this.collectDiskMetrics(diskPaths, fs);
|
|
1567
1567
|
await this.submitSystemMetric({
|
|
@@ -1577,12 +1577,13 @@ var MonitorClient = class {
|
|
|
1577
1577
|
}
|
|
1578
1578
|
}
|
|
1579
1579
|
/**
|
|
1580
|
-
* Measure CPU utilization by sampling cpus() twice with a
|
|
1581
|
-
*
|
|
1580
|
+
* Measure CPU utilization by sampling cpus() twice with a 3s gap.
|
|
1581
|
+
* The cumulative counters make this the average utilization over the
|
|
1582
|
+
* window, across all cores of the host. Returns a percentage (0–100).
|
|
1582
1583
|
*/
|
|
1583
1584
|
async measureCpuPercent(os) {
|
|
1584
1585
|
const sample1 = os.cpus();
|
|
1585
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
1586
|
+
await new Promise((resolve) => setTimeout(resolve, 3e3));
|
|
1586
1587
|
const sample2 = os.cpus();
|
|
1587
1588
|
let totalIdle = 0;
|
|
1588
1589
|
let totalTick = 0;
|
|
@@ -1594,9 +1595,30 @@ var MonitorClient = class {
|
|
|
1594
1595
|
totalTick += currTotal - prevTotal;
|
|
1595
1596
|
totalIdle += curr.times.idle - prev.times.idle;
|
|
1596
1597
|
}
|
|
1597
|
-
|
|
1598
|
+
if (totalTick <= 0) {
|
|
1599
|
+
return 0;
|
|
1600
|
+
}
|
|
1601
|
+
const idlePercent = totalIdle / totalTick * 100;
|
|
1598
1602
|
return Math.max(0, Math.min(100, 100 - idlePercent));
|
|
1599
1603
|
}
|
|
1604
|
+
/**
|
|
1605
|
+
* Get reclaimable memory in bytes. On Linux, reads MemAvailable from
|
|
1606
|
+
* /proc/meminfo so buffers/cache are not counted as used; falls back to
|
|
1607
|
+
* os.freemem() (MemFree) on other platforms or if parsing fails.
|
|
1608
|
+
*/
|
|
1609
|
+
async getAvailableMemoryBytes(os, fs) {
|
|
1610
|
+
if (os.platform() === "linux") {
|
|
1611
|
+
try {
|
|
1612
|
+
const meminfo = await fs.readFile("/proc/meminfo", "utf8");
|
|
1613
|
+
const match = meminfo.match(/^MemAvailable:\s+(\d+)\s*kB$/m);
|
|
1614
|
+
if (match) {
|
|
1615
|
+
return Number(match[1]) * 1024;
|
|
1616
|
+
}
|
|
1617
|
+
} catch {
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
return os.freemem();
|
|
1621
|
+
}
|
|
1600
1622
|
/**
|
|
1601
1623
|
* Collect disk usage for each configured path using fs.statfs() (Node 18.15+).
|
|
1602
1624
|
*/
|
package/package.json
CHANGED