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 modifier = process.env.MODIFIER;
|
||||
if (modifier){
|
||||
modifier = require("./" + modifier );
|
||||
modifier.init();
|
||||
var path = require('path');
|
||||
var configs = require("./config/config.json");
|
||||
|
||||
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){
|
||||
res.writeHead(200,{"Content-Type": "text/plain"});
|
||||
var data = modifier.data();
|
||||
var data = modifierexec.data();
|
||||
var body = "";
|
||||
var globallabelstring = "";
|
||||
if (data.__labels){
|
||||
@@ -55,8 +82,8 @@ if (modifier){
|
||||
}
|
||||
}
|
||||
res.end(body);
|
||||
}).listen(80);
|
||||
} else {
|
||||
console.log("No modifier selected");
|
||||
}).listen(port);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
var datadefinition = require("./fromlog.datadefinition" );
|
||||
var path = require('path');
|
||||
var datadefinition;
|
||||
var filepath;
|
||||
var counterpath;
|
||||
var data = {};
|
||||
var fs = require('fs'),
|
||||
bite_size = 4096,
|
||||
save_interval_or_retry = 10000,
|
||||
save_interval_or_retry,
|
||||
filereadbytes,
|
||||
tempdata = "",
|
||||
fd;
|
||||
|
||||
function init(){
|
||||
fs.readFile('fromlog.counter',function(err, content){
|
||||
function init(file,logic,idle){
|
||||
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){
|
||||
filereadbytes = 0;
|
||||
}else{
|
||||
@@ -20,7 +30,8 @@ function init(){
|
||||
var oldfilereadbytes = filereadbytes;
|
||||
setInterval(function(){
|
||||
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;
|
||||
}
|
||||
}, save_interval_or_retry);
|
||||
@@ -30,7 +41,7 @@ function init(){
|
||||
|
||||
|
||||
function openandreadsome(){
|
||||
fs.open('fromlog.file', 'r',function(err, file){
|
||||
fs.open(filepath, 'r',function(err, file){
|
||||
if (err){
|
||||
return setTimeout(openandreadsome, save_interval_or_retry);
|
||||
}
|
||||
@@ -84,8 +95,8 @@ function processsome(actualbytesread, buff) {
|
||||
|
||||
|
||||
module.exports = {
|
||||
init: function () {
|
||||
init();
|
||||
init: function (file,logic,idle) {
|
||||
init(file,logic,idle);
|
||||
data= datadefinition.init(data);
|
||||
},
|
||||
data: function () {
|
||||
Reference in New Issue
Block a user