Skip to content

Commit ab67902

Browse files
committed
lib: Allow to order processes by cpu usage
1 parent 1855f2c commit ab67902

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

discordbotlinuxmonitor/__main__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,13 @@ async def list_services(interaction: discord.Interaction) -> None: # type: ignor
110110
async def ports(interaction: discord.Interaction) -> None: # type: ignore
111111
await discord_bot_linux_monitor.ports(interaction)
112112

113-
@discord_bot.tree.command(name="list_processes", description="[Private] 📋 List active processes 📋")
113+
@discord_bot.tree.command(name="list_processes", description="[Private] 📋 List active processes (ordered by RAM usage) 📋")
114114
async def list_processes(interaction: discord.Interaction) -> None: # type: ignore
115-
await discord_bot_linux_monitor.list_processes(interaction)
115+
await discord_bot_linux_monitor.list_processes(interaction, order_by_ram=True)
116+
117+
@discord_bot.tree.command(name="list_processes_ordered_by_cpu_usage", description="[Private] 📋 List active processes (ordered by CPU usage) 📋")
118+
async def list_processes(interaction: discord.Interaction) -> None: # type: ignore
119+
await discord_bot_linux_monitor.list_processes(interaction, order_by_ram=False)
116120

117121
@discord_bot.tree.command(name="kill_process", description="[Private] 🚫 Stop a process by PID 🚫")
118122
async def kill_process(interaction: discord.Interaction, pid: int) -> None: # type: ignore

discordbotlinuxmonitor/discordbotlinuxmonitor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
__license__ = "MIT License"
3434
__copyright__ = "Copyright Quentin Comte-Gaz (2024)"
3535
__python_version__ = "3.+"
36-
__version__ = "1.4.0 (2024/10/07)"
36+
__version__ = "1.4.1 (2024/10/07)"
3737
__status__ = "Usable for any Linux project"
3838

3939
# pyright: reportMissingTypeStubs=false
@@ -736,7 +736,7 @@ async def ports(self, interaction: discord.Interaction) -> None:
736736
logging.exception(msg=out_msg)
737737
await self._interaction_followup_send_no_limit(interaction=interaction, msg=out_msg)
738738

739-
async def list_processes(self, interaction: discord.Interaction) -> None:
739+
async def list_processes(self, interaction: discord.Interaction, order_by_ram: bool) -> None:
740740
if not self._check_if_valid_guild(guild=interaction.guild):
741741
return
742742
if not (await self._is_bot_channel_interaction(interaction=interaction, send_message_if_not_bot=True)):
@@ -750,7 +750,7 @@ async def list_processes(self, interaction: discord.Interaction) -> None:
750750

751751
try:
752752
# Récupérer la liste des processus actifs
753-
out_msg: str = await self.monitoring.get_ordered_processes()
753+
out_msg: str = await self.monitoring.get_ordered_processes(get_non_consuming_processes=False, order_by_ram=order_by_ram)
754754

755755
# Répondre à l'utilisateur
756756
await self._interaction_followup_send_no_limit(interaction=interaction, msg=out_msg)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name="DiscordBotLinuxMonitor",
9-
version="1.4.0",
9+
version="1.4.1",
1010
description="From discord channels: Get information and warning status of Linux server like service, port, ping, ssl certificate, disk/folder/cpu/ram/swap usage, ip connection, ... (Python and shell library, Linux ONLY)",
1111
long_description=readme,
1212
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)