From 7805f8ad212bfc23391dd49f311501eed2c66166 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Sun, 12 Jan 2020 20:02:17 +0100 Subject: Track command completions. --- bot/cogs/metrics.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/bot/cogs/metrics.py b/bot/cogs/metrics.py index 6d3cc67bd..aff1b0eb2 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,27 @@ 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: + path = [] + if ( + ctx.command.root_parent is not None + and ctx.command.root_parent is not ctx.command.parent + ): + path.append(ctx.command.root_parent.name) + + if ctx.command.parent is not None: + path.append(ctx.command.parent.name) + + path.append(ctx.command.name) + + self.command_completions.labels( + guild_id=ctx.message.guild.id, + command=' '.join(path), + ).inc() + def setup(bot: Bot) -> None: """Load the Metrics cog.""" -- cgit v1.2.3 From b0b9cdd0d54230c50bf6b4620909477d4adde8b7 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Sun, 12 Jan 2020 20:10:23 +0100 Subject: Use parent path properly. --- bot/cogs/metrics.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/bot/cogs/metrics.py b/bot/cogs/metrics.py index aff1b0eb2..fa858bbd6 100644 --- a/bot/cogs/metrics.py +++ b/bot/cogs/metrics.py @@ -80,21 +80,14 @@ class Metrics(Cog): async def on_command_completion(self, ctx: Context) -> None: """Increment the command completion counter.""" if ctx.message.guild is not None: - path = [] - if ( - ctx.command.root_parent is not None - and ctx.command.root_parent is not ctx.command.parent - ): - path.append(ctx.command.root_parent.name) - - if ctx.command.parent is not None: - path.append(ctx.command.parent.name) - - path.append(ctx.command.name) + 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=' '.join(path), + command=command, ).inc() -- cgit v1.2.3