diff --git a/swarmlab-app/src/run/app.js b/swarmlab-app/src/run/app.js index 4bea50b6..2220c52c 100644 --- a/swarmlab-app/src/run/app.js +++ b/swarmlab-app/src/run/app.js @@ -167,6 +167,72 @@ app.get("/length", cors(corsOptions), (req, res) => { ); }); +app.get("/services", cors(corsOptions), (req, res) => { + console.error("getting length of logs"); + + var url = "mongodb://mongo:27017/"; + + 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 services = []; + var flag = false; + obj.forEach((value) => { + if (flag == false) { + services.push(value.container_name); + flag = true; + } else { + var tmp = "none"; + var count = 0; + services.forEach((val) => { + var length = services.length; + + var found = false; + if ( + val != value.container_name && + count + 1 < length && + found == false + ) { + count++; + //services.push(value.container_name) + } else if ( + val != value.container_name && + count + 1 == length && + found == false + ) { + //found =true; + tmp = value.container_name; + } else if (val == value.container_name) { + found = true; + } + }); + + if (tmp != "none") { + services.push(tmp); + } + } + }); + var RES = new Object(); + + RES.data = services; + // console.log("Sending Data: " + jsonfinal); + res.json(RES.data); + db.close(); + }); + } + ); +}); + // Lefos - mongo test read app.get("/test", cors(corsOptions), (req, res) => { console.log("reading from db...."); @@ -222,6 +288,13 @@ app.get("/test2", cors(corsOptions), (req, res) => { var sorttmp1 = sort.split("|"); var sortname = sorttmp1[0]; var sortorder = sorttmp1[1]; + + // text to search in logs + var logtext = req.query["logtext"]; + // service to choose from all containers + var selected = req.query["selected"]; + + console.error("EXTRA PARAMS: " + logtext); //console.log("TEST LOG"); var url = "mongodb://mongo:27017/"; @@ -243,13 +316,31 @@ app.get("/test2", cors(corsOptions), (req, res) => { obj.forEach((value) => { if (value.log.includes("app_name")) { var tmp = JSON.parse(value.log); + var container_name = value.container_name; if (tmp.type == "out") { tmp.type = '
' + tmp.type + "
"; } else if (tmp.type == "err") { tmp.type = '
' + tmp.type + "
"; } - jsonfinal.push(tmp); - } else if (value.container_name == "/redisserver") { + + // filtrarisma gia to text poy exei dwsei o xrhsths + if ( + logtext != "" && + tmp.message.includes(logtext) && + (container_name == selected || selected == "All") + ) { + jsonfinal.push(tmp); + } else if (logtext != "" && !tmp.message.includes(logtext)) { + } else if ( + logtext == "" && + (container_name == selected || selected == "All") + ) { + jsonfinal.push(tmp); + } + } else if ( + value.container_name == "/redisserver" && + (value.container_name == selected || selected == "All") + ) { var tmplog = value; //timestamp var time = tmplog.time; @@ -257,27 +348,30 @@ app.get("/test2", cors(corsOptions), (req, res) => { message: tmplog.log, timestamp: time, type: "
out
", - process_id: "Unknown", + process_id: "-", app_name: "redis", }; - jsonfinal.push(tmp); + if (logtext == "" || tmp.message.includes(logtext)) + jsonfinal.push(tmp); + } else if ( + value.container_name == "/mongo" && + (value.container_name == selected || selected == "All") + ) { + var tmplog = JSON.parse(value.log); + var msg2 = tmplog.msg; + + //timestam + var time = value.time; + var tmp = { + message: msg2, + timestamp: time, + type: "
out
", + process_id: "-", + app_name: "Mongo", + }; + if (logtext == "" || tmp.message.includes(logtext)) + jsonfinal.push(tmp); } - // else if (value.container_name == "/mongo") { - // var tmplog = JSON.parse(value.log); - // var msg2 = tmplog.msg; - - // //timestam - // var time = tmplog.t; - // time = time.$date; - // var tmp = { - // message: msg2, - // timestamp: time, - // type: "
out
", - // process_id: "Unknown", - // app_name: "Mongo", - // }; - // jsonfinal.push(tmp); - // } }); //console.log("Sending Data: " + jsonfinal); if (sortname == "type") {