mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 16:13:12 +09:00
1 parent
03bb6a8063
commit
cc6ff973b5
2 files changed
+53
-2
No files matched your search
@@ -437,6 +437,7 @@ function instanceManagement() {
|
|||||||
setInterval(function(){
|
setInterval(function(){
|
||||||
fs.readFile(instancedirectory + "/script-output/flows.txt", {encoding: "utf8"}, function(err, data) {
|
fs.readFile(instancedirectory + "/script-output/flows.txt", {encoding: "utf8"}, function(err, data) {
|
||||||
if(!err && data) {
|
if(!err && data) {
|
||||||
|
let timestamp = Date.now();
|
||||||
data = data.split("\n");
|
data = data.split("\n");
|
||||||
let flowStats = [];
|
let flowStats = [];
|
||||||
for(let i = 0; i < data.length; i++) {
|
for(let i = 0; i < data.length; i++) {
|
||||||
@@ -466,9 +467,9 @@ function instanceManagement() {
|
|||||||
//console.log(payload[key])
|
//console.log(payload[key])
|
||||||
}
|
}
|
||||||
console.log("Recorded flows, copper plate since last time: " + payload["copper-plate"]);
|
console.log("Recorded flows, copper plate since last time: " + payload["copper-plate"]);
|
||||||
/*needle.post(config.masterIP + ":" + config.masterPort + '/uploadMod', payload, function (err, response, body) {
|
needle.post(config.masterIP + ":" + config.masterPort + '/logStats', {timestamp: timestamp, slaveID: instanceconfig.unique,data: payload}, function (err, response, body) {
|
||||||
// we did it, keep going
|
// we did it, keep going
|
||||||
}*/
|
})
|
||||||
}
|
}
|
||||||
oldFlowStats = totalFlows
|
oldFlowStats = totalFlows
|
||||||
fs.writeFileSync(instancedirectory + "/script-output/flows.txt", "");
|
fs.writeFileSync(instancedirectory + "/script-output/flows.txt", "");
|
||||||
|
|||||||
@@ -29,9 +29,17 @@ app.use(express.static(masterModFolder));
|
|||||||
// set up database
|
// set up database
|
||||||
var Datastore = require('nedb');
|
var Datastore = require('nedb');
|
||||||
db = {};
|
db = {};
|
||||||
|
|
||||||
|
// database for items in system
|
||||||
db.items = new Datastore({ filename: 'database/items.db', autoload: true });
|
db.items = new Datastore({ filename: 'database/items.db', autoload: true });
|
||||||
|
|
||||||
|
// in memory database for combinator signals
|
||||||
db.signals = new Datastore({ filename: 'database/signals.db', autoload: true, inMemoryOnly: true});
|
db.signals = new Datastore({ filename: 'database/signals.db', autoload: true, inMemoryOnly: true});
|
||||||
db.signals.ensureIndex({ fieldName: 'time', expireAfterSeconds: 3600 }, function (err) {});
|
db.signals.ensureIndex({ fieldName: 'time', expireAfterSeconds: 3600 }, function (err) {});
|
||||||
|
|
||||||
|
// production chart database
|
||||||
|
db.flows = new Datastore({ filename: "database/flows.db", autoload: true})
|
||||||
|
db.flows.ensureIndex({ fieldName: "slaveID", expireAfterSeconds: 2592000}); // expire after 30 days
|
||||||
// db.slaves = new Datastore({ filename: 'database/slaves.db', autoload: true, inMemoryOnly: false});
|
// db.slaves = new Datastore({ filename: 'database/slaves.db', autoload: true, inMemoryOnly: false});
|
||||||
|
|
||||||
db.items.additem = function(object) {
|
db.items.additem = function(object) {
|
||||||
@@ -180,6 +188,48 @@ app.get("/inventory", function(req, res) {
|
|||||||
res.send(docs);
|
res.send(docs);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// post flowstats here for production graphs
|
||||||
|
// {timestamp: Date, slaveID: string, data: {"item":number}}
|
||||||
|
app.post("/logStats", function(req,res) {
|
||||||
|
if(typeof req.body == "object" && req.body.slaveID && req.body.timestamp && req.body.data) {
|
||||||
|
db.flows.insert({
|
||||||
|
slaveID: req.body.slaveID,
|
||||||
|
timestamp: req.body.timestamp,
|
||||||
|
data: req.body.data,
|
||||||
|
});
|
||||||
|
console.log("inserted: " + req.body.slaveID + " | " + req.body.timestamp)
|
||||||
|
} else {
|
||||||
|
res.send("failure")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// {slaveID: string, fromTime: Date, toTime, Date}
|
||||||
|
app.post("/getStats", function(req,res) {
|
||||||
|
if(typeof req.body == "object" && req.body.slaveID) {
|
||||||
|
// if not specified, get stats for last 24 hours
|
||||||
|
if(!req.body.fromTime) {
|
||||||
|
req.body.fromTime = Date.now() - 86400000 // 24 hours in MS
|
||||||
|
}
|
||||||
|
if(!req.body.toTime) {
|
||||||
|
req.body.toTime = Date.now();
|
||||||
|
}
|
||||||
|
db.flows.find({
|
||||||
|
$and: [
|
||||||
|
{
|
||||||
|
slaveID: req.body.slaveID,
|
||||||
|
}, {
|
||||||
|
timestamp: {
|
||||||
|
$gte: req.body.toTime,
|
||||||
|
$lt: req.body.fromTime,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, function(err, docs) {
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// endpoint for getting the chartjs library
|
// endpoint for getting the chartjs library
|
||||||
app.get("/chart.js", function(req, res) {
|
app.get("/chart.js", function(req, res) {
|
||||||
res.header("Access-Control-Allow-Origin", "*");
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
|
|||||||
Reference in new issue
Block a user