-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addition of actual files.
- Loading branch information
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"apps": [{ | ||
"name": "Server Specs", | ||
"cwd": "./", | ||
"script": "server_monitor.py", | ||
"args": "", | ||
"interpreter": "python3" | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import discord | ||
|
||
client = discord.Client() | ||
CHANNEL_ID = 740585774055161986 #Insert channel ID here | ||
print('One moment...') | ||
|
||
@client.event | ||
async def on_ready(): | ||
e = discord.Embed(title='Server information.', colour=discord.Colour.green()) | ||
e.add_field(name="CPU infomation", value="Null") | ||
e.add_field(name="RAM information", value="Null") | ||
e.add_field(name="Network information", value="Null") | ||
e.set_footer(text=f"Null") | ||
channel = await client.fetch_channel(CHANNEL_ID) | ||
message = await channel.send(embed=e) | ||
print(f"Setup complete!. Channel ID: {CHANNEL_ID} Message ID: {message.id}") | ||
print("Please copy this information into the main file. You may delete this file if you wish.") | ||
|
||
client.run('token') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import discord | ||
import asyncio | ||
import psutil | ||
from discord.ext import tasks | ||
from datetime import datetime | ||
from uptime import uptime | ||
|
||
|
||
intents = discord.Intents.default() | ||
client = discord.Client(intents=intents) | ||
|
||
CHANNEL_ID = 12345678910 # Insert channel ID here | ||
MESSAGE_ID = 10987654321 # Insert message ID here | ||
|
||
def b2h(n): | ||
symbols = ('KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB') | ||
prefix = {} | ||
for i, s in enumerate(symbols): | ||
prefix[s] = 1 << (i + 1) * 10 | ||
for s in reversed(symbols): | ||
if n >= prefix[s]: | ||
value = float(n) / prefix[s] | ||
return '%.1f%s' % (value, s) | ||
return "%sB" % n | ||
|
||
|
||
@client.event | ||
async def on_ready(): | ||
print("Online!") | ||
|
||
@tasks.loop(minutes=1) | ||
async def useful(): | ||
await client.wait_until_ready() | ||
message = await client.get_channel(CHANNEL_ID).fetch_message(MESSAGE_ID) | ||
while not client.is_closed(): | ||
cpu = psutil.cpu_percent() | ||
ram = psutil.virtual_memory() | ||
net = psutil.net_io_counters() | ||
await asyncio.sleep(1) | ||
net2 = psutil.net_io_counters() | ||
if net.bytes_recv > net2.bytes_recv: | ||
current_in = 0 | ||
else: | ||
current_in = net2.bytes_recv - net.bytes_recv | ||
if net.bytes_sent > net2.bytes_sent: | ||
current_out = 0 | ||
else: | ||
current_out = net2.bytes_sent - net.bytes_sent | ||
delta_uptime = uptime() | ||
hours, remainder = divmod(int(delta_uptime), 3600) | ||
minutes, seconds = divmod(remainder, 60) | ||
days, hours = divmod(hours, 24) | ||
newEmbed = discord.Embed(title='Server information.', colour=discord.Colour.green()) | ||
newEmbed.add_field(name="CPU infomation", value=f"{cpu}/100%") | ||
newEmbed.add_field(name="RAM information", value=f"{b2h(ram.used)}/{b2h(ram.total)}. Percentage: {ram.percent}%") | ||
newEmbed.add_field(name="Network information", value=f"Bytes sent: {b2h(current_out)} Bytes recieved: {b2h(current_in)} \nBytes sent in total: {b2h(net.bytes_sent)}. Bytes recieved in total: {b2h(net.bytes_recv)}") | ||
newEmbed.set_footer(text=f"Server online for: {days}d, {hours}h, {minutes}m, and {seconds}s") | ||
await message.edit(embed = newEmbed) | ||
await asyncio.sleep(30) | ||
|
||
useful.start() | ||
|
||
client.run('token') |