diff --git a/statist/Dockerfile b/statist/Dockerfile index 91bd67e..07cfd44 100644 --- a/statist/Dockerfile +++ b/statist/Dockerfile @@ -1,7 +1,7 @@ FROM centos:7 -RUN yum update -y && yum clean all +RUN yum update -y && yum install git -y && yum clean all RUN curl -sL https://rpm.nodesource.com/setup_14.x | bash - && yum install -y nodejs -COPY statist /statist +RUN git clone https://xgiovio@bitbucket.org/xgiovio/statist.git COPY docker-entrypoint.sh / WORKDIR /statist ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/statist/statist/fromlog.counter b/statist/statist/fromlog.counter deleted file mode 100644 index e69de29..0000000 diff --git a/statist/statist/fromlog.datadefinition b/statist/statist/fromlog.datadefinition deleted file mode 100644 index 33236aa..0000000 --- a/statist/statist/fromlog.datadefinition +++ /dev/null @@ -1,81 +0,0 @@ -module.exports = { - init: function(data){ - /* counter sample - data.name = {} - data.name.help = "help"; - data.name.type = "counter"; - data.name.value = 0; - */ - - /* gauge sample - data.name = {} - data.name.help = "help"; - data.name.type = "gauge"; - data.name.value= 0; - */ - - /* histogram sample - data.name = {} - data.name.help = "help"; - data.name.type = "histogram"; - data.name.bucket = {}; - data.name.sum = 0; - data.name.count = 0; - */ - - /* summary sample - - data.name = {} - data.name.help = "help"; - data.name.type = "summary"; - data.name.quantile = {}; - data.name.sum = 0; - data.name.count = 0; - */ - - - /* global label sample - data.__labels = {} - data.__labels.test1="aa"; - data.__labels.test2="bb"; - */ - - /* per metric label sample - data.name.labels = {} - data.name.labels.test3="aa"; - data.name.labels.test4="bb"; - */ - - - - return data; - }, - extractdatafromline: function(data,line){ - - /* counter sample - data.name.value++; - */ - - /* gauge sample - data.name.value= 10; - */ - - /* histogram sample - data.name.bucket["0.1"] = 3; - data.name.bucket["0.5"] = 5; - data.name.bucket["+Inf"] = 5; - data.name.sum = 1.3; - data.name.count = 5; - */ - - /* summary sample - data.name.quantile["0.95"] = 3; - data.name.sum = 1.3; - data.name.count = 5; - */ - - - return data; - - } -}; diff --git a/statist/statist/fromlog.file b/statist/statist/fromlog.file deleted file mode 100644 index e69de29..0000000 diff --git a/statist/statist/fromlog.js b/statist/statist/fromlog.js deleted file mode 100644 index a1b68af..0000000 --- a/statist/statist/fromlog.js +++ /dev/null @@ -1,101 +0,0 @@ -var datadefinition = require("./fromlog.datadefinition" ); -var data = {}; -var fs = require('fs'), - bite_size = 4096, - save_interval_or_retry = 10000, - filereadbytes, - tempdata = "", - fd; - -function init(){ - fs.readFile('fromlog.counter',function(err, content){ - if (err){ - filereadbytes = 0; - }else{ - filereadbytes = parseInt(content); - if (isNaN(filereadbytes)){ - filereadbytes = 0; - } - } - var oldfilereadbytes = filereadbytes; - setInterval(function(){ - if (filereadbytes != oldfilereadbytes){ - fs.writeFile("fromlog.counter", filereadbytes.toString(),function(err){}); - oldfilereadbytes = filereadbytes; - } - }, save_interval_or_retry); - openandreadsome(); - }); -} - - -function openandreadsome(){ - fs.open('fromlog.file', 'r',function(err, file){ - if (err){ - return setTimeout(openandreadsome, save_interval_or_retry); - } - fd = file; - fs.fstat(file, function(err, stats){ - if (err){ - return fs.close(file,function(err){ - setTimeout(openandreadsome, save_interval_or_retry); - }); - } - - readsome(stats); - }); - }); - -} - -function readsome(stats) { - - if(stats.size == filereadbytes) { - return fs.close(fd,function(err){ - setTimeout(openandreadsome, save_interval_or_retry); - }); - - }else { - if (stats.size < filereadbytes){ - filereadbytes =0; - } - fs.read(fd, Buffer.alloc(bite_size), 0, bite_size, filereadbytes, function(err, actualbytesread, buffer){ - if (err){ - return fs.close(fd,function(err){ - setTimeout(openandreadsome, save_interval_or_retry); - }); - - } - processsome(actualbytesread,buffer); - readsome(stats); - }); - - } - -} - -function processsome(actualbytesread, buff) { - var datastring = buff.toString('utf-8', 0, actualbytesread); - tempdata+=datastring; - var tempdatasplit = tempdata.split(/\r\n|\r|\n/); - for (var i = 0; i < tempdatasplit.length - 1; i++) { - data= datadefinition.extractdatafromline(data,tempdatasplit[i]); - } - tempdata = tempdatasplit[tempdatasplit.length - 1]; - filereadbytes+= actualbytesread; -} - - -module.exports = { - init: function () { - init(); - data= datadefinition.init(data); - }, - data: function () { - return data; - } -}; - - - - diff --git a/statist/statist/index.js b/statist/statist/index.js deleted file mode 100644 index 34ed472..0000000 --- a/statist/statist/index.js +++ /dev/null @@ -1,62 +0,0 @@ -var http = require('http'); -var modifier = process.env.MODIFIER; -if (modifier){ - modifier = require("./" + modifier ); - modifier.init(); - - http.createServer(function(req,res){ - res.writeHead(200,{"Content-Type": "text/plain"}); - var data = modifier.data(); - var body = ""; - var globallabelstring = ""; - if (data.__labels){ - for (var label in data.__labels) { - if (data.__labels.hasOwnProperty(label)){ - globallabelstring+=label + "=\"" + data.__labels[label] + "\","; - } - } - } - for (var prop in data) { - if (prop != "__labels" && data.hasOwnProperty(prop)) { - var labelstring = ""; - if (data[prop].labels){ - for (var label in data[prop].labels) { - if (data[prop].labels.hasOwnProperty(label)){ - labelstring+=label + "=\"" + data[prop].labels[label] + "\","; - } - } - } - body+="# HELP " + prop + " " + data[prop].help + "\n"; - if (data[prop].type == "counter"){ - body+="# TYPE " + prop + " counter" + "\n"; - body+=prop + "{" + globallabelstring + labelstring + "}" + " " + data[prop].value.toString() + "\n"; - }else if (data[prop].type == "gauge"){ - body+="# TYPE " + prop + " gauge" + "\n"; - body+=prop + "{" + globallabelstring + labelstring + "}" + " " + data[prop].value.toString() + "\n"; - }else if (data[prop].type == "histogram"){ - body+="# TYPE " + prop + " histogram" + "\n"; - for (var le in data[prop].bucket) { - if (data[prop].bucket.hasOwnProperty(le)){ - body+=prop + "_bucket{le=\""+ le + "\"," + globallabelstring + labelstring + "} " + data[prop].bucket[le].toString() + "\n"; - } - } - body+=prop + "_count{" + globallabelstring + labelstring + "} " + data[prop].count.toString()+ "\n"; - body+=prop + "_sum{" + globallabelstring + labelstring + "} " + data[prop].sum.toString()+ "\n"; - }else if (data[prop].type == "summary"){ - body+="# TYPE " + prop + " summary" + "\n"; - for (var q in data[prop].quantile) { - if (data[prop].quantile.hasOwnProperty(q)){ - body+=prop + "{quantile=\""+ q + "\"," + globallabelstring + labelstring + "} " + data[prop].quantile[q].toString() + "\n"; - } - } - body+=prop + "_count{" + globallabelstring + labelstring + "} " + data[prop].count.toString()+ "\n"; - body+=prop + "_sum{" + globallabelstring + labelstring + "} " + data[prop].sum.toString()+ "\n"; - } - } - } - res.end(body); - }).listen(80); -} else { - console.log("No modifier selected"); -} - diff --git a/statist/statist/package-lock.json b/statist/statist/package-lock.json deleted file mode 100644 index 83e1a1c..0000000 --- a/statist/statist/package-lock.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "statist", - "version": "1.0.0", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "version": "1.0.0", - "license": "ISC", - "dependencies": { - "http": "^0.0.1-security", - "line-reader": "^0.4.0" - } - }, - "node_modules/http": { - "version": "0.0.1-security", - "resolved": "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz", - "integrity": "sha512-RnDvP10Ty9FxqOtPZuxtebw1j4L/WiqNMDtuc1YMH1XQm5TgDRaR1G9u8upL6KD1bXHSp9eSXo/ED+8Q7FAr+g==" - }, - "node_modules/line-reader": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/line-reader/-/line-reader-0.4.0.tgz", - "integrity": "sha1-F+RIGNoKwzVnW6MAlU+U72cOZv0=" - } - }, - "dependencies": { - "http": { - "version": "0.0.1-security", - "resolved": "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz", - "integrity": "sha512-RnDvP10Ty9FxqOtPZuxtebw1j4L/WiqNMDtuc1YMH1XQm5TgDRaR1G9u8upL6KD1bXHSp9eSXo/ED+8Q7FAr+g==" - }, - "line-reader": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/line-reader/-/line-reader-0.4.0.tgz", - "integrity": "sha1-F+RIGNoKwzVnW6MAlU+U72cOZv0=" - } - } -} diff --git a/statist/statist/package.json b/statist/statist/package.json deleted file mode 100644 index 6bc3535..0000000 --- a/statist/statist/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "statist", - "version": "1.0.0", - "description": "collect data for prometheus", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "xgiovio", - "license": "ISC", - "dependencies": { - } -}