From 25f2308139963b5f62723b1b0b1bba9e4615d9e7 Mon Sep 17 00:00:00 2001 From: wlinator Date: Tue, 3 Sep 2024 10:03:32 -0400 Subject: [PATCH 1/2] refactor: Fix the CPU and RAM usage in the Ping command --- tux/cogs/utility/ping.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tux/cogs/utility/ping.py b/tux/cogs/utility/ping.py index e43a1ad70..d65007815 100644 --- a/tux/cogs/utility/ping.py +++ b/tux/cogs/utility/ping.py @@ -27,15 +27,16 @@ async def ping(self, ctx: commands.Context[Tux]) -> None: discord_ping = round(self.bot.latency * 1000) # Get the CPU usage and RAM usage of the bot - cpu_usage = psutil.cpu_percent() + cpu_usage = psutil.Process().cpu_percent() # Get the amount of RAM used by the bot - ram_amount = psutil.virtual_memory().used + ram_amount_in_bytes = psutil.Process().memory_info().rss + ram_amount_in_mb = ram_amount_in_bytes / (1024 * 1024) # Format the RAM usage to be in GB or MB - if ram_amount >= 1024**3: - ram_amount_formatted = f"{ram_amount // (1024**3)}GB" + if ram_amount_in_mb >= 1024: + ram_amount_formatted = f"{ram_amount_in_mb / 1024:.2f}GB" else: - ram_amount_formatted = f"{ram_amount // (1024**2)}MB" + ram_amount_formatted = f"{ram_amount_in_mb:.2f}MB" embed = EmbedCreator.create_success_embed( title="Pong!", From 4221d3b092dac5a95f6c881f382ce9886cb61c4b Mon Sep 17 00:00:00 2001 From: wlinator Date: Tue, 3 Sep 2024 10:29:53 -0400 Subject: [PATCH 2/2] refactor: Format RAM usage in Ping command to nearest integer --- tux/cogs/utility/ping.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tux/cogs/utility/ping.py b/tux/cogs/utility/ping.py index d65007815..a04324031 100644 --- a/tux/cogs/utility/ping.py +++ b/tux/cogs/utility/ping.py @@ -32,11 +32,11 @@ async def ping(self, ctx: commands.Context[Tux]) -> None: ram_amount_in_bytes = psutil.Process().memory_info().rss ram_amount_in_mb = ram_amount_in_bytes / (1024 * 1024) - # Format the RAM usage to be in GB or MB + # Format the RAM usage to be in GB or MB, rounded to nearest integer if ram_amount_in_mb >= 1024: - ram_amount_formatted = f"{ram_amount_in_mb / 1024:.2f}GB" + ram_amount_formatted = f"{round(ram_amount_in_mb / 1024)}GB" else: - ram_amount_formatted = f"{ram_amount_in_mb:.2f}MB" + ram_amount_formatted = f"{round(ram_amount_in_mb)}MB" embed = EmbedCreator.create_success_embed( title="Pong!",