Change name from slaveID to instanceID for consistency accross endpoints

This commit is contained in:
Danielv123 committed 2017-11-21 21:39:41 +01:00
1 parent 7ece1af073
commit e2a795528f
7 files changed
+50 -50

No files matched your search

+1 -1
View File
@@ -619,7 +619,7 @@ function instanceManagement() {
}
}
console.log("Recorded flows, copper plate since last time: " + payload["copper-plate"]);
needle.post(config.masterIP + ":" + config.masterPort + '/api/logStats', {timestamp: timestamp, slaveID: instanceconfig.unique,data: payload}, function (err, response, body) {
needle.post(config.masterIP + ":" + config.masterPort + '/api/logStats', {timestamp: timestamp, instanceID: instanceconfig.unique,data: payload}, function (err, response, body) {
// we did it, keep going
});
}
+25 -25
View File
@@ -164,18 +164,18 @@ app.post("/api/getID", function(req,res) {
app.post("/api/editSlaveMeta", function(req,res) {
// request.body should be an object
// {slaveID, pass, meta:{x,y,z}}
// {instanceID, pass, meta:{x,y,z}}
if(req.body && req.body.slaveID && req.body.password && req.body.meta){
if(req.body && req.body.instanceID && req.body.password && req.body.meta){
// check for editing permissions
if(slaves[req.body.slaveID] && slaves[req.body.slaveID].rconPassword == req.body.password){
if(!slaves[req.body.slaveID].meta){
slaves[req.body.slaveID].meta = {};
if(slaves[req.body.instanceID] && slaves[req.body.instanceID].rconPassword == req.body.password){
if(!slaves[req.body.instanceID].meta){
slaves[req.body.instanceID].meta = {};
}
slaves[req.body.slaveID].meta = deepmerge(slaves[req.body.slaveID].meta, req.body.meta, {clone:true});
console.log("Updating slave: " + slaves[req.body.slaveID].mac + " : " + slaves[req.body.slaveID].serverPort+" at " + slaves[req.body.slaveID].publicIP);
slaves[req.body.instanceID].meta = deepmerge(slaves[req.body.instanceID].meta, req.body.meta, {clone:true});
console.log("Updating slave: " + slaves[req.body.instanceID].mac + " : " + slaves[req.body.instanceID].serverPort+" at " + slaves[req.body.instanceID].publicIP);
} else {
res.send("ERROR: Invalid slaveID or password")
res.send("ERROR: Invalid instanceID or password")
}
}
});
@@ -435,28 +435,28 @@ app.get("/api/inventoryAsObject", function(req, res) {
});
// post flowstats here for production graphs
// {timestamp: Date, slaveID: string, data: {"item":number}}
// {timestamp: Date, instanceID: string, data: {"item":number}}
/**
POST endpoint to log production graph statistics. Should contain a timestamp
gathered from Date.now(), a slaveID (also reffered to as "unique") and of
gathered from Date.now(), a instanceID (also reffered to as "unique") and of
course the timeSeries data.
@memberof clusterioMaster
@instance
@alias api/logStats
@param {object} JSON {timestamp: Date.now(), slaveID: "string", data: {"item": number}}
@param {object} JSON {timestamp: Date.now(), instanceID: "string", data: {"item": number}}
@returns {string} failure
*/
app.post("/api/logStats", function(req,res) {
if(typeof req.body == "object" && req.body.slaveID && req.body.timestamp && req.body.data) {
if(typeof req.body == "object" && req.body.instanceID && req.body.timestamp && req.body.data) {
if(Number(req.body.timestamp) != NaN){
req.body.timestamp = Number(req.body.timestamp);
db.flows.insert({
slaveID: req.body.slaveID,
instanceID: req.body.instanceID,
timestamp: req.body.timestamp,
data: req.body.data,
});
console.log("inserted: " + req.body.slaveID + " | " + req.body.timestamp);
console.log("inserted: " + req.body.instanceID + " | " + req.body.timestamp);
} else {
console.log("error invalid timestamp " + req.body.timestamp);
res.send("failure");
@@ -465,7 +465,7 @@ app.post("/api/logStats", function(req,res) {
res.send("failure");
}
});
// {slaveID: string, fromTime: Date, toTime, Date}
// {instanceID: string, fromTime: Date, toTime, Date}
/**
POST endpoint to get timeSeries statistics stored on the master. Can give production
graphs and other IO statistics.
@@ -481,7 +481,7 @@ app.post("/api/getStats", function(req,res) {
req.body = JSON.parse(req.body);
}
// console.log(req.body);
if(typeof req.body == "object" && req.body.slaveID && req.body.statistic === undefined) {
if(typeof req.body == "object" && req.body.instanceID && req.body.statistic === undefined) {
// if not specified, get stats for last 24 hours
if(!req.body.fromTime) {
req.body.fromTime = Date.now() - 86400000 // 24 hours in MS
@@ -491,7 +491,7 @@ app.post("/api/getStats", function(req,res) {
}
console.log("Looking... " + JSON.stringify(req.body));
db.flows.find({
slaveID: req.body.slaveID,
instanceID: req.body.instanceID,
}, function(err, docs) {
let entries = docs.filter(function (el) {
return el.timestamp <= req.body.toTime && el.timestamp >= req.body.fromTime;
@@ -499,12 +499,12 @@ app.post("/api/getStats", function(req,res) {
// console.log(entries);
res.send(entries);
});
} else if(typeof req.body == "object" && req.body.slaveID && typeof req.body.slaveID == "string" && req.body.itemName){
} else if(typeof req.body == "object" && req.body.instanceID && typeof req.body.instanceID == "string" && req.body.itemName){
if(req.body.statistic == "place"){
console.log(`sending place data for slaveID ${req.body.slaveID} ${req.body.itemName}`);
console.log(`sending place data for instanceID ${req.body.instanceID} ${req.body.itemName}`);
// Gather data
//console.log(recievedItemStatisticsBySlaveID)
let itemStats = recievedItemStatisticsBySlaveID[req.body.slaveID];
let itemStats = recievedItemStatisticsBySlaveID[req.body.instanceID];
if(itemStats === undefined){
res.send({statusForDebugging:"no data available"});
return false;
@@ -517,10 +517,10 @@ app.post("/api/getStats", function(req,res) {
data: data,
});
} else if(req.body.statistic == "remove"){
console.log(`sending remove data for slaveID ${req.body.slaveID} ${req.body.itemName}`);
console.log(`sending remove data for instanceID ${req.body.instanceID} ${req.body.itemName}`);
// Gather data
console.log(sentItemStatisticsBySlaveID)
let itemStats = sentItemStatisticsBySlaveID[req.body.slaveID];
let itemStats = sentItemStatisticsBySlaveID[req.body.instanceID];
console.log(itemStats)
if(typeof itemStats == "object"){
let data = itemStats.get(config.itemStats.maxEntries, req.body.itemName);
@@ -546,12 +546,12 @@ making up about 92% of the response body weight.)
@memberof clusterioMaster
@instance
@alias api/getTimelineStats
@param {object} JSON {slaveID:1941029, fromTime: ???, toTime: ???}
@param {object} JSON {instanceID:1941029, fromTime: ???, toTime: ???}
@returns {object[]} timeseries where each entry is a set point in time.
*/
app.post("/api/getTimelineStats", function(req,res) {
console.log(req.body);
if(typeof req.body == "object" && req.body.slaveID) {
if(typeof req.body == "object" && req.body.instanceID) {
// if not specified, get stats for last 24 hours
if(!req.body.fromTime) {
req.body.fromTime = Date.now() - 86400000 // 24 hours in MS
@@ -561,7 +561,7 @@ app.post("/api/getTimelineStats", function(req,res) {
}
console.log("Looking... " + JSON.stringify(req.body));
db.flows.find({
slaveID: req.body.slaveID,
instanceID: req.body.instanceID,
}, function(err, docs) {
if(err) {
console.error(err);
+1 -1
View File
@@ -32,7 +32,7 @@ setInterval(function(){
let UPS = Math.round(ticksInPeriod / (timePeriod/1000));
// console.log("UPS: " + UPS);
try{
needle.post(config.masterIP+':'+config.masterPort+'/api/editSlaveMeta', {slaveID: config.unique, password: config.clientPassword, meta: {UPS:UPS}}, function(err, resp) {
needle.post(config.masterIP+':'+config.masterPort+'/api/editSlaveMeta', {instanceID: config.unique, password: config.clientPassword, meta: {UPS:UPS}}, function(err, resp) {
// success?
});
} catch (err){
@@ -143,7 +143,7 @@ function pollInventories(outputFile){
//return "/silent-command "+'local a="{"for b,c in pairs(game.players)do if c.connected then local d=game.players[b].get_inventory(defines.inventory.player_main).get_contents()local e=game.players[b].get_quickbar().get_contents()local f={}for g=1,game.players[b].force.character_logistic_slot_count do f[g]=game.players[b].character.get_request_slot(g)end;a=a..b..":{inventory:{"for h,i in pairs(d)do a=a.."['+"'"+'"..h.."'+"'"+']:"..i..","end;for h,i in pairs(e)do a=a.."['+"'"+'"..h.."'+"'"+']:"..i..","end;a=a.."},requestSlots:{"for h,i in pairs(f)do a=a.."['+"'"+'"..i["name"].."'+"'"+']:"..i["count"]..", "end;a=a.."}},"end end;a=a.."}"game.write_file("'+outputFile+'",a)'
return '/silent-command '+'local a='+"'"+'{"players":{'+"'"+'local b=false;for c,d in pairs(game.players)do if d.connected then if b then a=a..'+"'"+','+"'"+'else b=true end;local e=game.players[c].get_inventory(defines.inventory.player_main).get_contents()local f=game.players[c].get_quickbar().get_contents()local g={}for h=1,game.players[c].force.character_logistic_slot_count do g[h]=game.players[c].character.get_request_slot(h)end;a=a..'+"'"+'"'+"'"+'..c..'+"'"+'":{"inventory":{'+"'"+'local i=false;for j,k in pairs(e)do if i then a=a..'+"'"+','+"'"+'else i=true end;a=a..'+"'"+'"'+"'"+'..j..'+"'"+'":'+"'"+'..k end;for j,k in pairs(f)do if i then a=a..'+"'"+','+"'"+'else i=true end;a=a..'+"'"+'"'+"'"+'..j..'+"'"+'":'+"'"+'..k end;a=a..'+"'"+'},"requestSlots":{'+"'"+'i=false;for j,k in pairs(g)do if i then a=a..'+"'"+','+"'"+'else i=true end;a=a..'+"'"+'"'+"'"+'..k['+"'"+'name'+"'"+']..'+"'"+'":'+"'"+'..k['+"'"+'count'+"'"+']end;a=a..'+"'"+'}}'+"'"+'end end;a=a.."}}"game.write_file("'+outputFile+'",a)'
/*
needle.post(config.masterIP+':'+config.masterPort+'/api/editSlaveMeta', {slaveID: config.unique, password: config.clientPassword, meta: {UPS:UPS}}, function(err, resp) {
needle.post(config.masterIP+':'+config.masterPort+'/api/editSlaveMeta', {instanceID: config.unique, password: config.clientPassword, meta: {UPS:UPS}}, function(err, resp) {
// success?
});
*/
+8 -8
View File
@@ -42,7 +42,7 @@ setInterval(function(){
indicator.style.backgroundColor = "yellow";
indicator.title = "Master server unavailable";
// compare with Math.floor(x/100000) allows us to check if they are within 10s of each other
} else if(Math.floor(slaveData[getParameterByName("slaveID")].time/100000) == Math.floor(Date.now()/100000)){
} else if(Math.floor(slaveData[getParameterByName("instanceID")].time/100000) == Math.floor(Date.now()/100000)){
indicator.style.backgroundColor = "green";
indicator.title = "Slave is online";
} else {
@@ -54,9 +54,9 @@ setInterval(function(){
populateSlaveInfo();
function populateSlaveInfo(){
let slaveID = getParameterByName("slaveID");
if(!slaveID){
throw "We need slaveID! GIVE US SLAVEID! ALL HAIL OUR NEW OVERLORDS!"
let instanceID = getParameterByName("instanceID");
if(!instanceID){
throw "We need instanceID! GIVE US SLAVEID! ALL HAIL OUR NEW OVERLORDS!"
}
getJSON("/api/slaves", function(err, slaveData){
/*
@@ -83,7 +83,7 @@ function populateSlaveInfo(){
"mac":"44-85-00-D2-7E-D6"}
}
*/
let slave = slaveData[slaveID];
let slave = slaveData[instanceID];
let HTML = "<div id='header'><div id='onlineIndicator'></div><h1>Name: " + slave.instanceName+"</h1>"
HTML += "<div class='subbar'><h6>Host: "+slave.mac+" </h6><h6>Unique: "+slave.unique+" </h6>"
if(slave.publicIP != "localhost"){
@@ -225,9 +225,9 @@ function maximizeTerminal(instant){
}
// ID of slave, ID of canvasjs div without #
function makeGraph(slaveID, selector) {
post("api/getStats", {slaveID: slaveID}, function(data){
//console.log("Building chart " + slaveID + " with this data:")
function makeGraph(instanceID, selector) {
post("api/getStats", {instanceID: instanceID}, function(data){
//console.log("Building chart " + instanceID + " with this data:")
//console.log(data)
if(data.length > 0) {
// find keys
+4 -4
View File
@@ -14,7 +14,7 @@ setTimeout(function() {
let seenDate = moment(Number(slaveData[key].time)).format('DD.MM.YY, hh:mm:ss')
HTML += "<div class='slaveBox'>";
HTML += '<div id="' + slaveData[key].unique + '" class="productionGraph" style="width: calc(100% - 200px);"></div>';
HTML += "<a href='nodeDetails?slaveID="+slaveData[key].unique+"'><h2>" + slaveData[key].instanceName + "</h2></a><p>ID: " + slaveData[key].unique + "</p><p>Last seen: "+seenDate+"</p><p>Online players: "+slaveData[key].playerCount+"</p><p>IP: "+slaveData[key].publicIP +":"+ slaveData[key].serverPort+"</p>"
HTML += "<a href='nodeDetails?instanceID="+slaveData[key].unique+"'><h2>" + slaveData[key].instanceName + "</h2></a><p>ID: " + slaveData[key].unique + "</p><p>Last seen: "+seenDate+"</p><p>Online players: "+slaveData[key].playerCount+"</p><p>IP: "+slaveData[key].publicIP +":"+ slaveData[key].serverPort+"</p>"
HTML += "<p>Host: "+slaveData[key].mac+"</p>";
HTML += "<button onclick='hideAllDatasets(\"" + slaveData[key].unique + "\")\'>Hide all</button>";
HTML += "<button onclick='showAllDatasets(\"" + slaveData[key].unique + "\")\'>Show all</button>";
@@ -43,9 +43,9 @@ let chartIgnoreList = [
]
// ID of slave, ID of canvasjs div without #
function makeGraph(slaveID, selector) {
post("api/getTimelineStats", {slaveID: slaveID}, function(pointsInTime) {
//console.log("Building chart " + slaveID + " with this data:")
function makeGraph(instanceID, selector) {
post("api/getTimelineStats", {instanceID: instanceID}, function(pointsInTime) {
//console.log("Building chart " + instanceID + " with this data:")
//Find all keys at all points in time.
let itemNames = {};
+10 -10
View File
@@ -107,15 +107,15 @@ function makeItemGraphs(itemName){
if(typeof slaves == "string"){
slaves = JSON.parse(slaves);
}
let slaveIDs = Object.keys(slaves);
let instanceIDs = Object.keys(slaves);
let HTML = ""
// Draw in/out chart for unregistered slaves as well
slaveIDs.unshift("unknown");
slaveIDs.forEach(function(slaveID){
if(slaveID == "unknown" || Date.now() - slaves[slaveID].time < 120000 || JSON.parse(localStorage.settings)["Display offline slaves"]){
HTML += '<div id="contentGraph'+slaveID+'" class="storageGraph" style="width: 100%;"></div>';
instanceIDs.unshift("unknown");
instanceIDs.forEach(function(instanceID){
if(instanceID == "unknown" || Date.now() - slaves[instanceID].time < 120000 || JSON.parse(localStorage.settings)["Display offline slaves"]){
HTML += '<div id="contentGraph'+instanceID+'" class="storageGraph" style="width: 100%;"></div>';
["place", "remove"].forEach(statistic => {
console.log("Making chart for "+slaveID+"'s "+statistic+" statistic");
console.log("Making chart for "+instanceID+"'s "+statistic+" statistic");
setTimeout(function(){
let xmlhttp = new XMLHttpRequest(); // new HttpRequest instance
@@ -128,7 +128,7 @@ function makeItemGraphs(itemName){
if(isJSON(xmlhttp.responseText) && JSON.parse(xmlhttp.responseText).statusForDebugging === undefined){
let slaveDisplayName = "unknown";
try {
slaveDisplayName = slaves[slaveID].instanceName;
slaveDisplayName = slaves[instanceID].instanceName;
} catch(e) {}
let whatGraphIsIt = "Item IO from ";
// if(statistic == "remove") whatGraphIsIt = "Items taken from cluster by";
@@ -143,19 +143,19 @@ function makeItemGraphs(itemName){
break;
}
drawChartWhenCalledTwice(chartData, whatGraphIsIt + " " + slaveDisplayName);
//drawChart(statistic+"contentGraph"+slaveID, [JSON.parse(xmlhttp.response).data], `${whatGraphIsIt} ${slaveDisplayName} (${slaveID}) ${itemName}`);
//drawChart(statistic+"contentGraph"+instanceID, [JSON.parse(xmlhttp.response).data], `${whatGraphIsIt} ${slaveDisplayName} (${instanceID}) ${itemName}`);
// console.log(JSON.parse(xmlhttp.response).data);
}
}
}
xmlhttp.send(JSON.stringify({statistic:statistic, itemName:itemName, slaveID:slaveID}));
xmlhttp.send(JSON.stringify({statistic:statistic, itemName:itemName, instanceID:instanceID}));
},1);
});
let chartLines = [];
function drawChartWhenCalledTwice(data, slaveDisplayName){
chartLines.push(data);
if(chartLines.length >= 2){
drawChart("contentGraph"+slaveID, chartLines, `${slaveDisplayName} (${slaveID}) ${itemName}`);
drawChart("contentGraph"+instanceID, chartLines, `${slaveDisplayName} (${instanceID}) ${itemName}`);
}
}
}