diff --git a/plugins/statistics_exporter/instance.js b/plugins/statistics_exporter/instance.js index 8a3d63be..d95dd9c7 100644 --- a/plugins/statistics_exporter/instance.js +++ b/plugins/statistics_exporter/instance.js @@ -1,6 +1,7 @@ "use strict"; const libPlugin = require("@clusterio/lib/plugin"); const { Gauge } = require("@clusterio/lib/prometheus"); +const libHelpers = require("@clusterio/lib/helpers"); const instancePlayerCount = new Gauge( @@ -28,7 +29,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin { } } - async onMetrics() { + async gatherMetrics() { let string = await this.instance.server.sendRcon("/sc statistics_exporter.export()"); let stats; try { @@ -61,6 +62,14 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin { } } } + + async onMetrics() { + // Wait up to 5 seconds for the metrics to be collected. It may + // take a long time for the command to go through if the command + // stream is overloaded. Should this take more than 5 seconds the + // previous values for the metrics will end up being sent to master. + await libHelpers.timeout(this.gatherMetrics(), 5e3); + } } module.exports = {