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:
Hornwitser committed 2020-04-09 16:17:38 +02:00
1 parent 56ee1fe955
commit 6bc07ad1b3
4 files changed
+35

No files matched your search

+23
View File
@@ -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();
}
}