Merge branch 'samhza-master'
This commit is contained in:
commit
d0a4addcb5
2 changed files with 37 additions and 4 deletions
|
@ -44,6 +44,8 @@ OUTPUT=
|
||||||
TEMPDIR=
|
TEMPDIR=
|
||||||
# Put temporary image web server domain
|
# Put temporary image web server domain
|
||||||
TMP_DOMAIN=
|
TMP_DOMAIN=
|
||||||
|
# Port for serving metrics. Metrics served are compatible with Prometheus.
|
||||||
|
METRICS=
|
||||||
|
|
||||||
# Set this to true if you're using PM2 to manage the bot
|
# Set this to true if you're using PM2 to manage the bot
|
||||||
PMTWO=false
|
PMTWO=false
|
||||||
|
|
31
shard.js
31
shard.js
|
@ -21,6 +21,7 @@ const misc = require("./utils/misc.js");
|
||||||
// generate help page
|
// generate help page
|
||||||
const helpGenerator =
|
const helpGenerator =
|
||||||
process.env.OUTPUT !== "" ? require("./utils/help.js") : null;
|
process.env.OUTPUT !== "" ? require("./utils/help.js") : null;
|
||||||
|
const http = require("http");
|
||||||
|
|
||||||
class Shard extends Base {
|
class Shard extends Base {
|
||||||
constructor(bot) {
|
constructor(bot) {
|
||||||
|
@ -68,6 +69,36 @@ class Shard extends Base {
|
||||||
logger.log("info", "The help docs have been generated.");
|
logger.log("info", "The help docs have been generated.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.env.METRICS !== "") {
|
||||||
|
logger.log("YES");
|
||||||
|
const httpServer = http.createServer(async (req, res) => {
|
||||||
|
if (req.method !== "GET") {
|
||||||
|
res.statusCode = 405;
|
||||||
|
return res.end("GET only");
|
||||||
|
}
|
||||||
|
res.write(`# HELP connected_workers Number of workers connected
|
||||||
|
# TYPE connected_workers gauge
|
||||||
|
connected_workers ${image.connections.length}
|
||||||
|
# HELP running_jobs Number of running jobs on this worker
|
||||||
|
# TYPE running_jobs gauge
|
||||||
|
# HELP queued_jobs Number of queued jobs on this worker
|
||||||
|
# TYPE queued_jobs gauge
|
||||||
|
# HELP max_jobs Number of max allowed jobs on this worker
|
||||||
|
# TYPE max_jobs gauge
|
||||||
|
`);
|
||||||
|
const servers = await image.getStatus();
|
||||||
|
for (const [i, w] of servers.entries()) {
|
||||||
|
res.write(`running_jobs{worker="${i}"} ${w.runningJobs}\n`);
|
||||||
|
res.write(`queued_jobs{worker="${i}"} ${w.queued}\n`);
|
||||||
|
res.write(`max_jobs{worker="${i}"} ${w.max}\n`);
|
||||||
|
}
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
httpServer.listen(process.env.METRICS, () => {
|
||||||
|
logger.log("info", `Serving metrics at ${process.env.METRICS}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// handle process stop
|
// handle process stop
|
||||||
process.on("SIGINT", () => {
|
process.on("SIGINT", () => {
|
||||||
logger.log("warn", "SIGINT detected, shutting down...");
|
logger.log("warn", "SIGINT detected, shutting down...");
|
||||||
|
|
Loading…
Reference in a new issue