Browse Source

mongo tail

master
zeus 4 years ago
parent
commit
b5e5a0d9d2
  1. 66
      swarmlab-app/src/run/app.js

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

@ -6,13 +6,16 @@ var http = require('http').Server(app);
var https = require('https'); var https = require('https');
var io = require('socket.io')(http); var io = require('socket.io')(http);
var chokidar = require("chokidar"); var mongodb = require('mongodb');
var logpath = "/var/lab/playground-serverlogs"; MongoClient = mongodb.MongoClient;
var watcher = chokidar.watch(logpath, {
ignored: /[\/\\]\./, //var chokidar = require("chokidar");
awaitWriteFinish: true, //var logpath = "/var/lab/playground-serverlogs";
persistent: true //var watcher = chokidar.watch(logpath, {
}); // ignored: /[\/\\]\./,
// awaitWriteFinish: true,
// persistent: true
// });
var async = require("async"); var async = require("async");
@ -251,8 +254,14 @@ app.get('/run', [
cors(corsOptions), (req, res, next) => { cors(corsOptions), (req, res, next) => {
var RES = new Object(); var RES = new Object();
RES.code = req.query["code"] RES.code = req.query["filter"]
console.error('socket GET from client ' + RES.code); RES.token = req.query["filter"]
var isvalid = await checkToken(RES.token);
if(isvalid.action == 'ok'){
console.log("Authserver ok " + RES.token);
}else{
console.log("Authserver no " + RES.token);
}
RES.error = false RES.error = false
RES.error_msg = "ok" RES.error_msg = "ok"
res.json(RES) res.json(RES)
@ -274,9 +283,9 @@ cors(corsOptions), (req, res, next) => {
//console.log(JSON.stringify(req.headers)); //console.log(JSON.stringify(req.headers));
//console.log(JSON.stringify(req.body)); //console.log(JSON.stringify(req.body));
console.log("mongo "+JSON.stringify(req.body)); //console.log("mongo "+JSON.stringify(req.body));
console.log("LOG "+JSON.stringify(req.body[0].message)); //console.log("LOG "+JSON.stringify(req.body[0].message));
console.log("PATH "+JSON.stringify(req.body[0].tailed_path)); //console.log("PATH "+JSON.stringify(req.body[0].tailed_path));
for (var i = 0; i < req.body.length; i++){ for (var i = 0; i < req.body.length; i++){
//var getpath = await onlogfile(req.body[i].tailed_path) //var getpath = await onlogfile(req.body[i].tailed_path)
@ -352,11 +361,42 @@ cors(corsOptions), (req, res, next) => {
}); });
// *************************************************** // ***************************************************
// rocket // socket
// *************************************************** // ***************************************************
io.origins('*:*') // for latest version io.origins('*:*') // for latest version
function onCollection(err, collection) {
var cursor = collection.find({}, { tailable: true, awaitdata: true }),
cursorStream = cursor.stream(),
itemsProcessed = 0;
cursorStream.on('data', function (data) {
console.log(data.value);
itemsProcessed++;
});
setInterval(function () {
console.log('itemsProcessed', itemsProcessed);
}, 1000);
}
//function onConnected(err, db) {
// db.collection('log', onCollection);
//}
var mongourl = "mongodb://playgrounduser:efvvnuioervefSDFSGYGHRDFVsdfergvssppiiedifhwincvinviw_dbfjbsifbsdkjfswuunscfudfgbbfvibqefwrvnine@ondemand_playground_mongo1:27017,ondemand_playground_mongo2:27017,ondemand_playground_mongo3:27017,ondemand_playground_mongo4:27017,ondemand_playground_mongo5:27017,ondemand_playground_mongo6:27017,ondemand_playground_mongo7:27017?replicaSet=rs1&tls=false"
//MongoClient.connect(mongourl, options).then((client) => {
MongoClient.connect(mongourl).then((client) => {
const db = client.db('fluent');
db.collection('log', onCollection);
// do database things
}).catch((error) => {
console.log("error " +JSON.stringify(error))
// handle connection errors
});
io.on('connection', s => { io.on('connection', s => {
console.error('socket connection'); console.error('socket connection');

Loading…
Cancel
Save