multiconfig version update
This commit is contained in:
9
README.md
Normal file
9
README.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
set config file in config/config.json
|
||||||
|
|
||||||
|
for fromlog config
|
||||||
|
logs go in config/fromlog/logs
|
||||||
|
datadefinitions in config/fromlogs/datadefintions
|
||||||
|
|
||||||
|
program save own data in program-data folder
|
||||||
|
|
||||||
|
launch with: node index.js in root folder
|
||||||
9
config/config.json
Normal file
9
config/config.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"modifier":"fromlog",
|
||||||
|
"file":"file",
|
||||||
|
"logic":"filelogic.js",
|
||||||
|
"port":80,
|
||||||
|
"idle":10000
|
||||||
|
}
|
||||||
|
]
|
||||||
43
index.js
43
index.js
@@ -1,12 +1,39 @@
|
|||||||
var http = require('http');
|
var http = require('http');
|
||||||
var modifier = process.env.MODIFIER;
|
var path = require('path');
|
||||||
if (modifier){
|
var configs = require("./config/config.json");
|
||||||
modifier = require("./" + modifier );
|
|
||||||
modifier.init();
|
configs.forEach(function(config){
|
||||||
|
var modifier= config.modifier;
|
||||||
|
if (modifier=="fromlog"){
|
||||||
|
var file = config.file;
|
||||||
|
var logic = config.logic;
|
||||||
|
var port = config.port;
|
||||||
|
var idle = config.idle;
|
||||||
|
if (isNaN(idle)){
|
||||||
|
idle = 10000;
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
fromlog(file,logic,port,idle);
|
||||||
|
console.log("Launched configuration:" + modifier + ";" + file);
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Error launching configuration:" + modifier + ";" + file+ ";Error:" + error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function fromlog(file,logic,port,idle){
|
||||||
|
delete require.cache[require.resolve("./plugins/fromlog/index.js")];
|
||||||
|
var modifierexec = require("./plugins/fromlog/index.js");
|
||||||
|
modifierexec.init(file,logic,idle);
|
||||||
|
createserver(modifierexec,port);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createserver (modifierexec,port){
|
||||||
|
|
||||||
http.createServer(function(req,res){
|
http.createServer(function(req,res){
|
||||||
res.writeHead(200,{"Content-Type": "text/plain"});
|
res.writeHead(200,{"Content-Type": "text/plain"});
|
||||||
var data = modifier.data();
|
var data = modifierexec.data();
|
||||||
var body = "";
|
var body = "";
|
||||||
var globallabelstring = "";
|
var globallabelstring = "";
|
||||||
if (data.__labels){
|
if (data.__labels){
|
||||||
@@ -55,8 +82,8 @@ if (modifier){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.end(body);
|
res.end(body);
|
||||||
}).listen(80);
|
}).listen(port);
|
||||||
} else {
|
|
||||||
console.log("No modifier selected");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,24 @@
|
|||||||
var datadefinition = require("./fromlog.datadefinition" );
|
var path = require('path');
|
||||||
|
var datadefinition;
|
||||||
|
var filepath;
|
||||||
|
var counterpath;
|
||||||
var data = {};
|
var data = {};
|
||||||
var fs = require('fs'),
|
var fs = require('fs'),
|
||||||
bite_size = 4096,
|
bite_size = 4096,
|
||||||
save_interval_or_retry = 10000,
|
save_interval_or_retry,
|
||||||
filereadbytes,
|
filereadbytes,
|
||||||
tempdata = "",
|
tempdata = "",
|
||||||
fd;
|
fd;
|
||||||
|
|
||||||
function init(){
|
function init(file,logic,idle){
|
||||||
fs.readFile('fromlog.counter',function(err, content){
|
delete require.cache[require.resolve('../../config/fromlog/datadefinitions/' + logic)];
|
||||||
|
datadefinition = require('../../config/fromlog/datadefinitions/' + logic);
|
||||||
|
|
||||||
|
save_interval_or_retry = idle;
|
||||||
|
|
||||||
|
filepath = path.resolve(__dirname, '../../config/fromlog/logs/' + file);
|
||||||
|
|
||||||
|
fs.readFile(filepath,function(err, content){
|
||||||
if (err){
|
if (err){
|
||||||
filereadbytes = 0;
|
filereadbytes = 0;
|
||||||
}else{
|
}else{
|
||||||
@@ -20,7 +30,8 @@ function init(){
|
|||||||
var oldfilereadbytes = filereadbytes;
|
var oldfilereadbytes = filereadbytes;
|
||||||
setInterval(function(){
|
setInterval(function(){
|
||||||
if (filereadbytes != oldfilereadbytes){
|
if (filereadbytes != oldfilereadbytes){
|
||||||
fs.writeFile("fromlog.counter", filereadbytes.toString(),function(err){});
|
counterpath = path.resolve(__dirname, '../../program-data/fromlog/counters/' + file);
|
||||||
|
fs.writeFile(counterpath, filereadbytes.toString(),function(err){});
|
||||||
oldfilereadbytes = filereadbytes;
|
oldfilereadbytes = filereadbytes;
|
||||||
}
|
}
|
||||||
}, save_interval_or_retry);
|
}, save_interval_or_retry);
|
||||||
@@ -30,7 +41,7 @@ function init(){
|
|||||||
|
|
||||||
|
|
||||||
function openandreadsome(){
|
function openandreadsome(){
|
||||||
fs.open('fromlog.file', 'r',function(err, file){
|
fs.open(filepath, 'r',function(err, file){
|
||||||
if (err){
|
if (err){
|
||||||
return setTimeout(openandreadsome, save_interval_or_retry);
|
return setTimeout(openandreadsome, save_interval_or_retry);
|
||||||
}
|
}
|
||||||
@@ -84,8 +95,8 @@ function processsome(actualbytesread, buff) {
|
|||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init: function () {
|
init: function (file,logic,idle) {
|
||||||
init();
|
init(file,logic,idle);
|
||||||
data= datadefinition.init(data);
|
data= datadefinition.init(data);
|
||||||
},
|
},
|
||||||
data: function () {
|
data: function () {
|
||||||
Reference in New Issue
Block a user