diff --git a/swarmlab-app/src/run/app.js b/swarmlab-app/src/run/app.js index f8aba302..4bea50b6 100644 --- a/swarmlab-app/src/run/app.js +++ b/swarmlab-app/src/run/app.js @@ -4,7 +4,6 @@ var pathmodule = require("path"); var app = require("express")(); var http = require("http").Server(app); var https = require("https"); -const mongoose = require("mongoose"); var CONFIG = require(pathmodule.resolve(__dirname, "runconfig.js")); const io = require("socket.io")(http, { // pingTimeout: 30000, @@ -102,66 +101,70 @@ app.get("/length", cors(corsOptions), (req, res) => { 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; - var mongolerror = 0; - var redis = 0; - var dumout = 0; - var dumerr = 0; - obj.forEach((value) => { - if (value.container_name == "/mongo") { - var tmp = JSON.parse(value.log); - if (tmp.s == "I") mongol++; - // count every informative log as an output log - else if (tmp.s == "W" || tmp.s == "E") mongolerror++; //count every warning and error log - } else if ( - value.container_name == "/readmongo_service" && - value.log.includes("app_name") - ) { - var test = JSON.parse(value.log); - var type = test.type; - if (type == "err") apperror++; - else appout++; - } else if (value.container_name == "/redisserver") { - redis++; - } else if ( - value.container_name == "/dummy_service" && - value.log.includes("app_name") - ) { - var test = JSON.parse(value.log); - var type = test.type; - if (type == "err") dumerr++; - else dumout++; - } + MongoClient.connect( + url, + { useNewUrlParser: true, useUnifiedTopology: true }, + 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; + var mongolerror = 0; + var redis = 0; + var dumout = 0; + var dumerr = 0; + obj.forEach((value) => { + if (value.container_name == "/mongo") { + var tmp = JSON.parse(value.log); + if (tmp.s == "I") mongol++; + // count every informative log as an output log + else if (tmp.s == "W" || tmp.s == "E") mongolerror++; //count every warning and error log + } else if ( + value.container_name == "/readmongo_service" && + value.log.includes("app_name") + ) { + var test = JSON.parse(value.log); + var type = test.type; + if (type == "err") apperror++; + else appout++; + } else if (value.container_name == "/redisserver") { + redis++; + } else if ( + value.container_name == "/dummy_service" && + value.log.includes("app_name") + ) { + var test = JSON.parse(value.log); + var type = test.type; + if (type == "err") dumerr++; + else dumout++; + } + }); + var RES = new Object(); + var data = { + mongolength: mongol, + mongolerror: mongolerror, + appout: appout, + apperror: apperror, + redis: redis, + dumout: dumout, + dumerr: dumerr, + }; + RES.data = data; + + // console.log("Sending Data: " + jsonfinal); + res.json(RES.data); + db.close(); }); - var RES = new Object(); - var data = { - mongolength: mongol, - mongolerror: mongolerror, - appout: appout, - apperror: apperror, - redis: redis, - dumout: dumout, - dumerr: dumerr, - }; - RES.data = data; - - // console.log("Sending Data: " + jsonfinal); - res.json(RES.data); - db.close(); - }); - }); + } + ); }); // Lefos - mongo test read @@ -170,39 +173,43 @@ app.get("/test", cors(corsOptions), (req, res) => { 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 jsonfinal = []; - var mongo = []; - var app = []; - obj.forEach((value) => { - if (value.container_name == "/redisserver") { - // jsonfinal.push(JSON.parse(value.log)); - jsonfinal.push(value); - } else if (value.container_name == "/mongo") { - mongo.push(JSON.parse(value.log)); - } else if (value.log.includes("app_name")) { - app.push(JSON.parse(value.log)); - } + MongoClient.connect( + url, + { useNewUrlParser: true, useUnifiedTopology: true }, + 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 jsonfinal = []; + var mongo = []; + var app = []; + obj.forEach((value) => { + if (value.container_name == "/redisserver") { + // jsonfinal.push(JSON.parse(value.log)); + jsonfinal.push(value); + } else if (value.container_name == "/mongo") { + mongo.push(JSON.parse(value.log)); + } else if (value.log.includes("app_name")) { + app.push(JSON.parse(value.log)); + } + }); + var RES = new Object(); + RES.data = { + redis: jsonfinal, + mongo: mongo, + app: app, + }; + res.json(RES.data); + db.close(); }); - var RES = new Object(); - RES.data = { - redis: jsonfinal, - mongo: mongo, - app: app, - }; - res.json(RES.data); - db.close(); - }); - }); + } + ); }); app.get("/test2", cors(corsOptions), (req, res) => { @@ -219,112 +226,115 @@ app.get("/test2", cors(corsOptions), (req, res) => { var url = "mongodb://mongo:27017/"; var jsonfinal = []; - 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)); - - obj.forEach((value) => { - if (value.log.includes("app_name")) { - var tmp = JSON.parse(value.log); - if (tmp.type == "out") { - tmp.type = '