diff --git a/dashboard/src/components/SystemGraphs.vue b/dashboard/src/components/SystemGraphs.vue index 6a8199a22..44283a223 100644 --- a/dashboard/src/components/SystemGraphs.vue +++ b/dashboard/src/components/SystemGraphs.vue @@ -61,20 +61,21 @@ async function liveRefresh() { appIds: selectedContainers.value.map(c => c.id), serviceIds: [] }; + const metricIds = options.appIds.concat('system'); // 'system' has to be in the end for the loop below metricStream = await systemModel.getMetricStream(options); metricStream.onerror = (error) => console.log('event stream error:', error); metricStream.onmessage = (message) => { const data = JSON.parse(message.data); - for (const [id, metric] of Object.entries(data)) { - const idx = id !== 'system' ? selectedContainers.value.findIndex(c => c.id === id) : selectedContainers.value.length; + for (const [idx, id] of metricIds.entries()) { + const metric = data[id]; // metric can be undefined if the container stopped midway - if (cpuGraphItem.value) cpuGraphItem.value.pushData(idx, metric.cpu); - if (memoryGraphItem.value) memoryGraphItem.value.pushData(idx*2, metric.memory, metric.swap || []); // apps have no swap - if (diskGraphItem.value) diskGraphItem.value.pushData(idx*2, metric.blockReadRate, metric.blockWriteRate); - if (networkGraphItem.value) networkGraphItem.value.pushData(idx*2, metric.networkReadRate, metric.networkWriteRate); + if (cpuGraphItem.value) cpuGraphItem.value.pushData(idx, metric?.cpu || 0); + if (memoryGraphItem.value) memoryGraphItem.value.pushData(idx*2, metric?.memory || 0, metric?.swap || []); // apps have no swap + if (diskGraphItem.value) diskGraphItem.value.pushData(idx*2, metric?.blockReadRate || 0, metric?.blockWriteRate || 0); + if (networkGraphItem.value) networkGraphItem.value.pushData(idx*2, metric?.networkReadRate || 0, metric?.networkWriteRate || 0); - if (id === 'system') { + if (id === 'system') { // metric is always present blockReadTotal.value = prettyDecimalSize(metric.blockReadTotal); blockWriteTotal.value = prettyDecimalSize(metric.blockWriteTotal); networkReadTotal.value = prettyDecimalSize(metric.networkReadTotal); diff --git a/src/metrics.js b/src/metrics.js index f690b3c1e..786ae8aa9 100644 --- a/src/metrics.js +++ b/src/metrics.js @@ -381,7 +381,10 @@ async function pipeContainerToMap(name, statsMap) { statsStream.on('data', (data) => { const stats = JSON.parse(data.toString('utf8')); const metrics = translateContainerStatsSync(stats); - if (!metrics) return; // maybe the container stopped + if (!metrics) { // maybe the container stopped + statsMap.delete(name); + return; + } const { ts, networkRead, networkWrite, blockRead, blockWrite, memoryUsed, cpuUsageMsecs } = metrics;