From 1cb92ad70661ddf73cb9a6702627d3edcff615e8 Mon Sep 17 00:00:00 2001 From: lefteris Date: Sun, 18 Apr 2021 17:06:49 +0300 Subject: [PATCH] highchart api --- swarmlab-app/src/run/app.js | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/swarmlab-app/src/run/app.js b/swarmlab-app/src/run/app.js index 793dae98..666e24f6 100644 --- a/swarmlab-app/src/run/app.js +++ b/swarmlab-app/src/run/app.js @@ -95,6 +95,49 @@ const corsOptions = { // ------------------------------ // --- LEFOS MONGO LOGGING // ------------------------------ +// Lefos - get length of logs +app.get("/length", cors(corsOptions), (req, res) => { + console.log("getting length of logs"); + + var url = "mongodb://mongo:27017/"; + + MongoClient.connect(url, function (err, db) { + if (err) throw err; + var dbo = db.db("fluentdb"); + dbo + .collection("test") + .find({}) + .toArray(function (err, result) { + if (err) throw err; + // EPIDI EXW NESTED JSON PREPEI NA TO KANW PARSE DUO FORES + var obj = JSON.parse(JSON.stringify(result)); + var appout = 0; + var apperror = 0; + var mongol = 0; + obj.forEach((value) => { + if (value.container_name == "/mongo") { + mongol++; + } else if (value.log.includes("app_name")) { + var test = JSON.parse(value.log); + var type = test.type; + if (type == "err") apperror++; + else appout++; + } + }); + var RES = new Object(); + var data = { + mongolength: mongol, + appout: appout, + apperror: apperror, + }; + RES.data = data; + + // console.log("Sending Data: " + jsonfinal); + res.json(RES.data); + db.close(); + }); + }); +}); // Lefos - mongo test read app.get("/test", cors(corsOptions), (req, res) => {