|
@ -4,7 +4,6 @@ var pathmodule = require("path"); |
|
|
var app = require("express")(); |
|
|
var app = require("express")(); |
|
|
var http = require("http").Server(app); |
|
|
var http = require("http").Server(app); |
|
|
var https = require("https"); |
|
|
var https = require("https"); |
|
|
const mongoose = require("mongoose"); |
|
|
|
|
|
var CONFIG = require(pathmodule.resolve(__dirname, "runconfig.js")); |
|
|
var CONFIG = require(pathmodule.resolve(__dirname, "runconfig.js")); |
|
|
const io = require("socket.io")(http, { |
|
|
const io = require("socket.io")(http, { |
|
|
// pingTimeout: 30000,
|
|
|
// pingTimeout: 30000,
|
|
@ -102,66 +101,70 @@ app.get("/length", cors(corsOptions), (req, res) => { |
|
|
|
|
|
|
|
|
var url = "mongodb://mongo:27017/"; |
|
|
var url = "mongodb://mongo:27017/"; |
|
|
|
|
|
|
|
|
MongoClient.connect(url, function (err, db) { |
|
|
MongoClient.connect( |
|
|
if (err) throw err; |
|
|
url, |
|
|
var dbo = db.db("fluentdb"); |
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
dbo |
|
|
function (err, db) { |
|
|
.collection("test") |
|
|
if (err) throw err; |
|
|
.find({}) |
|
|
var dbo = db.db("fluentdb"); |
|
|
.toArray(function (err, result) { |
|
|
dbo |
|
|
if (err) throw err; |
|
|
.collection("test") |
|
|
// EPIDI EXW NESTED JSON PREPEI NA TO KANW PARSE DUO FORES
|
|
|
.find({}) |
|
|
var obj = JSON.parse(JSON.stringify(result)); |
|
|
.toArray(function (err, result) { |
|
|
var appout = 0; |
|
|
if (err) throw err; |
|
|
var apperror = 0; |
|
|
// EPIDI EXW NESTED JSON PREPEI NA TO KANW PARSE DUO FORES
|
|
|
var mongol = 0; |
|
|
var obj = JSON.parse(JSON.stringify(result)); |
|
|
var mongolerror = 0; |
|
|
var appout = 0; |
|
|
var redis = 0; |
|
|
var apperror = 0; |
|
|
var dumout = 0; |
|
|
var mongol = 0; |
|
|
var dumerr = 0; |
|
|
var mongolerror = 0; |
|
|
obj.forEach((value) => { |
|
|
var redis = 0; |
|
|
if (value.container_name == "/mongo") { |
|
|
var dumout = 0; |
|
|
var tmp = JSON.parse(value.log); |
|
|
var dumerr = 0; |
|
|
if (tmp.s == "I") mongol++; |
|
|
obj.forEach((value) => { |
|
|
// count every informative log as an output log
|
|
|
if (value.container_name == "/mongo") { |
|
|
else if (tmp.s == "W" || tmp.s == "E") mongolerror++; //count every warning and error log
|
|
|
var tmp = JSON.parse(value.log); |
|
|
} else if ( |
|
|
if (tmp.s == "I") mongol++; |
|
|
value.container_name == "/readmongo_service" && |
|
|
// count every informative log as an output log
|
|
|
value.log.includes("app_name") |
|
|
else if (tmp.s == "W" || tmp.s == "E") mongolerror++; //count every warning and error log
|
|
|
) { |
|
|
} else if ( |
|
|
var test = JSON.parse(value.log); |
|
|
value.container_name == "/readmongo_service" && |
|
|
var type = test.type; |
|
|
value.log.includes("app_name") |
|
|
if (type == "err") apperror++; |
|
|
) { |
|
|
else appout++; |
|
|
var test = JSON.parse(value.log); |
|
|
} else if (value.container_name == "/redisserver") { |
|
|
var type = test.type; |
|
|
redis++; |
|
|
if (type == "err") apperror++; |
|
|
} else if ( |
|
|
else appout++; |
|
|
value.container_name == "/dummy_service" && |
|
|
} else if (value.container_name == "/redisserver") { |
|
|
value.log.includes("app_name") |
|
|
redis++; |
|
|
) { |
|
|
} else if ( |
|
|
var test = JSON.parse(value.log); |
|
|
value.container_name == "/dummy_service" && |
|
|
var type = test.type; |
|
|
value.log.includes("app_name") |
|
|
if (type == "err") dumerr++; |
|
|
) { |
|
|
else dumout++; |
|
|
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
|
|
|
// Lefos - mongo test read
|
|
@ -170,39 +173,43 @@ app.get("/test", cors(corsOptions), (req, res) => { |
|
|
|
|
|
|
|
|
var url = "mongodb://mongo:27017/"; |
|
|
var url = "mongodb://mongo:27017/"; |
|
|
|
|
|
|
|
|
MongoClient.connect(url, function (err, db) { |
|
|
MongoClient.connect( |
|
|
if (err) throw err; |
|
|
url, |
|
|
var dbo = db.db("fluentdb"); |
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
dbo |
|
|
function (err, db) { |
|
|
.collection("test") |
|
|
if (err) throw err; |
|
|
.find({}) |
|
|
var dbo = db.db("fluentdb"); |
|
|
.toArray(function (err, result) { |
|
|
dbo |
|
|
if (err) throw err; |
|
|
.collection("test") |
|
|
// EPIDI EXW NESTED JSON PREPEI NA TO KANW PARSE DUO FORES
|
|
|
.find({}) |
|
|
var obj = JSON.parse(JSON.stringify(result)); |
|
|
.toArray(function (err, result) { |
|
|
var jsonfinal = []; |
|
|
if (err) throw err; |
|
|
var mongo = []; |
|
|
// EPIDI EXW NESTED JSON PREPEI NA TO KANW PARSE DUO FORES
|
|
|
var app = []; |
|
|
var obj = JSON.parse(JSON.stringify(result)); |
|
|
obj.forEach((value) => { |
|
|
var jsonfinal = []; |
|
|
if (value.container_name == "/redisserver") { |
|
|
var mongo = []; |
|
|
// jsonfinal.push(JSON.parse(value.log));
|
|
|
var app = []; |
|
|
jsonfinal.push(value); |
|
|
obj.forEach((value) => { |
|
|
} else if (value.container_name == "/mongo") { |
|
|
if (value.container_name == "/redisserver") { |
|
|
mongo.push(JSON.parse(value.log)); |
|
|
// jsonfinal.push(JSON.parse(value.log));
|
|
|
} else if (value.log.includes("app_name")) { |
|
|
jsonfinal.push(value); |
|
|
app.push(JSON.parse(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)); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
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) => { |
|
|
app.get("/test2", cors(corsOptions), (req, res) => { |
|
@ -219,112 +226,115 @@ app.get("/test2", cors(corsOptions), (req, res) => { |
|
|
|
|
|
|
|
|
var url = "mongodb://mongo:27017/"; |
|
|
var url = "mongodb://mongo:27017/"; |
|
|
var jsonfinal = []; |
|
|
var jsonfinal = []; |
|
|
MongoClient.connect(url, function (err, db) { |
|
|
MongoClient.connect( |
|
|
if (err) throw err; |
|
|
url, |
|
|
var dbo = db.db("fluentdb"); |
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
dbo |
|
|
function (err, db) { |
|
|
.collection("test") |
|
|
if (err) throw err; |
|
|
.find({}) |
|
|
var dbo = db.db("fluentdb"); |
|
|
.toArray(function (err, result) { |
|
|
dbo |
|
|
if (err) throw err; |
|
|
.collection("test") |
|
|
// EPIDI EXW NESTED JSON PREPEI NA TO KANW PARSE DUO FORES
|
|
|
.find({}) |
|
|
var obj = JSON.parse(JSON.stringify(result)); |
|
|
.toArray(function (err, result) { |
|
|
|
|
|
if (err) throw err; |
|
|
obj.forEach((value) => { |
|
|
// EPIDI EXW NESTED JSON PREPEI NA TO KANW PARSE DUO FORES
|
|
|
if (value.log.includes("app_name")) { |
|
|
var obj = JSON.parse(JSON.stringify(result)); |
|
|
var tmp = JSON.parse(value.log); |
|
|
|
|
|
if (tmp.type == "out") { |
|
|
obj.forEach((value) => { |
|
|
tmp.type = '<div class="outtype" >' + tmp.type + "</div>"; |
|
|
if (value.log.includes("app_name")) { |
|
|
} else if (tmp.type == "err") { |
|
|
var tmp = JSON.parse(value.log); |
|
|
tmp.type = '<div class="errtype" >' + tmp.type + "</div>"; |
|
|
if (tmp.type == "out") { |
|
|
} |
|
|
tmp.type = '<div class="outtype" >' + tmp.type + "</div>"; |
|
|
jsonfinal.push(tmp); |
|
|
} else if (tmp.type == "err") { |
|
|
} else if (value.container_name == "/redisserver") { |
|
|
tmp.type = '<div class="errtype" >' + tmp.type + "</div>"; |
|
|
var tmplog = value; |
|
|
} |
|
|
//timestamp
|
|
|
jsonfinal.push(tmp); |
|
|
var time = tmplog.time; |
|
|
} else if (value.container_name == "/redisserver") { |
|
|
var tmp = { |
|
|
var tmplog = value; |
|
|
message: tmplog.log, |
|
|
//timestamp
|
|
|
timestamp: time, |
|
|
var time = tmplog.time; |
|
|
type: "<div class= 'outtype'>out</div>", |
|
|
var tmp = { |
|
|
process_id: "Unknown", |
|
|
message: tmplog.log, |
|
|
app_name: "redis", |
|
|
timestamp: time, |
|
|
}; |
|
|
type: "<div class= 'outtype'>out</div>", |
|
|
jsonfinal.push(tmp); |
|
|
process_id: "Unknown", |
|
|
} |
|
|
app_name: "redis", |
|
|
// else if (value.container_name == "/mongo") {
|
|
|
}; |
|
|
// var tmplog = JSON.parse(value.log);
|
|
|
jsonfinal.push(tmp); |
|
|
// var msg2 = tmplog.msg;
|
|
|
|
|
|
|
|
|
|
|
|
// //timestam
|
|
|
|
|
|
// var time = tmplog.t;
|
|
|
|
|
|
// time = time.$date;
|
|
|
|
|
|
// var tmp = {
|
|
|
|
|
|
// message: msg2,
|
|
|
|
|
|
// timestamp: time,
|
|
|
|
|
|
// type: "<div class= 'outtype'>out</div>",
|
|
|
|
|
|
// process_id: "Unknown",
|
|
|
|
|
|
// app_name: "Mongo",
|
|
|
|
|
|
// };
|
|
|
|
|
|
// jsonfinal.push(tmp);
|
|
|
|
|
|
// }
|
|
|
|
|
|
}); |
|
|
|
|
|
//console.log("Sending Data: " + jsonfinal);
|
|
|
|
|
|
if (sortname == "type") { |
|
|
|
|
|
jsonfinal.sort(function (a, b) { |
|
|
|
|
|
if (sortorder == "asc") { |
|
|
|
|
|
return a.type.localeCompare(b.type); |
|
|
|
|
|
} else { |
|
|
|
|
|
return b.type.localeCompare(a.type); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} else if (sortname == "message") { |
|
|
|
|
|
jsonfinal.sort(function (a, b) { |
|
|
|
|
|
if (sortorder == "asc") { |
|
|
|
|
|
return a.message.localeCompare(b.message); |
|
|
|
|
|
} else { |
|
|
|
|
|
return b.message.localeCompare(a.message); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} else if (sortname == "time") { |
|
|
|
|
|
jsonfinal.sort(function (a, b) { |
|
|
|
|
|
if (sortorder == "asc") { |
|
|
|
|
|
return a.timestamp.localeCompare(b.timestamp); |
|
|
|
|
|
} else { |
|
|
|
|
|
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); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
// 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: "<div class= 'outtype'>out</div>",
|
|
|
|
|
|
// process_id: "Unknown",
|
|
|
|
|
|
// app_name: "Mongo",
|
|
|
|
|
|
// };
|
|
|
|
|
|
// jsonfinal.push(tmp);
|
|
|
|
|
|
// }
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
//console.log("Sending Data: " + jsonfinal);
|
|
|
//Pagination
|
|
|
if (sortname == "type") { |
|
|
var total = jsonfinal.length; |
|
|
jsonfinal.sort(function (a, b) { |
|
|
var perpage = per_page; |
|
|
if (sortorder == "asc") { |
|
|
var lastpage = total / perpage; |
|
|
return a.type.localeCompare(b.type); |
|
|
if (lastpage <= 1) { |
|
|
} else { |
|
|
lastpage = 1; |
|
|
return b.type.localeCompare(a.type); |
|
|
} else { |
|
|
} |
|
|
lastpage++; |
|
|
}); |
|
|
} |
|
|
} else if (sortname == "message") { |
|
|
lastpage = Math.trunc(lastpage); |
|
|
jsonfinal.sort(function (a, b) { |
|
|
var next = page + 1; |
|
|
if (sortorder == "asc") { |
|
|
if (next >= lastpage) { |
|
|
return a.message.localeCompare(b.message); |
|
|
next = lastpage; |
|
|
} else { |
|
|
} |
|
|
return b.message.localeCompare(a.message); |
|
|
var prev = page - 1; |
|
|
} |
|
|
if (prev == 0) { |
|
|
}); |
|
|
prev = 1; |
|
|
} else if (sortname == "time") { |
|
|
} |
|
|
jsonfinal.sort(function (a, b) { |
|
|
var from = (page - 1) * perpage + 1; |
|
|
if (sortorder == "asc") { |
|
|
var to = perpage * page; |
|
|
return a.timestamp.localeCompare(b.timestamp); |
|
|
var mypage = new Object(); |
|
|
} else { |
|
|
var links = ` |
|
|
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; |
|
|
|
|
|
var perpage = per_page; |
|
|
|
|
|
var lastpage = total / perpage; |
|
|
|
|
|
if (lastpage <= 1) { |
|
|
|
|
|
lastpage = 1; |
|
|
|
|
|
} else { |
|
|
|
|
|
lastpage++; |
|
|
|
|
|
} |
|
|
|
|
|
lastpage = Math.trunc(lastpage); |
|
|
|
|
|
var next = page + 1; |
|
|
|
|
|
if (next >= lastpage) { |
|
|
|
|
|
next = lastpage; |
|
|
|
|
|
} |
|
|
|
|
|
var prev = page - 1; |
|
|
|
|
|
if (prev == 0) { |
|
|
|
|
|
prev = 1; |
|
|
|
|
|
} |
|
|
|
|
|
var from = (page - 1) * perpage + 1; |
|
|
|
|
|
var to = perpage * page; |
|
|
|
|
|
var mypage = new Object(); |
|
|
|
|
|
var links = ` |
|
|
{ |
|
|
{ |
|
|
"pagination": { |
|
|
"pagination": { |
|
|
"total": ${total}, |
|
|
"total": ${total}, |
|
@ -340,21 +350,22 @@ app.get("/test2", cors(corsOptions), (req, res) => { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
`;
|
|
|
`;
|
|
|
mypage.links = JSON.parse(links); |
|
|
mypage.links = JSON.parse(links); |
|
|
from--; |
|
|
from--; |
|
|
mypage.data = jsonfinal.slice(from, to); |
|
|
mypage.data = jsonfinal.slice(from, to); |
|
|
var RES = new Object(); |
|
|
var RES = new Object(); |
|
|
RES.code = req.query["action"]; |
|
|
RES.code = req.query["action"]; |
|
|
RES.token = req.query["token"]; |
|
|
RES.token = req.query["token"]; |
|
|
RES.error = false; |
|
|
RES.error = false; |
|
|
RES.error_msg = "ok"; |
|
|
RES.error_msg = "ok"; |
|
|
RES.data = mypage; |
|
|
RES.data = mypage; |
|
|
|
|
|
|
|
|
// console.log("Sending Data: " + jsonfinal);
|
|
|
// console.log("Sending Data: " + jsonfinal);
|
|
|
res.json(RES.data); |
|
|
res.json(RES.data); |
|
|
db.close(); |
|
|
db.close(); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
|
|
|
); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
console.log("reading from db...."); |
|
|
console.log("reading from db...."); |
|
@ -757,11 +768,15 @@ async function checkstream(data) { |
|
|
console.log("Creating Stream...."); |
|
|
console.log("Creating Stream...."); |
|
|
|
|
|
|
|
|
var url = "mongodb://mongo:27017/"; |
|
|
var url = "mongodb://mongo:27017/"; |
|
|
MongoClient.connect(url, function (err, db) { |
|
|
MongoClient.connect( |
|
|
if (err) throw err; |
|
|
url, |
|
|
var dbo = db.db("fluentdb"); |
|
|
{ useNewUrlParser: true, useUnifiedTopology: true }, |
|
|
dbo.collection("test", onCollectionNew.bind(data)); |
|
|
function (err, db) { |
|
|
}); |
|
|
if (err) throw err; |
|
|
|
|
|
var dbo = db.db("fluentdb"); |
|
|
|
|
|
dbo.collection("test", onCollectionNew.bind(data)); |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
// ***************************************************
|
|
|
// ***************************************************
|
|
|