Added command counts to Prometheus metrics
This commit is contained in:
parent
d0a4addcb5
commit
e5d9388952
4 changed files with 21 additions and 11 deletions
|
@ -8,15 +8,19 @@ class CountCommand extends Command {
|
||||||
if (this.message.channel.guild && !this.message.channel.permissionsOf(this.client.user.id).has("embedLinks")) return `${this.message.author.mention}, I don't have the \`Embed Links\` permission!`;
|
if (this.message.channel.guild && !this.message.channel.permissionsOf(this.client.user.id).has("embedLinks")) return `${this.message.author.mention}, I don't have the \`Embed Links\` permission!`;
|
||||||
const counts = await database.getCounts();
|
const counts = await database.getCounts();
|
||||||
const countArray = [];
|
const countArray = [];
|
||||||
const sortedValues = counts.sort((a, b) => {
|
for (const entry of Object.entries(counts)) {
|
||||||
|
countArray.push(entry);
|
||||||
|
}
|
||||||
|
const sortedValues = countArray.sort((a, b) => {
|
||||||
return b[1] - a[1];
|
return b[1] - a[1];
|
||||||
});
|
});
|
||||||
|
const countArray2 = [];
|
||||||
for (const [key, value] of sortedValues) {
|
for (const [key, value] of sortedValues) {
|
||||||
countArray.push(`**${key}**: ${value}`);
|
countArray2.push(`**${key}**: ${value}`);
|
||||||
}
|
}
|
||||||
const embeds = [];
|
const embeds = [];
|
||||||
const groups = countArray.map((item, index) => {
|
const groups = countArray2.map((item, index) => {
|
||||||
return index % 15 === 0 ? countArray.slice(index, index + 15) : null;
|
return index % 15 === 0 ? countArray2.slice(index, index + 15) : null;
|
||||||
}).filter((item) => {
|
}).filter((item) => {
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,12 +14,12 @@ class HelpCommand extends Command {
|
||||||
if (this.args.length !== 0 && (commands.has(this.args[0].toLowerCase()) || aliases.has(this.args[0].toLowerCase()))) {
|
if (this.args.length !== 0 && (commands.has(this.args[0].toLowerCase()) || aliases.has(this.args[0].toLowerCase()))) {
|
||||||
const command = aliases.has(this.args[0].toLowerCase()) ? collections.aliases.get(this.args[0].toLowerCase()) : this.args[0].toLowerCase();
|
const command = aliases.has(this.args[0].toLowerCase()) ? collections.aliases.get(this.args[0].toLowerCase()) : this.args[0].toLowerCase();
|
||||||
const info = collections.info.get(command);
|
const info = collections.info.get(command);
|
||||||
const countDB = await database.getCounts();
|
const counts = await database.getCounts();
|
||||||
const counts = countDB.reduce((acc, val) => {
|
/*const counts = countDB.reduce((acc, val) => {
|
||||||
const [key, value] = val;
|
const [key, value] = val;
|
||||||
acc[key] = value;
|
acc[key] = value;
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});*/
|
||||||
const embed = {
|
const embed = {
|
||||||
"embed": {
|
"embed": {
|
||||||
"author": {
|
"author": {
|
||||||
|
|
7
shard.js
7
shard.js
|
@ -85,6 +85,8 @@ connected_workers ${image.connections.length}
|
||||||
# TYPE queued_jobs gauge
|
# TYPE queued_jobs gauge
|
||||||
# HELP max_jobs Number of max allowed jobs on this worker
|
# HELP max_jobs Number of max allowed jobs on this worker
|
||||||
# TYPE max_jobs gauge
|
# TYPE max_jobs gauge
|
||||||
|
# HELP command_count Number of times a command has been run
|
||||||
|
# TYPE command_count counter
|
||||||
`);
|
`);
|
||||||
const servers = await image.getStatus();
|
const servers = await image.getStatus();
|
||||||
for (const [i, w] of servers.entries()) {
|
for (const [i, w] of servers.entries()) {
|
||||||
|
@ -92,6 +94,10 @@ connected_workers ${image.connections.length}
|
||||||
res.write(`queued_jobs{worker="${i}"} ${w.queued}\n`);
|
res.write(`queued_jobs{worker="${i}"} ${w.queued}\n`);
|
||||||
res.write(`max_jobs{worker="${i}"} ${w.max}\n`);
|
res.write(`max_jobs{worker="${i}"} ${w.max}\n`);
|
||||||
}
|
}
|
||||||
|
const counts = await database.getCounts();
|
||||||
|
for (const [i, w] of Object.entries(counts)) {
|
||||||
|
res.write(`command_count{command="${i}"} ${w}\n`);
|
||||||
|
}
|
||||||
res.end();
|
res.end();
|
||||||
});
|
});
|
||||||
httpServer.listen(process.env.METRICS, () => {
|
httpServer.listen(process.env.METRICS, () => {
|
||||||
|
@ -146,7 +152,6 @@ connected_workers ${image.connections.length}
|
||||||
if (result) return this.ipc.broadcast("reloadFail", { result: result });
|
if (result) return this.ipc.broadcast("reloadFail", { result: result });
|
||||||
const result2 = await handler.load(collections.paths.get(message.cmd));
|
const result2 = await handler.load(collections.paths.get(message.cmd));
|
||||||
if (result2) return this.ipc.broadcast("reloadFail", { result: result2 });
|
if (result2) return this.ipc.broadcast("reloadFail", { result: result2 });
|
||||||
//return this.ipc.broadcast("reloadSuccess", this.clusterID);
|
|
||||||
return this.ipc.broadcast("reloadSuccess");
|
return this.ipc.broadcast("reloadSuccess");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -51,11 +51,12 @@ exports.enableChannel = async (channel) => {
|
||||||
|
|
||||||
exports.getCounts = async () => {
|
exports.getCounts = async () => {
|
||||||
const counts = await connection.query("SELECT * FROM counts");
|
const counts = await connection.query("SELECT * FROM counts");
|
||||||
const countArray = [];
|
//const countArray = [];
|
||||||
|
const countObject = {};
|
||||||
for (const { command, count } of counts.rows) {
|
for (const { command, count } of counts.rows) {
|
||||||
countArray.push([command, count]);
|
countObject[command] = count;
|
||||||
}
|
}
|
||||||
return countArray;
|
return countObject;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.addCount = async (command) => {
|
exports.addCount = async (command) => {
|
||||||
|
|
Loading…
Reference in a new issue