diff --git a/plugins/statistics_exporter/instance.ts b/plugins/statistics_exporter/instance.ts index d371f735..91e68284 100644 --- a/plugins/statistics_exporter/instance.ts +++ b/plugins/statistics_exporter/instance.ts @@ -22,6 +22,8 @@ type IpcStats = { [key: string]: { force: string, surface: string, + speed: number, + weight: number, } } } @@ -56,6 +58,16 @@ const instancePlatformMapping = new Gauge( "Mapping of platform name to force, surface and instance", { labels: ["instance_id", "platform_name", "force", "surface"] } ); +const instancePlatformSpeed = new Gauge( + "clusterio_statistics_exporter_platform_speed", + "Current speed of the platform", + { labels: ["instance_id", "force", "surface"] } +); +const instancePlatformWeight = new Gauge( + "clusterio_statistics_exporter_platform_weight", + "Current weight/mass of the platform", + { labels: ["instance_id", "force", "surface"] } +); function setForceFlowStatistic( instanceId: number, @@ -114,10 +126,12 @@ export class InstancePlugin extends BaseInstancePlugin { instanceGameTicksTotal.labels(String(instanceId)).set(stats.game_tick); instancePlayerCount.labels(String(instanceId)).set(stats.player_count); - // Remove existing platform mappings for this instance + // Remove existing platform mappings and stats for this instance instancePlatformMapping.removeAll({ instance_id: String(instanceId) }); + instancePlatformSpeed.removeAll({ instance_id: String(instanceId) }); + instancePlatformWeight.removeAll({ instance_id: String(instanceId) }); - // Set new platform mappings + // Set new platform mappings and stats for (let [platformName, platform] of Object.entries(stats.platforms)) { instancePlatformMapping.labels( String(instanceId), @@ -125,6 +139,18 @@ export class InstancePlugin extends BaseInstancePlugin { platform.force, platform.surface ).set(1); + + instancePlatformSpeed.labels( + String(instanceId), + platform.force, + platform.surface + ).set(platform.speed); + + instancePlatformWeight.labels( + String(instanceId), + platform.force, + platform.surface + ).set(platform.weight); } for (let [surfaceName, surfaceStats] of Object.entries(stats.surface_statistics)) { @@ -176,3 +202,5 @@ export const _instanceGameTicksTotal = instanceGameTicksTotal; export const _instanceForceFlowStatistics = instanceForceFlowStatistics; export const _instanceGameFlowStatistics = instanceGameFlowStatistics; export const _instancePlatformMapping = instancePlatformMapping; +export const _instancePlatformSpeed = instancePlatformSpeed; +export const _instancePlatformWeight = instancePlatformWeight; diff --git a/plugins/statistics_exporter/module/export.lua b/plugins/statistics_exporter/module/export.lua index fe9d4c16..33626000 100644 --- a/plugins/statistics_exporter/module/export.lua +++ b/plugins/statistics_exporter/module/export.lua @@ -49,7 +49,9 @@ function statistics_exporter.export() for _, platform in pairs(force.platforms) do stats.platforms[platform.name] = { force = force.name, - surface = platform.surface.name + surface = platform.surface.name, + speed = platform.speed, + weight = platform.weight, } end end diff --git a/plugins/statistics_exporter/test/plugin.js b/plugins/statistics_exporter/test/plugin.js index 5fd12c8b..4d315fbc 100644 --- a/plugins/statistics_exporter/test/plugin.js +++ b/plugins/statistics_exporter/test/plugin.js @@ -52,6 +52,8 @@ describe("statistics_exporter plugin", function() { "platform-1": { force: "player", surface: "nauvis", + speed: 1, + weight: 2, }, }, }) @@ -70,6 +72,12 @@ describe("statistics_exporter plugin", function() { assert.equal(instance._instancePlatformMapping.labels( "7357", "platform-1", "player", "nauvis").get(), 1); + assert.equal(instance._instancePlatformSpeed.labels( + "7357", "player", "nauvis").get(), + 1); + assert.equal(instance._instancePlatformWeight.labels( + "7357", "player", "nauvis").get(), + 2); }); it("should pass on JSON parse errors", async function() { let string = "An error occured\n";