From f15ce3fb2309f67f1a1b6979914260bb594d36f6 Mon Sep 17 00:00:00 2001 From: Danielv123 Date: Sun, 29 Apr 2018 21:45:22 +0200 Subject: [PATCH 1/6] No longer auto install clusterio 1.0.0 --- lib/npmPostinstall.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/npmPostinstall.js b/lib/npmPostinstall.js index 8106fad4..187407bf 100644 --- a/lib/npmPostinstall.js +++ b/lib/npmPostinstall.js @@ -5,7 +5,7 @@ var fs = require('fs'); var modManager = require("./manager/modManager.js"); -modManager.addMod("clusterio", "shared"); +// modManager.addMod("clusterio", "shared"); function makeDirectory(path){ return new Promise((resolve, reject) => { From 355e8974a416c1449a8eb1fc76a8253cf976d60f Mon Sep 17 00:00:00 2001 From: Danielv123 Date: Mon, 30 Apr 2018 12:09:01 +0200 Subject: [PATCH 2/6] Added more websocket utilization metrics --- .gitignore | 1 + master.js | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 0270b57f..9752a88d 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,7 @@ mod_cache.json static/pictures/spritesheet.js static/pictures/spritesheet.png static/external +saves # weird pattern to ignore sharedPlugins except not ignore some core modules !sharedPlugins/ diff --git a/master.js b/master.js index fa47c882..5bece902 100644 --- a/master.js +++ b/master.js @@ -935,6 +935,7 @@ class wsSlave { // handle command return values this.commandsWaitingForReturn = {}; this.socket.on("runCommandReturnValue", resp => { + prometheusWsUsageCounter.labels('runCommandReturnValue').inc(); if(resp.commandID && resp.body && this.commandsWaitingForReturn[resp.commandID] && this.commandsWaitingForReturn[resp.commandID].callback && typeof this.commandsWaitingForReturn[resp.commandID].callback == "function"){ this.commandsWaitingForReturn[resp.commandID].callback(resp.body); delete this.commandsWaitingForReturn[resp.commandID]; @@ -942,6 +943,7 @@ class wsSlave { }); this.socket.on("gameChat", data => { + prometheusWsUsageCounter.labels('gameChat').inc(); if(typeof data === "object"){ data.timestamp = Date.now(); if(!global.wsChatRecievers) global.wsChatRecievers = []; @@ -952,6 +954,7 @@ class wsSlave { }); this.socket.on("alert", alert => { + prometheusWsUsageCounter.labels('alert').inc(); if(typeof alert === "object"){ alert.timestamp = Date.now(); if(!global.wsAlertRecievers) global.wsAlertRecievers = []; From 47430b5d289bc1f8d5d0489caa874390c092c0f5 Mon Sep 17 00:00:00 2001 From: Danielv123 Date: Mon, 30 Apr 2018 14:30:01 +0200 Subject: [PATCH 3/6] Remove super exessive logging on master Also added better prometheus endpoint logging --- master.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/master.js b/master.js index 5bece902..7e24a9a6 100644 --- a/master.js +++ b/master.js @@ -699,7 +699,7 @@ app.post("/api/getStats", function(req,res) { } else if(req.body.statistic == "remove"){ console.log(`sending remove data for instanceID ${req.body.instanceID} ${req.body.itemName}`); // Gather data - console.log(sentItemStatisticsBySlaveID) + // console.log(sentItemStatisticsBySlaveID) let itemStats = sentItemStatisticsBySlaveID[req.body.instanceID]; console.log(itemStats) if(typeof itemStats == "object"){ From 968a306c5a6f7154dcb6b9457d544d7df064068d Mon Sep 17 00:00:00 2001 From: Danielv123 Date: Mon, 30 Apr 2018 23:05:55 +0200 Subject: [PATCH 4/6] Fixed issue where slaves would not register when ran on VM withou MAC --- client.js | 24 ++++++++++++------------ master.js | 8 ++++++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/client.js b/client.js index cbedfcf8..3712cdfe 100644 --- a/client.js +++ b/client.js @@ -619,20 +619,20 @@ function instanceManagement() { function callback(err, mac) { if (err) { + mac = "unknown"; console.log("##### getMac crashed, but we don't really give a shit because we are probably closing down #####"); - } else { - payload.mac = mac - console.log("Registered our precense with master "+config.masterIP+" at " + payload.time); - needle.post(config.masterIP + ":" + config.masterPort + '/api/getID', payload, needleOptionsWithTokenAuthHeader, function (err, response, body) { - if (err && err.code != "ECONNRESET"){ - console.error("We got problems, something went wrong when contacting master"); - console.error(err); - } else if (response && response.body) { - // In the future we might be interested in whether or not we actually manage to send it, but honestly I don't care. - console.log(response.body); - } - }); } + payload.mac = mac; + console.log("Registered our precense with master "+config.masterIP+" at " + payload.time); + needle.post(config.masterIP + ":" + config.masterPort + '/api/getID', payload, needleOptionsWithTokenAuthHeader, function (err, response, body) { + if (err && err.code != "ECONNRESET"){ + console.error("We got problems, something went wrong when contacting master"); + console.error(err); + } else if (response && response.body) { + // In the future we might be interested in whether or not we actually manage to send it, but honestly I don't care. + console.log(response.body); + } + }); } if(global.mac){ callback(undefined, global.mac); diff --git a/master.js b/master.js index 7e24a9a6..8250a171 100644 --- a/master.js +++ b/master.js @@ -291,6 +291,8 @@ POST Get metadata from a single slave. For whenever you find the data returned b @alias /api/getSlaveMeta */ app.post("/api/getSlaveMeta", function (req, res) { + endpointHitCounter.labels(req.route.path).inc(); + let reqStartTime = Date.now(); console.log("body", req.body); if(req.body && req.body.instanceID && req.body.password){ console.log("returning meta for ", req.body.instanceID); @@ -299,6 +301,7 @@ app.post("/api/getSlaveMeta", function (req, res) { res.status(400); res.send('{"INVALID REQUEST":1}'); } + httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime); }); // mod management // should handle uploading and checking if mods are uploaded @@ -786,6 +789,8 @@ Requires x-access-token header to be set. Find you api token in secret-api-token @returns {object} Status {auth: bool, message: "Informative error", data:{}} */ app.post("/api/runCommand", (req,res) => { + endpointHitCounter.labels(req.route.path).inc(); + let reqStartTime = Date.now(); var token = req.headers['x-access-token']; if(!token) return res.status(401).send({ auth: false, message: 'No token provided.' }); @@ -808,6 +813,7 @@ app.post("/api/runCommand", (req,res) => { wsSlaves[instanceID].runCommand(body.command); } res.status(200).send({auth: true, message: "success", response: "Cluster wide messaging initiated"}); + httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime); } else if ( body.instanceID && wsSlaves[body.instanceID] @@ -818,9 +824,11 @@ app.post("/api/runCommand", (req,res) => { // execute command wsSlaves[body.instanceID].runCommand(body.command, data => { res.status(200).send({auth: true, message: "success", data}); + httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime); }); } else { res.status(400).send({auth: true, message: "Error: invalid request.body"}); + httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime); } }); }); From 1e0c2759688fbff25162ee0dd7ad8e284ca6216d Mon Sep 17 00:00:00 2001 From: Danielv123 Date: Mon, 30 Apr 2018 23:34:09 +0200 Subject: [PATCH 5/6] Use rcon instead of stdin on linux as well --- client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client.js b/client.js index 3712cdfe..2533059a 100644 --- a/client.js +++ b/client.js @@ -64,7 +64,7 @@ function messageInterface(command, callback) { command = command.toString('utf8'); } - if(process.platform == "linux" && typeof command == "string" && serverprocess) { + if(false && process.platform == "linux" && typeof command == "string" && serverprocess) { /* to send to stdin, use: serverprocess.stdin.write("/c command;\n") @@ -381,7 +381,7 @@ write-data=__PATH__executable__/../../../instances/" + instance + "\r\n\ }); // connect to the server with rcon - if(process.platform != "linux"){ + if(true || process.platform != "linux"){ // IP, port, password client = new Rcon({ host: 'localhost', From 6514462a1db6300fce2f524faf51e273c4c9535a Mon Sep 17 00:00:00 2001 From: Danielv123 Date: Mon, 30 Apr 2018 23:47:31 +0200 Subject: [PATCH 6/6] Increased max command size for imports --- client.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client.js b/client.js index 2533059a..fcda464c 100644 --- a/client.js +++ b/client.js @@ -834,13 +834,14 @@ function instanceManagement() { for(let i=0;i400)//450 //ITS SMALL SO FACTORIO DOESNT SPILT IT INTO MULTIPLE PACKETS + if(cmd.length>8000)//450 //ITS SMALL SO FACTORIO DOESNT SPILT IT INTO MULTIPLE PACKETS { messageInterface("/silent-command remote.call('clusterio', 'importMany', '"+cmd.slice(0, -1)+"]"+ "')"); cmd="["; } } - if (!(cmd=="[")){messageInterface("/silent-command remote.call('clusterio', 'importMany', '"+cmd.slice(0, -1)+"]"+ "')");}confirmedOrders=[]; + if (!(cmd=="[")){messageInterface("/silent-command remote.call('clusterio', 'importMany', '"+cmd.slice(0, -1)+"]"+ "')");} + confirmedOrders=[]; } }, 1000); // COMBINATOR SIGNALS ---------------------------------------------------------