mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 16:13:12 +09:00
Add clusterio_statistics_exporter_platform_mapping
This allows queries to map between the platform surfaces tracked in the statistics and the name assigned by the player
This commit is contained in:
1 parent
7934e471a7
commit
fd741f9b49
2 files changed
+38
-1
No files matched your search
@@ -17,6 +17,12 @@ type IpcStats = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
platforms: {
|
||||||
|
[key: string]: {
|
||||||
|
force: string,
|
||||||
|
surface: string,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +51,11 @@ const instanceGameFlowStatistics = new Gauge(
|
|||||||
"Pollution produced/consumed in the game",
|
"Pollution produced/consumed in the game",
|
||||||
{ labels: ["instance_id", "surface", "statistic", "direction", "name"] },
|
{ labels: ["instance_id", "surface", "statistic", "direction", "name"] },
|
||||||
);
|
);
|
||||||
|
const instancePlatformMapping = new Gauge(
|
||||||
|
"clusterio_statistics_exporter_platform_mapping",
|
||||||
|
"Mapping of platform name to force, surface and instance",
|
||||||
|
{ labels: ["instance_id", "platform_name", "force", "surface"] }
|
||||||
|
);
|
||||||
|
|
||||||
function setForceFlowStatistic(
|
function setForceFlowStatistic(
|
||||||
instanceId: number,
|
instanceId: number,
|
||||||
@@ -103,6 +114,19 @@ export class InstancePlugin extends BaseInstancePlugin {
|
|||||||
instanceGameTicksTotal.labels(String(instanceId)).set(stats.game_tick);
|
instanceGameTicksTotal.labels(String(instanceId)).set(stats.game_tick);
|
||||||
instancePlayerCount.labels(String(instanceId)).set(stats.player_count);
|
instancePlayerCount.labels(String(instanceId)).set(stats.player_count);
|
||||||
|
|
||||||
|
// Remove existing platform mappings for this instance
|
||||||
|
instancePlatformMapping.removeAll({ instance_id: String(instanceId) });
|
||||||
|
|
||||||
|
// Set new platform mappings
|
||||||
|
for (let [platformName, platform] of Object.entries(stats.platforms)) {
|
||||||
|
instancePlatformMapping.labels(
|
||||||
|
String(instanceId),
|
||||||
|
platformName,
|
||||||
|
platform.force,
|
||||||
|
platform.surface
|
||||||
|
).set(1);
|
||||||
|
}
|
||||||
|
|
||||||
for (let [surfaceName, surfaceStats] of Object.entries(stats.surface_statistics)) {
|
for (let [surfaceName, surfaceStats] of Object.entries(stats.surface_statistics)) {
|
||||||
for (let [forceName, flowStatistics] of Object.entries(surfaceStats.force_flow_statistics)) {
|
for (let [forceName, flowStatistics] of Object.entries(surfaceStats.force_flow_statistics)) {
|
||||||
for (let [statisticName, statistic] of Object.entries(flowStatistics)) {
|
for (let [statisticName, statistic] of Object.entries(flowStatistics)) {
|
||||||
@@ -151,3 +175,4 @@ export const _instancePlayerCount = instancePlayerCount;
|
|||||||
export const _instanceGameTicksTotal = instanceGameTicksTotal;
|
export const _instanceGameTicksTotal = instanceGameTicksTotal;
|
||||||
export const _instanceForceFlowStatistics = instanceForceFlowStatistics;
|
export const _instanceForceFlowStatistics = instanceForceFlowStatistics;
|
||||||
export const _instanceGameFlowStatistics = instanceGameFlowStatistics;
|
export const _instanceGameFlowStatistics = instanceGameFlowStatistics;
|
||||||
|
export const _instancePlatformMapping = instancePlatformMapping;
|
||||||
@@ -14,7 +14,8 @@ function statistics_exporter.export()
|
|||||||
local stats = {
|
local stats = {
|
||||||
game_tick = game.tick,
|
game_tick = game.tick,
|
||||||
player_count = #game.connected_players,
|
player_count = #game.connected_players,
|
||||||
surface_statistics = {}
|
surface_statistics = {},
|
||||||
|
platforms = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, surface in pairs(game.surfaces) do
|
for _, surface in pairs(game.surfaces) do
|
||||||
@@ -43,5 +44,16 @@ function statistics_exporter.export()
|
|||||||
stats.surface_statistics[surface.name] = surface_stats
|
stats.surface_statistics[surface.name] = surface_stats
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if v2_stats then
|
||||||
|
for _, force in pairs(game.forces) do
|
||||||
|
for _, platform in pairs(force.platforms) do
|
||||||
|
stats.platforms[platform.name] = {
|
||||||
|
force = force.name,
|
||||||
|
surface = platform.surface.name
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
rcon.print(compat.table_to_json(stats))
|
rcon.print(compat.table_to_json(stats))
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user