aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/cogs/metrics.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/bot/cogs/metrics.py b/bot/cogs/metrics.py
index 6d3cc67bd..fa858bbd6 100644
--- a/bot/cogs/metrics.py
+++ b/bot/cogs/metrics.py
@@ -1,7 +1,7 @@
from collections import defaultdict
from discord import Member, Message
-from discord.ext.commands import Cog
+from discord.ext.commands import Cog, Context
from prometheus_client import Counter, Gauge
from bot.bot import Bot
@@ -29,6 +29,11 @@ class Metrics(Cog):
documentation="Guild messages by guild by channel.",
labelnames=('channel_id', 'guild_id', 'channel_name')
)
+ self.command_completions = Counter(
+ name=f'{self.PREFIX}_command_completions',
+ documentation="Completed commands by command by guild.",
+ labelnames=('guild_id', 'command')
+ )
@Cog.listener()
async def on_ready(self) -> None:
@@ -71,6 +76,20 @@ class Metrics(Cog):
guild_id=message.guild.id,
).inc()
+ @Cog.listener()
+ async def on_command_completion(self, ctx: Context) -> None:
+ """Increment the command completion counter."""
+ if ctx.message.guild is not None:
+ if ctx.command.full_parent_name:
+ command = f'{ctx.command.full_parent_name} {ctx.command.name}'
+ else:
+ command = ctx.command.name
+
+ self.command_completions.labels(
+ guild_id=ctx.message.guild.id,
+ command=command,
+ ).inc()
+
def setup(bot: Bot) -> None:
"""Load the Metrics cog."""