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!`;
|
||||
const counts = await database.getCounts();
|
||||
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];
|
||||
});
|
||||
const countArray2 = [];
|
||||
for (const [key, value] of sortedValues) {
|
||||
countArray.push(`**${key}**: ${value}`);
|
||||
countArray2.push(`**${key}**: ${value}`);
|
||||
}
|
||||
const embeds = [];
|
||||
const groups = countArray.map((item, index) => {
|
||||
return index % 15 === 0 ? countArray.slice(index, index + 15) : null;
|
||||
const groups = countArray2.map((item, index) => {
|
||||
return index % 15 === 0 ? countArray2.slice(index, index + 15) : null;
|
||||
}).filter((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()))) {
|
||||
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 countDB = await database.getCounts();
|
||||
const counts = countDB.reduce((acc, val) => {
|
||||
const counts = await database.getCounts();
|
||||
/*const counts = countDB.reduce((acc, val) => {
|
||||
const [key, value] = val;
|
||||
acc[key] = value;
|
||||
return acc;
|
||||
}, {});
|
||||
}, {});*/
|
||||
const embed = {
|
||||
"embed": {
|
||||
"author": {
|
||||
|
|
7
shard.js
7
shard.js
|
@ -85,6 +85,8 @@ connected_workers ${image.connections.length}
|
|||
# TYPE queued_jobs gauge
|
||||
# HELP max_jobs Number of max allowed jobs on this worker
|
||||
# TYPE max_jobs gauge
|
||||
# HELP command_count Number of times a command has been run
|
||||
# TYPE command_count counter
|
||||
`);
|
||||
const servers = await image.getStatus();
|
||||
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(`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();
|
||||
});
|
||||
httpServer.listen(process.env.METRICS, () => {
|
||||
|
@ -146,7 +152,6 @@ connected_workers ${image.connections.length}
|
|||
if (result) return this.ipc.broadcast("reloadFail", { result: result });
|
||||
const result2 = await handler.load(collections.paths.get(message.cmd));
|
||||
if (result2) return this.ipc.broadcast("reloadFail", { result: result2 });
|
||||
//return this.ipc.broadcast("reloadSuccess", this.clusterID);
|
||||
return this.ipc.broadcast("reloadSuccess");
|
||||
});
|
||||
|
||||
|
|
|
@ -51,11 +51,12 @@ exports.enableChannel = async (channel) => {
|
|||
|
||||
exports.getCounts = async () => {
|
||||
const counts = await connection.query("SELECT * FROM counts");
|
||||
const countArray = [];
|
||||
//const countArray = [];
|
||||
const countObject = {};
|
||||
for (const { command, count } of counts.rows) {
|
||||
countArray.push([command, count]);
|
||||
countObject[command] = count;
|
||||
}
|
||||
return countArray;
|
||||
return countObject;
|
||||
};
|
||||
|
||||
exports.addCount = async (command) => {
|
||||
|
|
Loading…
Reference in a new issue