mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Add Factorio CPU and Memory usage statistics
Add per instance metrics for CPU and memory usage with the pidusage library.
This commit is contained in:
1 parent
56ee1fe955
commit
6bc07ad1b3
4 files changed
+35
No files matched your search
@@ -37,6 +37,7 @@ Version 2.0.0
|
||||
allowing it to be proxied behind web-server.
|
||||
- Added WebSocket usage statistics.
|
||||
- Added commands sent statistic.
|
||||
- Added Factorio server CPU and memory usage statistic.
|
||||
|
||||
### Changes
|
||||
|
||||
|
||||
@@ -590,6 +590,16 @@ class FactorioServer extends events.EventEmitter {
|
||||
return this._version;
|
||||
}
|
||||
|
||||
/**
|
||||
* The pid of the server process, or null if not running
|
||||
*/
|
||||
get pid() {
|
||||
if (!this._server) {
|
||||
return null;
|
||||
}
|
||||
return this._server.pid;
|
||||
}
|
||||
|
||||
_attachStdio() {
|
||||
this._server.stdout.on('data', chunk => { this._stdout.data(chunk); });
|
||||
this._server.stdout.on('close', () => { this._stdout.end(); });
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
"needle": "^2.4.0",
|
||||
"node-factorio-api": "^0.3.8",
|
||||
"node-forge": "^0.7.1",
|
||||
"pidusage": "^2.0.18",
|
||||
"rcon-client": "^4.2.0",
|
||||
"request": "^2.83.0",
|
||||
"sanitizer": "^0.1.3",
|
||||
|
||||
@@ -2,6 +2,7 @@ const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const yargs = require("yargs");
|
||||
const events = require("events");
|
||||
const pidusage = require("pidusage");
|
||||
const version = require("./package").version;
|
||||
|
||||
// internal libraries
|
||||
@@ -22,6 +23,18 @@ const instanceRconCommandsCounter = new prometheus.Counter(
|
||||
{ labels: ["instance_id"] }
|
||||
);
|
||||
|
||||
const instanceFactorioCpuTime = new prometheus.Gauge(
|
||||
"clusterio_instance_factorio_cpu_time_total",
|
||||
"Factorio CPU time spent in seconds.",
|
||||
{ labels: ["instance_id"] }
|
||||
);
|
||||
|
||||
const instanceFactorioMemoryUsage = new prometheus.Gauge(
|
||||
"clusterio_instance_factorio_resident_memory_bytes",
|
||||
"Factorio resident memory size in bytes.",
|
||||
{ labels: ["instance_id"] }
|
||||
);
|
||||
|
||||
/**
|
||||
* Keeps track of the runtime parameters of an instance
|
||||
*/
|
||||
@@ -311,6 +324,13 @@ class Instance extends link.Link{
|
||||
}
|
||||
}
|
||||
|
||||
let pid = this.server.pid;
|
||||
if (pid) {
|
||||
let stats = await pidusage(pid);
|
||||
instanceFactorioCpuTime.labels(String(this.config.get("instance.id"))).set(stats.ctime / 1000);
|
||||
instanceFactorioMemoryUsage.labels(String(this.config.get("instance.id"))).set(stats.memory);
|
||||
}
|
||||
|
||||
return { results };
|
||||
}
|
||||
|
||||
@@ -702,6 +722,9 @@ class Slave extends link.Link {
|
||||
}
|
||||
this.connector.close(1001, "Slave Shutdown");
|
||||
await events.once(this.connector, "close");
|
||||
|
||||
// Clear silly interval in pidfile library.
|
||||
pidusage.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user