Changed superbuffer to rollover and client improvements

master
Ringo Watanabe 6 years ago
parent 19c440d978
commit 05d5ee0279

@ -11,7 +11,7 @@ var config = {
BACKEND_SOCKET: "./backend/rtbw.sock",
BUFFER_PURGE_TIME: 1800000, //30 minutes
SUPERBUFFER_PURGE_TIME: 43200000 //12 hours
SUPERBUFFER_SIZE: 24
};
module.exports = config;

@ -2,15 +2,21 @@ const Cycle = require("./cycle").Cycle;
const logger = require("./logger");
class CycleBuffer {
constructor(purgeTime) {
constructor(purgeTime, fixed=false) {
this.time = purgeTime;
this.buffer=[];
var th = this;
this.onclear = function(sp) {};
if(fixed) {
this.fixed=true;
}
else {
this.inter = setInterval(function() {
th.purge();
}, this.time);
}
}
purge()
{
@ -20,6 +26,8 @@ class CycleBuffer {
add(cycle) {
this.buffer.push(cycle);
if(this.fixed && this.buffer.length>=this.time)
this.buffer.shift();
}
all() {
@ -31,6 +39,7 @@ class CycleBuffer {
return ret;
}
close() {
if(this.inter)
clearInterval(this.inter);
this.buffer.length=0;
}

@ -75,7 +75,7 @@ var allTime = new _cycle.Cycle();
var allTimeAverage = new _cycle.Cycle();
var allTimeAverageN = 0;
var buffer = new CycleBuffer(config.BUFFER_PURGE_TIME);
var superbuffer = new CycleBuffer(config.SUPERBUFFER_PURGE_TIME);
var superbuffer = new CycleBuffer(config.SUPERBUFFER_SIZE, true);
var beInfo = null;
var upSince = new Date();
@ -96,7 +96,7 @@ superbuffer.onclear = function(bu) {
};
logger.log("Buffer set to clear every "+(config.BUFFER_PURGE_TIME/1000/60)+" minutes");
logger.log("Superbuffer set to clear every "+(config.SUPERBUFFER_PURGE_TIME/1000/60)+" minutes");
logger.log("Superbuffer set to fill at "+(config.SUPERBUFFER_SIZE)+" entries");
process.execFile(config.PYTHON_EXECUTABLE, [config.RTBWCTL_FILENAME, config.BACKEND_SOCKET, "info"], function(error,stdout,stderr) {
@ -128,7 +128,7 @@ var server = http.createServer(function(req, res) {
res.end(JSON.stringify({
interval: config.POLL_INTERVAL,
purgeInterval: config.BUFFER_PURGE_TIME,
superPurgeInterval: config.SUPERBUFFER_PURGE_TIME,
superPurgeInterval: config.SUPERBUFFER_SIZE,
backendInterval: beInfo.timeout,
board: beInfo.board,
upSince: upSince
@ -213,10 +213,6 @@ wss.on('request', function(req) { //why isn't this getting called?
});
wss.on('connection', function (ws) {
/*ws.on('message', function (message) {
ws.send("Received: " + message);
});*/
var f = function(cycle) {
ws.send(JSON.stringify({type: "cycle", data: cycle}));
};

@ -19,7 +19,7 @@
Cycle interval: <em id='interval'></em><br />
Archiver interval: <em id='binterval'></em><br />
Server buffer purge interval: <em id='pinterval'></em><br />
Server aggregate buffer purge interval: <em id='spinterval'></em><br />
Server aggregate buffer max size: <em id='spinterval'></em><br />
</p>
<hr></hr>
<h2>Total uptime stats</h2>

@ -31,6 +31,8 @@ const maxEntries= client.preloadCycles;
var cycleTableRollover = null;
var sessionAverageRollover = null;
var cyTotal=0;
function setStatus(str)
{
$('#status').text(str);
@ -74,7 +76,7 @@ function createNewCandle(charts, close)
function createNewLinePoint(charts, data)
{
if(charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1]) {
if(charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1] !==undefined) {
charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1] = data.number;
charts.agline.data.datasets[1].data[charts.agline.data.datasets[0].data.length-1] = data.number/data._cycles;
}
@ -305,12 +307,18 @@ function graphCycle(data, charts,update=true)
//Line
//Total posts
if(charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1]) {
charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1] += data.number;
if(client.superBuffer.length>0)
charts.agline.data.datasets[1].data[charts.agline.data.datasets[0].data.length-1] = charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1] /client.superBuffer[client.superBuffer.length-1]._cycles;
if(update)
var lgc = charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1];
//console.log(lgc+" "+data.number);
if(lgc || lgc===0) {
charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1]= lgc+ data.number;
if(cyTotal>0)
{
charts.agline.data.datasets[1].data[charts.agline.data.datasets[1].data.length-1] = (lgc+ data.number)/cyTotal;
}
if(update) {
charts.agline.update();
//console.log("Update to "+charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1]);
}
}
}
@ -782,13 +790,15 @@ function begin() {
client.superGrapher = function(data) {
//TODO: new supercycle
//add_new_candle(g_chartsSuper(), data);
//add_new_candle(g_chartsSuper(), data)
cyTotal = 0;
createNewCandle(g_chartsSuper(), data._candle.number.c);
createNewLinePoint(g_chartsSuper(), data);
};
client.start(function(data) {
//on message function
cyTotal += 1;
updateAllTime(g_charts(),data);
graphCycle(data, g_chartsSession());
@ -797,7 +807,7 @@ function begin() {
$('#interval').text(client.info.interval+" ms");
$('#binterval').text(client.info.backendInterval+" s");
$('#pinterval').text((client.info.purgeInterval/1000/60).toFixed(2)+" m");
$('#spinterval').text((client.info.superPurgeInterval/1000/60/60).toFixed(2)+" h");
$('#spinterval').text( (((client.info.purgeInterval/1000/60)*client.info.superPurgeInterval)/60).toFixed(2)+" h");
$('#board').text(client.info.board);
$('#uptime').text(fixtime2(new Date(client.info.upSince)));
$('#s_started').text(fixtime2(new Date()));
@ -902,6 +912,7 @@ function begin() {
chartAGLine.data.labels.shift();
chartAGLine.data.datasets[0].data.shift();
chartAGLine.data.datasets[1].data.shift();
chartAGLine.update();
});

Loading…
Cancel
Save