graphs: show correct metrics when container stops
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user