Add metric mapping slave and instance id to name

Add exported metrics that map instance id and slave id to their
respective names.  This allows getting the instance name of a metric by
doing a left join using query of the form 'metric * on(instance_id)
group_left(instance_name) clusterio_master_instance_mapping'.
This commit is contained in:
Hornwitser committed 2020-12-07 17:22:17 +01:00
1 parent 71164faa14
commit 450e27e001
2 files changed
+41 -3

No files matched your search

+2
View File
@@ -51,6 +51,8 @@ Version 2.0.0
- Added stripping of long paths in the Factorio server log.
- Added option to configure maximum number of commands to send in parallel.
- Added option to auto start instances on slave startup.
- Added metric mapping of slave and instance ids to their names, allowing
them to be displayed by name in queries that join with the mapping.
### Changes
+39 -3
View File
@@ -42,6 +42,10 @@ let debugEvents = new events.EventEmitter();
let loadedPlugins = {};
let devMiddleware;
let clusterLogger;
let db = {
instances: new Map(),
slaves: new Map(),
};
// homebrew modules
const generateSslCert = require("./src/generate_ssl_cert");
@@ -106,6 +110,41 @@ function serveWeb(route) {
app.use(express.static(path.join(__dirname, "static")));
app.use(express.static("static")); // Used for data export files
const slaveMappingGauge = new libPrometheus.Gauge(
"clusterio_master_slave_mapping",
"Mapping of Slave ID to name",
{
labels: ["slave_id", "slave_name"],
callback: function() {
slaveMappingGauge.clear();
for (let [id, slave] of db.slaves) {
slaveMappingGauge.labels({
slave_id: String(id),
slave_name: slave.name,
}).set(1);
};
},
}
);
const instanceMappingGauge = new libPrometheus.Gauge(
"clusterio_master_instance_mapping",
"Mapping of Instance ID to name and slave",
{
labels: ["instance_id", "instance_name", "slave_id"],
callback: function() {
instanceMappingGauge.clear();
for (let [id, instance] of db.instances) {
instanceMappingGauge.labels({
instance_id: String(id),
instance_name: String(instance.config.get("instance.name")),
slave_id: String(instance.config.get("instance.assigned_slave")),
}).set(1);
}
},
}
);
const endpointHitCounter = new libPrometheus.Counter(
"clusterio_master_http_endpoint_hits_total",
"How many requests a particular HTTP endpoint has gotten",
@@ -280,9 +319,6 @@ const masterConnectedClientsCount = new libPrometheus.Gauge(
},
);
// set up database
const db = {};
/**
* Load Map from JSON file in the database directory.
*