Browse Source

api v2

master
lefteris 4 years ago
parent
commit
78a708fbd9
  1. 31
      swarmlab-app/src/run/app.js

31
swarmlab-app/src/run/app.js

@ -61,6 +61,7 @@ const helmet = require("helmet");
app.use(helmet()); app.use(helmet());
const cors = require("cors"); const cors = require("cors");
const { MongoError } = require("mongodb");
const whitelist = [ const whitelist = [
"http://localhost:3000", "http://localhost:3000",
"http://localhost:8080", "http://localhost:8080",
@ -114,21 +115,30 @@ app.get("/length", cors(corsOptions), (req, res) => {
var appout = 0; var appout = 0;
var apperror = 0; var apperror = 0;
var mongol = 0; var mongol = 0;
var mongolerror = 0;
var redis = 0;
obj.forEach((value) => { obj.forEach((value) => {
if (value.container_name == "/mongo") { if (value.container_name == "/mongo") {
mongol++; 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.log.includes("app_name")) {
var test = JSON.parse(value.log); var test = JSON.parse(value.log);
var type = test.type; var type = test.type;
if (type == "err") apperror++; if (type == "err") apperror++;
else appout++; else appout++;
} else if (value.container_name == "/redisserver") {
redis++;
} }
}); });
var RES = new Object(); var RES = new Object();
var data = { var data = {
mongolength: mongol, mongolength: mongol,
mongolerror: mongolerror,
appout: appout, appout: appout,
apperror: apperror, apperror: apperror,
redis: redis,
}; };
RES.data = data; RES.data = data;
@ -156,12 +166,25 @@ app.get("/test", cors(corsOptions), (req, res) => {
// EPIDI EXW NESTED JSON PREPEI NA TO KANW PARSE DUO FORES // EPIDI EXW NESTED JSON PREPEI NA TO KANW PARSE DUO FORES
var obj = JSON.parse(JSON.stringify(result)); var obj = JSON.parse(JSON.stringify(result));
var jsonfinal = []; var jsonfinal = [];
var mongo = [];
var app = [];
obj.forEach((value) => { obj.forEach((value) => {
if (value.container_name == "/mongo") { if (value.container_name == "/redisserver") {
jsonfinal.push(JSON.parse(value.log)); // jsonfinal.push(JSON.parse(value.log));
jsonfinal.push(value.log);
} 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));
} }
}); });
res.json(jsonfinal); var RES = new Object();
RES.data = {
redis: jsonfinal,
mongo: mongo,
app: app,
};
res.json(RES.data);
db.close(); db.close();
}); });
}); });

Loading…
Cancel
Save