@jsenv/os-metrics 0.0.1 → 0.0.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/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/os-metrics",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/jsenv/core",
|
|
8
|
-
"directory": "packages/
|
|
8
|
+
"directory": "packages/tooling/os-metrics"
|
|
9
9
|
},
|
|
10
10
|
"author": {
|
|
11
11
|
"name": "dmail",
|
|
12
12
|
"email": "dmaillard06@gmail.com"
|
|
13
13
|
},
|
|
14
|
-
"
|
|
15
|
-
"access": "public"
|
|
16
|
-
},
|
|
17
|
-
"type": "module",
|
|
14
|
+
"license": "MIT",
|
|
18
15
|
"main": "./src/main.js",
|
|
19
16
|
"files": [
|
|
20
17
|
"/src/"
|
|
21
18
|
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
22
|
"sideEffects": false
|
|
23
23
|
}
|
package/src/cpu_usage.js
CHANGED
|
@@ -31,6 +31,13 @@ export const startMeasuringTotalCpuUsage = () => {
|
|
|
31
31
|
let cpuArray = cpus();
|
|
32
32
|
const ms = Date.now();
|
|
33
33
|
const ellapsedMs = ms - previousMs;
|
|
34
|
+
// When the OS takes the thread for longer than the interval, the overdue
|
|
35
|
+
// timer fires again within the same ms: no time elapsed, so no ratio exists
|
|
36
|
+
// (0/0 would turn every average of this batch into NaN).
|
|
37
|
+
// The previous values are kept so the next sample covers this period.
|
|
38
|
+
if (ellapsedMs === 0) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
34
41
|
const cpuUsageSampleArray = [];
|
|
35
42
|
let overallSystemMs = 0;
|
|
36
43
|
let overallUserMs = 0;
|
package/src/memory_monitoring.js
CHANGED
|
@@ -4,7 +4,9 @@ import { startMonitoringMetric } from "./metric_monitoring.js";
|
|
|
4
4
|
|
|
5
5
|
export const startMonitoringMemoryUsage = () => {
|
|
6
6
|
const processMemoryUsageMonitoring = startMonitoringMetric(() => {
|
|
7
|
-
|
|
7
|
+
// memoryUsage.rss() reads only rss; the full memoryUsage() computes
|
|
8
|
+
// every field and shows up in build profiles
|
|
9
|
+
return memoryUsage.rss();
|
|
8
10
|
});
|
|
9
11
|
const osMemoryUsageMonitoring = startMonitoringMetric(() => {
|
|
10
12
|
const total = totalmem();
|
|
@@ -3,7 +3,9 @@ import { startMonitoringMetric } from "./metric_monitoring.js";
|
|
|
3
3
|
|
|
4
4
|
export const startMeasuringProcessMemoryUsage = () => {
|
|
5
5
|
const processMemoryUsageMonitoring = startMonitoringMetric(() => {
|
|
6
|
-
|
|
6
|
+
// memoryUsage.rss() reads only rss; the full memoryUsage() computes
|
|
7
|
+
// every field and shows up in build profiles
|
|
8
|
+
return memoryUsage.rss();
|
|
7
9
|
});
|
|
8
10
|
return processMemoryUsageMonitoring;
|
|
9
11
|
};
|