Skip to content

Instantly share code, notes, and snippets.

@infideleraser
Last active November 4, 2018 18:58
Show Gist options
  • Save infideleraser/63f37092f57cae46d700a979ef7b41c7 to your computer and use it in GitHub Desktop.
Save infideleraser/63f37092f57cae46d700a979ef7b41c7 to your computer and use it in GitHub Desktop.
@commands.command(brief="Shows the system status of the host", aliases=['systeminfo'])
async def systemstats(self, ctx):
"""System Status."""
def solveunit(input):
output = ((input // 1024) // 1024) // 1024
return int(output)
total_seconds = int(time.time()) - int(psutil.boot_time())
mins, secs = divmod(total_seconds, 60)
hours, mins = divmod(mins, 60)
days, hours = divmod(hours, 24)
#botuptime = datetime.now() - counter
sysuptime = f"{int(days)} Days {int(hours)} Hours {int(mins)} Minutes {int(secs)} Seconds"
print('-1')
try:
mem_usage = "{:.2f} MiB".format(
psutil.Process().memory_full_info().uss / 1024 ** 2
)
except AttributeError:
mem_usage = "{:.2f} MiB".format(
psutil.Process().memory_full_info().rss / 1024 ** 2
)
print('1')
status = discord.Embed(
title="System Status.",
description="Shows the current system usage.",
color=0x00FF00,
)
print('2')
status.add_field(
name="CPU Usage.", value=f"{psutil.cpu_percent():.2f}%", inline=False
)
print('3')
status.add_field(
name="CPU Frequency.",
value=f"{psutil.cpu_freq().current} MHz",
inline=False,
)
print('4')
status.add_field(
name="Memory Usage.",
value=f"Total System Memory: {solveunit(psutil.virtual_memory().total):.2f} GB\nSystem Memory Usage: {psutil.virtual_memory().percent}%\nBot Memory Usage: {mem_usage}",
inline=False,
)
print('5')
status.add_field(
name="Disk Usage.",
value=f"Total Size: {solveunit(psutil.disk_usage('/').total)} GB \nCurrently Used: {solveunit(psutil.disk_usage('/').used)} GB",
inline=False,
)
print('6')
status.add_field(name="Current System Time.", value=time.ctime().strftime("%H:%M %p, %B %d, %Y"), inline=False)
status.add_field(
name="Last System Boot Time.",
value=datetime.fromtimestamp(psutil.boot_time()).strftime(
"%B %d, %Y at %H:%M %p"
),
inline=False,
)
print('7')
status.add_field(name="System Uptime.", value=sysuptime, inline=False)
#status.add_field(name="Bot Uptime.", value=botuptime, inline=False)
await ctx.send(content=None, embed=status)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment