From 05fee73724e00f5cb4be3beffc382b8b3b3a042c Mon Sep 17 00:00:00 2001 From: lefteris Date: Sun, 25 Apr 2021 19:23:40 +0300 Subject: [PATCH] redis logs ok --- swarmlab-app/src/run/app.js | 55 +++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/swarmlab-app/src/run/app.js b/swarmlab-app/src/run/app.js index fa99f476..f8aba302 100644 --- a/swarmlab-app/src/run/app.js +++ b/swarmlab-app/src/run/app.js @@ -117,19 +117,32 @@ app.get("/length", cors(corsOptions), (req, res) => { 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.log.includes("app_name")) { + } 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(); @@ -139,6 +152,8 @@ app.get("/length", cors(corsOptions), (req, res) => { appout: appout, apperror: apperror, redis: redis, + dumout: dumout, + dumerr: dumerr, }; RES.data = data; @@ -171,7 +186,7 @@ app.get("/test", cors(corsOptions), (req, res) => { obj.forEach((value) => { if (value.container_name == "/redisserver") { // jsonfinal.push(JSON.parse(value.log)); - jsonfinal.push(value.log); + jsonfinal.push(value); } else if (value.container_name == "/mongo") { mongo.push(JSON.parse(value.log)); } else if (value.log.includes("app_name")) { @@ -224,7 +239,35 @@ app.get("/test2", cors(corsOptions), (req, res) => { tmp.type = '
' + tmp.type + "
"; } jsonfinal.push(tmp); + } else if (value.container_name == "/redisserver") { + var tmplog = value; + //timestamp + var time = tmplog.time; + var tmp = { + message: tmplog.log, + timestamp: time, + type: "
out
", + process_id: "Unknown", + app_name: "redis", + }; + 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") { @@ -251,6 +294,14 @@ app.get("/test2", cors(corsOptions), (req, res) => { return b.timestamp.localeCompare(a.timestamp); } }); + } else if (sortname == "app_name") { + jsonfinal.sort(function (a, b) { + if (sortorder == "asc") { + return a.app_name.localeCompare(b.app_name); + } else { + return b.app_name.localeCompare(a.app_name); + } + }); } //Pagination var total = jsonfinal.length;