fix prometheus metric names (#142)

> A metric name should have a (single-word) application prefix relevant to the
> domain the metric belongs to.
https://prometheus.io/docs/practices/naming/
This commit is contained in:
samhza 2021-07-14 19:42:19 -04:00 committed by GitHub
parent d03967212e
commit 833ac924d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,30 +13,30 @@ class PrometheusWorker extends BaseServiceWorker {
res.statusCode = 405; res.statusCode = 405;
return res.end("GET only"); return res.end("GET only");
} }
res.write(`# HELP command_count Number of times a command has been run res.write(`# HELP esmbot_command_count Number of times a command has been run
# TYPE command_count counter # TYPE esmbot_command_count counter
`); `);
if (process.env.API === "true") { if (process.env.API === "true") {
const servers = await this.ipc.command("image", { type: "stats" }, true); const servers = await this.ipc.command("image", { type: "stats" }, true);
res.write(`# HELP connected_workers Number of workers connected res.write(`# HELP esmbot_connected_workers Number of workers connected
# TYPE connected_workers gauge # TYPE esmbot_connected_workers gauge
connected_workers ${servers.length} esmbot_connected_workers ${servers.length}
# HELP running_jobs Number of running jobs on this worker # HELP esmbot_running_jobs Number of running jobs on this worker
# TYPE running_jobs gauge # TYPE esmbot_running_jobs gauge
# HELP queued_jobs Number of queued jobs on this worker # HELP esmbot_queued_jobs Number of queued jobs on this worker
# TYPE queued_jobs gauge # TYPE esmbot_queued_jobs gauge
# HELP max_jobs Number of max allowed jobs on this worker # HELP esmbot_max_jobs Number of max allowed jobs on this worker
# TYPE max_jobs gauge # TYPE esmbot_max_jobs gauge
`); `);
for (const [i, w] of servers.entries()) { for (const [i, w] of servers.entries()) {
res.write(`running_jobs{worker="${i}"} ${w.runningJobs}\n`); res.write(`esmbot_running_jobs{worker="${i}"} ${w.runningJobs}\n`);
res.write(`queued_jobs{worker="${i}"} ${w.queued}\n`); res.write(`esmbot_queued_jobs{worker="${i}"} ${w.queued}\n`);
res.write(`max_jobs{worker="${i}"} ${w.max}\n`); res.write(`esmbot_max_jobs{worker="${i}"} ${w.max}\n`);
} }
} }
const counts = await database.getCounts(); const counts = await database.getCounts();
for (const [i, w] of Object.entries(counts)) { for (const [i, w] of Object.entries(counts)) {
res.write(`command_count{command="${i}"} ${w}\n`); res.write(`esmbot_command_count{command="${i}"} ${w}\n`);
} }
res.end(); res.end();
}); });