metrics: make interval msecs
This commit is contained in:
+3
-3
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user