SystemInfoCommand
Base classes
| Name |
Children |
Inherits |
SlashedCommand slashed.commands Base class for declarative commands. |
|
|
⋔ Inheritance diagram
graph TD
4111803577["system.SystemInfoCommand"]
807245086["commands.SlashedCommand"]
900363605["base.BaseCommand"]
925645236["abc.ABC"]
2751680898["builtins.object"]
807245086 --> 4111803577
900363605 --> 807245086
925645236 --> 900363605
2751680898 --> 925645236
🛈 DocStrings
Bases: SlashedCommand
Show system information.
Usage
/sysinfo
Displays
- OS information
- CPU usage
- Memory usage
- Disk usage
- Network interfaces
Requires
psutil package
Source code in src/slashed/builtin/system.py
| class SystemInfoCommand(SlashedCommand):
"""Show system information.
Usage:
/sysinfo
Displays:
- OS information
- CPU usage
- Memory usage
- Disk usage
- Network interfaces
Requires:
psutil package
"""
name = "sysinfo"
category = "system"
def is_available(self) -> bool:
return find_spec("psutil") is not None
async def execute_command(self, ctx: CommandContext[Any]) -> None:
"""Show system information."""
import psutil
cpu_percent = await asyncio.to_thread(psutil.cpu_percent, interval=1)
memory = psutil.virtual_memory()
disk = psutil.disk_usage("/")
info = [
"## System Information",
"",
f"**System:** {platform.system()} {platform.release()}",
f"**Python:** {sys.version.split()[0]}",
f"**CPU Usage:** {cpu_percent}%",
(
f"**Memory:** {memory.percent}% used "
f"({memory.used // 1024 // 1024}MB of {memory.total // 1024 // 1024}MB)"
),
(
f"**Disk:** {disk.percent}% used "
f"({disk.used // 1024 // 1024 // 1024}GB of "
f"{disk.total // 1024 // 1024 // 1024}GB)"
),
f"**Network interfaces:** `{', '.join(psutil.net_if_addrs().keys())}`",
]
await ctx.print("\n".join(info))
|
execute_command
async
Show system information.
Source code in src/slashed/builtin/system.py
| async def execute_command(self, ctx: CommandContext[Any]) -> None:
"""Show system information."""
import psutil
cpu_percent = await asyncio.to_thread(psutil.cpu_percent, interval=1)
memory = psutil.virtual_memory()
disk = psutil.disk_usage("/")
info = [
"## System Information",
"",
f"**System:** {platform.system()} {platform.release()}",
f"**Python:** {sys.version.split()[0]}",
f"**CPU Usage:** {cpu_percent}%",
(
f"**Memory:** {memory.percent}% used "
f"({memory.used // 1024 // 1024}MB of {memory.total // 1024 // 1024}MB)"
),
(
f"**Disk:** {disk.percent}% used "
f"({disk.used // 1024 // 1024 // 1024}GB of "
f"{disk.total // 1024 // 1024 // 1024}GB)"
),
f"**Network interfaces:** `{', '.join(psutil.net_if_addrs().keys())}`",
]
await ctx.print("\n".join(info))
|
:fa-brands-github: Show source on GitHub