diff --git a/dashboard/src/components/GraphItem.vue b/dashboard/src/components/GraphItem.vue index b95d4ccbf..ad0d7ceb7 100644 --- a/dashboard/src/components/GraphItem.vue +++ b/dashboard/src/components/GraphItem.vue @@ -9,7 +9,7 @@ import annotationPlugin from 'chartjs-plugin-annotation'; Chart.register(annotationPlugin); -const LIVE_REFRESH_INTERVAL_MSECS = 500; // for realtime graphs, the time (x axis) advances at this pace +const LIVE_REFRESH_INTERVAL_MSECS = 1000; // for realtime graphs, the time (x axis) advances at this pace const graphNode = useTemplateRef('graphNode'); diff --git a/dashboard/src/components/SystemMetrics.vue b/dashboard/src/components/SystemMetrics.vue index 181fce247..1c2e588ad 100644 --- a/dashboard/src/components/SystemMetrics.vue +++ b/dashboard/src/components/SystemMetrics.vue @@ -40,10 +40,8 @@ let systemMemory = {}; let systemCpus = {}; let metricStream = null; -const LIVE_REFRESH_INTERVAL_MSECS = 500; - async function liveRefresh() { - metricStream = await systemModel.getMetricStream(LIVE_REFRESH_INTERVAL_MSECS); + metricStream = await systemModel.getMetricStream(); metricStream.onerror = (error) => console.log('event stream error:', error); metricStream.onmessage = (message) => { const data = JSON.parse(message.data); diff --git a/dashboard/src/models/SystemModel.js b/dashboard/src/models/SystemModel.js index 41bf4a42c..356fe0420 100644 --- a/dashboard/src/models/SystemModel.js +++ b/dashboard/src/models/SystemModel.js @@ -94,8 +94,8 @@ function create() { if (error || result.status !== 200) return [error || result]; return [null, result.body]; }, - async getMetricStream(intervalMsecs) { - return new EventSource(`${API_ORIGIN}/api/v1/system/metricstream?access_token=${accessToken}&intervalMsecs=${intervalMsecs}`); + async getMetricStream() { + return new EventSource(`${API_ORIGIN}/api/v1/system/metricstream?access_token=${accessToken}`); } }; } diff --git a/src/metrics.js b/src/metrics.js index 5531973e9..a291d9959 100644 --- a/src/metrics.js +++ b/src/metrics.js @@ -386,7 +386,7 @@ async function getSystem(options) { async function getSystemStream(options) { assert.strictEqual(typeof options, 'object'); - const intervalMsecs = options.intervalMsecs || 5000; + const INTERVAL_MSECS = 1000; let intervalId = null, oldMetrics = null; const metricsStream = new Readable({ @@ -402,11 +402,11 @@ async function getSystemStream(options) { const [error, metrics] = await safe(readSystemMetrics()); if (error) return metricsStream.destroy(error); - const cpuPercent = oldMetrics ? (metrics.userMsecs + metrics.sysMsecs - oldMetrics.userMsecs - oldMetrics.sysMsecs) * 100 / intervalMsecs : null; - const blockReadRate = oldMetrics ? (metrics.blockRead - oldMetrics.blockRead) / (intervalMsecs/1000) : null; - const blockWriteRate = oldMetrics ? (metrics.blockWrite - oldMetrics.blockWrite) / (intervalMsecs/1000) : null; - const networkReadRate = oldMetrics ? (metrics.networkRead - oldMetrics.networkRead) / (intervalMsecs/1000) : null; - const networkWriteRate = oldMetrics ? (metrics.networkWrite - oldMetrics.networkWrite) / (intervalMsecs/1000) : null; + const cpuPercent = oldMetrics ? (metrics.userMsecs + metrics.sysMsecs - oldMetrics.userMsecs - oldMetrics.sysMsecs) * 100 / INTERVAL_MSECS : null; + const blockReadRate = oldMetrics ? (metrics.blockRead - oldMetrics.blockRead) / (INTERVAL_MSECS/1000) : null; + const blockWriteRate = oldMetrics ? (metrics.blockWrite - oldMetrics.blockWrite) / (INTERVAL_MSECS/1000) : null; + const networkReadRate = oldMetrics ? (metrics.networkRead - oldMetrics.networkRead) / (INTERVAL_MSECS/1000) : null; + const networkWriteRate = oldMetrics ? (metrics.networkWrite - oldMetrics.networkWrite) / (INTERVAL_MSECS/1000) : null; oldMetrics = metrics; @@ -426,7 +426,7 @@ async function getSystemStream(options) { networkReadTotal: metrics.networkRead, networkWriteTotal: metrics.networkWrite, }); - }, intervalMsecs); + }, INTERVAL_MSECS); return metricsStream; } diff --git a/src/routes/system.js b/src/routes/system.js index 85f7d6b46..bbf3582dd 100644 --- a/src/routes/system.js +++ b/src/routes/system.js @@ -134,10 +134,7 @@ 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 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({ intervalMsecs })); + const [error, metricStream] = await safe(metrics.getSystemStream({})); if (error) return next(BoxError.toHttpError(error)); res.writeHead(200, {