mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 00:23:12 +09:00
UPS display plugin that shows on master
This commit is contained in:
1 parent
960cd79be3
commit
844bfebcd7
4 files changed
+80
No files matched your search
@@ -0,0 +1,38 @@
|
||||
const needle = require("needle");
|
||||
|
||||
console.log("/silent-command game.print('UPSdisplay enabled')\n");
|
||||
|
||||
setInterval(function(){
|
||||
console.log("/silent-command game.write_file('UPSdisplay.txt', game.tick, true, 0)\n");
|
||||
},1000);
|
||||
var config = {};
|
||||
process.stdin.setEncoding('utf8');
|
||||
let historicalTicks = [];
|
||||
process.stdin.on('readable', () => {
|
||||
var chunk = process.stdin.read();
|
||||
if (chunk !== null && !isNaN(chunk) && !chunk.includes("{")){
|
||||
// console.log("Tick: " + chunk);
|
||||
historicalTicks[historicalTicks.length] = {tick:Number(chunk), timestamp:Date.now()};
|
||||
if(historicalTicks.length > 30){
|
||||
historicalTicks.shift(); // delete last element in array (position 0);
|
||||
}
|
||||
} else {
|
||||
config = JSON.parse(chunk);
|
||||
}
|
||||
});
|
||||
process.stdin.on('end', () => {
|
||||
process.stdout.write('end');
|
||||
});
|
||||
|
||||
// Post average UPS
|
||||
setInterval(function(){
|
||||
if(historicalTicks && historicalTicks[0]){
|
||||
let timePeriod = historicalTicks[historicalTicks.length-1].timestamp - historicalTicks[0].timestamp;
|
||||
let ticksInPeriod = historicalTicks[historicalTicks.length-1].tick - historicalTicks[0].tick;
|
||||
let UPS = Math.round(ticksInPeriod / (timePeriod/1000));
|
||||
// console.log("UPS: " + UPS);
|
||||
needle.post(config.masterIP+':'+config.masterPort+'/api/editSlaveMeta', {slaveID: config.unique, password: config.clientPassword, meta: {UPS:UPS}}, function(err, resp) {
|
||||
// success?
|
||||
});
|
||||
}
|
||||
}, 10000);
|
||||
Reference in new issue
Block a user