updated statist to download project from repo
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
FROM centos: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
|
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 /
|
COPY docker-entrypoint.sh /
|
||||||
WORKDIR /statist
|
WORKDIR /statist
|
||||||
ENTRYPOINT ["/docker-entrypoint.sh"]
|
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||||
|
|||||||
@@ -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;
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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");
|
|
||||||
}
|
|
||||||
|
|
||||||
38
statist/statist/package-lock.json
generated
38
statist/statist/package-lock.json
generated
@@ -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="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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": {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user