From 5fa08800bf421284e4dbf85ab883c7ae27c5ae43 Mon Sep 17 00:00:00 2001 From: Marco van Dijk Date: Wed, 10 Aug 2022 11:14:39 +0200 Subject: [PATCH] fixes --- master/src/routes/master.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/master/src/routes/master.js b/master/src/routes/master.js index 56de814..1503012 100644 --- a/master/src/routes/master.js +++ b/master/src/routes/master.js @@ -100,8 +100,7 @@ Incoming stats parsing masterRouter.post("/collectStats", async (req, res) => { try { if (!isSynced) { console.log("waiting for sync"); res.end('busy'); return; } - const { id, discoveryResults, - responseTime, tag, key } = req.body; + const { id, discoveryResults, responseTime, tag, key } = req.body; if (!id || !tag || !key) { console.log("Received malformed data. Aborting stats update..."); console.log(id, discoveryResults, responseTime, tag, key); @@ -157,7 +156,7 @@ masterRouter.post("/collectStats", async (req, res) => { } if (!orchFound) { currentDataList = [{ latency: thisPing, timestamp: now }]; - orchScores.push({ id: thisId, data: currentDataList }); + orchScores.push({ id: thisId, data: [{ tag, data: currentDataList }] }); } await storage.setItem('orchScores', orchScores); // Calc new scores @@ -188,7 +187,9 @@ masterRouter.post("/collectStats", async (req, res) => { promAverageLatency.set({ region: tag, orchestrator: thisId }, pingsum / pingpoints); } if (uptime || downtime) { - const score = uptime / (uptime + downtime) + let score; + if (!uptime) { score = 0; } + else { score = uptime / (uptime + downtime); } promAUptimeScore.set({ region: tag, orchestrator: thisId }, score); } res.send(true); @@ -219,7 +220,7 @@ masterRouter.get("/prometheus", async (req, res) => { masterRouter.get("/json", async (req, res) => { try { res.set('Content-Type', 'application/json'); - res.end(orchScores); + res.end(JSON.stringify(orchScores)); } catch (err) { res.status(400).send(err); }