mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 23:53:13 +09:00
Add platform speed and weight metrics
clusterio_statistics_exporter_platform_speed clusterio_statistics_exporter_platform_weight
This commit is contained in:
1 parent
9464541d61
commit
8e22de9d2d
3 files changed
+41
-3
No files matched your search
@@ -22,6 +22,8 @@ type IpcStats = {
|
|||||||
[key: string]: {
|
[key: string]: {
|
||||||
force: string,
|
force: string,
|
||||||
surface: string,
|
surface: string,
|
||||||
|
speed: number,
|
||||||
|
weight: number,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,6 +58,16 @@ const instancePlatformMapping = new Gauge(
|
|||||||
"Mapping of platform name to force, surface and instance",
|
"Mapping of platform name to force, surface and instance",
|
||||||
{ labels: ["instance_id", "platform_name", "force", "surface"] }
|
{ 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(
|
function setForceFlowStatistic(
|
||||||
instanceId: number,
|
instanceId: number,
|
||||||
@@ -114,10 +126,12 @@ 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
|
// Remove existing platform mappings and stats for this instance
|
||||||
instancePlatformMapping.removeAll({ instance_id: String(instanceId) });
|
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)) {
|
for (let [platformName, platform] of Object.entries(stats.platforms)) {
|
||||||
instancePlatformMapping.labels(
|
instancePlatformMapping.labels(
|
||||||
String(instanceId),
|
String(instanceId),
|
||||||
@@ -125,6 +139,18 @@ export class InstancePlugin extends BaseInstancePlugin {
|
|||||||
platform.force,
|
platform.force,
|
||||||
platform.surface
|
platform.surface
|
||||||
).set(1);
|
).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)) {
|
for (let [surfaceName, surfaceStats] of Object.entries(stats.surface_statistics)) {
|
||||||
@@ -176,3 +202,5 @@ export const _instanceGameTicksTotal = instanceGameTicksTotal;
|
|||||||
export const _instanceForceFlowStatistics = instanceForceFlowStatistics;
|
export const _instanceForceFlowStatistics = instanceForceFlowStatistics;
|
||||||
export const _instanceGameFlowStatistics = instanceGameFlowStatistics;
|
export const _instanceGameFlowStatistics = instanceGameFlowStatistics;
|
||||||
export const _instancePlatformMapping = instancePlatformMapping;
|
export const _instancePlatformMapping = instancePlatformMapping;
|
||||||
|
export const _instancePlatformSpeed = instancePlatformSpeed;
|
||||||
|
export const _instancePlatformWeight = instancePlatformWeight;
|
||||||
@@ -49,7 +49,9 @@ function statistics_exporter.export()
|
|||||||
for _, platform in pairs(force.platforms) do
|
for _, platform in pairs(force.platforms) do
|
||||||
stats.platforms[platform.name] = {
|
stats.platforms[platform.name] = {
|
||||||
force = force.name,
|
force = force.name,
|
||||||
surface = platform.surface.name
|
surface = platform.surface.name,
|
||||||
|
speed = platform.speed,
|
||||||
|
weight = platform.weight,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ describe("statistics_exporter plugin", function() {
|
|||||||
"platform-1": {
|
"platform-1": {
|
||||||
force: "player",
|
force: "player",
|
||||||
surface: "nauvis",
|
surface: "nauvis",
|
||||||
|
speed: 1,
|
||||||
|
weight: 2,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -70,6 +72,12 @@ describe("statistics_exporter plugin", function() {
|
|||||||
assert.equal(instance._instancePlatformMapping.labels(
|
assert.equal(instance._instancePlatformMapping.labels(
|
||||||
"7357", "platform-1", "player", "nauvis").get(),
|
"7357", "platform-1", "player", "nauvis").get(),
|
||||||
1);
|
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() {
|
it("should pass on JSON parse errors", async function() {
|
||||||
let string = "An error occured\n";
|
let string = "An error occured\n";
|
||||||
|
|||||||
Reference in new issue
Block a user