diff --git a/src/metrics.js b/src/metrics.js index 547b7d9c0..6d71d6329 100644 --- a/src/metrics.js +++ b/src/metrics.js @@ -390,6 +390,7 @@ async function getSystemStream(options) { let intervalId = null, oldMetrics = null; const metricsStream = new Readable({ + objectMode: true, read(/*size*/) { /* ignored, we push via interval */ }, destroy(error, callback) { clearInterval(intervalId); @@ -410,7 +411,7 @@ async function getSystemStream(options) { oldMetrics = metrics; const nowSecs = Date.now() / 1000; // to match graphite return value - metricsStream.push(JSON.stringify({ + metricsStream.push({ cpu: [ cpuPercent, nowSecs ], memory: [ metrics.memoryUsed, nowSecs ], swap: [ metrics.swapUsed, nowSecs ], @@ -424,7 +425,7 @@ async function getSystemStream(options) { networkWriteRate: [ networkWriteRate, nowSecs ], networkReadTotal: metrics.networkRead, networkWriteTotal: metrics.networkWrite, - })); + }); }, intervalMsecs); return metricsStream; @@ -437,6 +438,7 @@ async function getContainerStream(name, options) { let oldMetrics = null; const metricsStream = new Readable({ + objectMode: true, read(/*size*/) { /* ignored, we push via interval */ }, destroy(error, callback) { statsStream.destroy(); // double destroy is a no-op @@ -467,7 +469,7 @@ async function getContainerStream(name, options) { oldMetrics = metrics; const nowSecs = ts.getTime() / 1000; // conver to secs to match graphite return value - metricsStream.push(JSON.stringify({ + metricsStream.push({ cpu: [ cpuPercent, nowSecs ], memory: [ memoryUsed, nowSecs ], @@ -480,7 +482,7 @@ async function getContainerStream(name, options) { networkWriteRate: [ networkWriteRate, nowSecs ], networkReadTotal: metrics.networkRead, networkWriteTotal: metrics.networkWrite, - })); + }); }); return metricsStream; diff --git a/src/routes/apps.js b/src/routes/apps.js index e77845044..7037f18eb 100644 --- a/src/routes/apps.js +++ b/src/routes/apps.js @@ -1097,8 +1097,7 @@ async function getMetricStream(req, res, next) { }); res.write('retry: 3000\n'); res.on('close', () => metricStream.destroy()); - metricStream.on('data', function (data) { - const obj = JSON.parse(data); + metricStream.on('data', function (obj) { // objectMode stream const sse = `data: ${JSON.stringify(obj)}\n\n`; res.write(sse); }); diff --git a/src/routes/system.js b/src/routes/system.js index 4e3b9e52a..85f7d6b46 100644 --- a/src/routes/system.js +++ b/src/routes/system.js @@ -149,8 +149,7 @@ async function getMetricStream(req, res, next) { }); res.write('retry: 3000\n'); res.on('close', () => metricStream.destroy()); - metricStream.on('data', function (data) { - const obj = JSON.parse(data); + metricStream.on('data', function (obj) { // objectMode stream const sse = `data: ${JSON.stringify(obj)}\n\n`; res.write(sse); });