graphs: directly stream docker stats

docker stats API caches the stat and reading it frequently gives back the same value.
this trips our "rate" code into thinking rate is 0.

one approach was to persist polling like we do now and ignore entries based on stats.read.
this works fine but the streaming approach seems better since we don't need to poll anymore.
This commit is contained in:
Girish Ramakrishnan
2025-07-03 19:01:40 +02:00
parent 03b7445cb9
commit 813409a8fb
4 changed files with 31 additions and 31 deletions

View File

@@ -43,10 +43,8 @@ let systemMemory = {};
let systemCpus = {};
let metricStream = null;
const LIVE_REFRESH_INTERVAL_MSECS = 500;
async function liveRefresh() {
metricStream = await appsModel.getMetricStream(app.id, LIVE_REFRESH_INTERVAL_MSECS);
metricStream = await appsModel.getMetricStream(app.id);
metricStream.onerror = (error) => console.log('event stream error:', error);
metricStream.onmessage = (message) => {
const data = JSON.parse(message.data);

View File

@@ -407,8 +407,8 @@ function create() {
if (result.status !== 200) return [result];
return [null, result.body];
},
async getMetricStream(id, intervalMsecs) {
return new EventSource(`${API_ORIGIN}/api/v1/apps/${id}/metricstream?access_token=${accessToken}&intervalMsecs=${intervalMsecs}`);
async getMetricStream(id) {
return new EventSource(`${API_ORIGIN}/api/v1/apps/${id}/metricstream?access_token=${accessToken}`);
},
async repair(id, data) {
let result;