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); } }); });