mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 08:23:12 +09:00
Add autosave tracking and statistics
Detect when autosaves are made and track the size in a Prometheus gague.
This commit is contained in:
1 parent
139585f8c6
commit
e908c5069b
4 files changed
+69
No files matched your search
@@ -38,6 +38,7 @@ Version 2.0.0
|
|||||||
- Added WebSocket usage statistics.
|
- Added WebSocket usage statistics.
|
||||||
- Added commands sent statistic.
|
- Added commands sent statistic.
|
||||||
- Added Factorio server CPU and memory usage statistic.
|
- Added Factorio server CPU and memory usage statistic.
|
||||||
|
- Added Factorio autosave size statistic.
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
|
|
||||||
|
|||||||
@@ -349,6 +349,18 @@ const outputHeuristics = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Message indicating the server has started an autosave
|
||||||
|
{
|
||||||
|
filter: {
|
||||||
|
type: 'log',
|
||||||
|
message: /^Saving to _autosave\d+ \((non-)?blocking\)\.$/,
|
||||||
|
},
|
||||||
|
action: function(output) {
|
||||||
|
let name = /^Saving to (_autosave\d+) /.exec(output.message)[1];
|
||||||
|
this.emit('_autosave', name);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
// Message indicating the server has finished saving
|
// Message indicating the server has finished saving
|
||||||
{
|
{
|
||||||
filter: {
|
filter: {
|
||||||
@@ -419,6 +431,8 @@ const outputHeuristics = [
|
|||||||
* output - invoked with parsed output from Factorio
|
* output - invoked with parsed output from Factorio
|
||||||
* rcon-ready - invoked when the RCON client has connected
|
* rcon-ready - invoked when the RCON client has connected
|
||||||
* game-ready - invoked when the server is finished starting up
|
* game-ready - invoked when the server is finished starting up
|
||||||
|
* autosave-start - invoked when the server starts an autosave
|
||||||
|
* autosave-fnished - invoked when the autosave finished
|
||||||
* exit - invoked when the sterver has exited
|
* exit - invoked when the sterver has exited
|
||||||
*/
|
*/
|
||||||
class FactorioServer extends events.EventEmitter {
|
class FactorioServer extends events.EventEmitter {
|
||||||
@@ -454,6 +468,20 @@ class FactorioServer extends events.EventEmitter {
|
|||||||
|
|
||||||
this._stdout = new LineSplitter((line) => { this._handleOutput(line, 'stdout'); });
|
this._stdout = new LineSplitter((line) => { this._handleOutput(line, 'stdout'); });
|
||||||
this._stderr = new LineSplitter((line) => { this._handleOutput(line, 'stderr'); });
|
this._stderr = new LineSplitter((line) => { this._handleOutput(line, 'stderr'); });
|
||||||
|
|
||||||
|
// Track autosaving
|
||||||
|
this._runningAutosave = null;
|
||||||
|
this.on("_autosave", function(name) {
|
||||||
|
this.emit("autosave-start", name);
|
||||||
|
this._runningAutosave = name;
|
||||||
|
})
|
||||||
|
|
||||||
|
this.on("_saved", function() {
|
||||||
|
if (this._runningAutosave) {
|
||||||
|
this.emit("autosave-finished", this._runningAutosave);
|
||||||
|
this._runningAutosave = null;
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
_check(expectedStates) {
|
_check(expectedStates) {
|
||||||
@@ -645,6 +673,7 @@ class FactorioServer extends events.EventEmitter {
|
|||||||
this._rconReady = false;
|
this._rconReady = false;
|
||||||
this._gameReady = false;
|
this._gameReady = false;
|
||||||
this._unexpected = [];
|
this._unexpected = [];
|
||||||
|
this._runningAutosave = null;
|
||||||
|
|
||||||
this.emit("exit");
|
this.emit("exit");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ const instanceFactorioMemoryUsage = new prometheus.Gauge(
|
|||||||
{ labels: ["instance_id"] }
|
{ labels: ["instance_id"] }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const instanceFactorioAutosaveSize = new prometheus.Gauge(
|
||||||
|
"clusterio_instance_factorio_autosave_bytes",
|
||||||
|
"Size of Factorio server autosave in bytes.",
|
||||||
|
{ labels: ["instance_id"] }
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keeps track of the runtime parameters of an instance
|
* Keeps track of the runtime parameters of an instance
|
||||||
*/
|
*/
|
||||||
@@ -78,6 +84,17 @@ class Instance extends link.Link{
|
|||||||
this.server.on("error", err => {
|
this.server.on("error", err => {
|
||||||
console.log(`Error in instance ${this.name}:`, err);
|
console.log(`Error in instance ${this.name}:`, err);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.server.on("autosave-finished", name => {
|
||||||
|
this._autosave(name).catch(err => {
|
||||||
|
console.error("Error handling autosave-finished:", err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async _autosave(name) {
|
||||||
|
let stat = await fs.stat(this.path("saves", `${name}.zip`));
|
||||||
|
instanceFactorioAutosaveSize.labels(String(this.config.get("instance.id"))).set(stat.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyExit() {
|
notifyExit() {
|
||||||
|
|||||||
@@ -109,6 +109,28 @@ let testLines = new Map([
|
|||||||
message: "Error while running event level::on_nth_tick(1)",
|
message: "Error while running event level::on_nth_tick(1)",
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
"4802.763 Info AppManager.cpp:287: Saving to _autosave4 (blocking).",
|
||||||
|
{
|
||||||
|
format: "seconds",
|
||||||
|
time: "4802.763",
|
||||||
|
type: "log",
|
||||||
|
level: "Info",
|
||||||
|
file: "AppManager.cpp:287",
|
||||||
|
message: "Saving to _autosave4 (blocking).",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"4202.780 Info AppManagerStates.cpp:1802: Saving finished",
|
||||||
|
{
|
||||||
|
format: "seconds",
|
||||||
|
time: "4202.780",
|
||||||
|
type: "log",
|
||||||
|
level: "Info",
|
||||||
|
file: "AppManagerStates.cpp:1802",
|
||||||
|
message: "Saving finished",
|
||||||
|
}
|
||||||
|
],
|
||||||
])
|
])
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
Reference in new issue
Block a user