From 99ac8f4f3365f3d6da18c4a43abccedc7a89b166 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 4 Apr 2020 12:18:26 +0200 Subject: [PATCH] Add commands sent statistic Track RCON commands sent. --- CHANGELOG.md | 1 + slave.js | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db27eb9a..b5bbfb88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ Version 2.0.0 - Added config to specify which path the master interface is accessed under, allowing it to be proxied behind web-server. - Added WebSocket usage statistics. +- Added commands sent statistic. ### Changes diff --git a/slave.js b/slave.js index 2ebcd27d..a18575be 100644 --- a/slave.js +++ b/slave.js @@ -16,6 +16,12 @@ const luaTools = require('lib/luaTools'); const config = require('lib/config'); +const instanceRconCommandsCounter = new prometheus.Counter( + "clusterio_instance_rcon_commands_total", + "How many commands have been sent to the instance", + { labels: ["instance_id"] } +); + /** * Keeps track of the runtime parameters of an instance */ @@ -39,6 +45,12 @@ class Instance extends link.Link{ factorioDir, this._dir, serverOptions ); + let originalSendRcon = this.server.sendRcon; + this.server.sendRcon = (...args) => { + instanceRconCommandsCounter.labels(String(this.config.get("instance.id"))).inc(); + return originalSendRcon.call(this.server, ...args); + } + this.server.on('output', (output) => { link.messages.instanceOutput.send(this, { instance_id: this.config.get("instance.id"), output })