mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 00:13:12 +09:00
Reference by global in statistics_exporter
Store export function in a global table in the lua module for statistics exporter in order to avoid a remote.call.
This commit is contained in:
1 parent
0e9cd35c30
commit
6cf16cc09e
4 files changed
+6
-11
No files matched your search
@@ -22,7 +22,7 @@ const instanceGameFlowStatistics = new Gauge(
|
|||||||
|
|
||||||
class InstancePlugin extends plugin.BaseInstancePlugin {
|
class InstancePlugin extends plugin.BaseInstancePlugin {
|
||||||
async onMetrics() {
|
async onMetrics() {
|
||||||
let string = await this.instance.server.sendRcon('/sc remote.call("statistics_exporter", "export")');
|
let string = await this.instance.server.sendRcon('/sc statistics_exporter.export()');
|
||||||
let stats;
|
let stats;
|
||||||
try {
|
try {
|
||||||
stats = JSON.parse(string);
|
stats = JSON.parse(string);
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ local statistics = {
|
|||||||
"entity_build_count_statistics",
|
"entity_build_count_statistics",
|
||||||
}
|
}
|
||||||
|
|
||||||
local function export()
|
statistics_exporter = {}
|
||||||
|
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,
|
||||||
@@ -31,9 +32,3 @@ local function export()
|
|||||||
|
|
||||||
rcon.print(game.table_to_json(stats))
|
rcon.print(game.table_to_json(stats))
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
|
||||||
add_remote_interface = function()
|
|
||||||
remote.add_interface("statistics_exporter", { export = export })
|
|
||||||
end
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"name": "statistics_exporter",
|
"name": "statistics_exporter",
|
||||||
"load": ["export.lua"]
|
"require": ["export.lua"]
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@ describe("statistics_exporter plugin", function() {
|
|||||||
describe(".onMetrics()", function() {
|
describe(".onMetrics()", function() {
|
||||||
it("should record statistics", async function() {
|
it("should record statistics", async function() {
|
||||||
instancePlugin.instance.server.rconCommandResults.set(
|
instancePlugin.instance.server.rconCommandResults.set(
|
||||||
'/sc remote.call("statistics_exporter", "export")',
|
'/sc statistics_exporter.export()',
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
game_tick: 100,
|
game_tick: 100,
|
||||||
player_count: 3,
|
player_count: 3,
|
||||||
@@ -51,7 +51,7 @@ describe("statistics_exporter plugin", function() {
|
|||||||
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';
|
||||||
instancePlugin.instance.server.rconCommandResults.set(
|
instancePlugin.instance.server.rconCommandResults.set(
|
||||||
'/sc remote.call("statistics_exporter", "export")', string
|
'/sc statistics_exporter.export()', string
|
||||||
);
|
);
|
||||||
|
|
||||||
let errorMessage;
|
let errorMessage;
|
||||||
|
|||||||
Reference in new issue
Block a user