metrics: make interval msecs

This commit is contained in:
Girish Ramakrishnan
2025-05-22 12:18:31 +02:00
parent b2c48af53f
commit e5b27af055
3 changed files with 7 additions and 7 deletions
+3 -3
View File
@@ -307,7 +307,7 @@ async function getSystem(options) {
async function getSystemStream(options) {
assert.strictEqual(typeof options, 'object');
const INTERVAL_SECS = options.intervalSecs || 5;
const INTERVAL_MSECS = options.intervalMsecs || 5000;
let intervalId = null, oldCpuMetrics = null;
const metricsStream = new Readable({
@@ -322,7 +322,7 @@ async function getSystemStream(options) {
const memoryMetrics = await getMemoryMetrics();
const cpuMetrics = await getCpuMetrics();
const cpuPercent = oldCpuMetrics ? (cpuMetrics.userMsecs + cpuMetrics.sysMsecs - oldCpuMetrics.userMsecs - oldCpuMetrics.sysMsecs) * 0.1 / INTERVAL_SECS : null;
const cpuPercent = oldCpuMetrics ? (cpuMetrics.userMsecs + cpuMetrics.sysMsecs - oldCpuMetrics.userMsecs - oldCpuMetrics.sysMsecs) * 0.1 / (INTERVAL_MSECS/1000) : null;
oldCpuMetrics = cpuMetrics;
const now = Date.now() / 1000;
@@ -331,7 +331,7 @@ async function getSystemStream(options) {
memory: [ memoryMetrics.memoryUsed, now ],
swap: [ memoryMetrics.swapUsed, now ],
}));
}, INTERVAL_SECS*1000);
}, INTERVAL_MSECS);
return metricsStream;
}