diff --git a/dashboard/src/models/SystemModel.js b/dashboard/src/models/SystemModel.js index 0f63e7eaf..736a5140b 100644 --- a/dashboard/src/models/SystemModel.js +++ b/dashboard/src/models/SystemModel.js @@ -95,7 +95,7 @@ function create() { return [null, result.body]; }, async getMetricStream() { - return new EventSource(`${API_ORIGIN}/api/v1/system/metricstream?access_token=${accessToken}&intervalSecs=3`); + return new EventSource(`${API_ORIGIN}/api/v1/system/metricstream?access_token=${accessToken}&intervalMsecs=500`); } }; } diff --git a/src/metrics.js b/src/metrics.js index cac1f0b86..f4984ae08 100644 --- a/src/metrics.js +++ b/src/metrics.js @@ -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; } diff --git a/src/routes/system.js b/src/routes/system.js index 2769f7019..4e3b9e52a 100644 --- a/src/routes/system.js +++ b/src/routes/system.js @@ -134,10 +134,10 @@ async function getMetrics(req, res, next) { async function getMetricStream(req, res, next) { if (req.headers.accept !== 'text/event-stream') return next(new HttpError(400, 'This API call requires EventStream')); - const intervalSecs = typeof req.query.intervalSecs !== 'undefined' ? parseInt(req.query.intervalSecs, 10) : 5; - if (!intervalSecs || intervalSecs < 2) return next(new HttpError(400, 'intervalSecs query param must be >= 2')); + const intervalMsecs = typeof req.query.intervalMsecs !== 'undefined' ? parseInt(req.query.intervalMsecs, 10) : 5000; + if (!intervalMsecs || intervalMsecs < 100) return next(new HttpError(400, 'intervalSecs query param must be atleast 100')); - const [error, metricStream] = await safe(metrics.getSystemStream({ intervalSecs })); + const [error, metricStream] = await safe(metrics.getSystemStream({ intervalMsecs })); if (error) return next(BoxError.toHttpError(error)); res.writeHead(200, {