Skip to content

Commit

Permalink
Merge branch 'main' into tts-commands
Browse files Browse the repository at this point in the history
  • Loading branch information
GitGinocchio authored Feb 12, 2025
2 parents 2fd546a + 5962733 commit 6c08bf7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ install:
uninstall:
pip uninstall -y -r requirements.txt

freeze:
pip freeze > requirements.txt

clearpycache:
python ./src/.make/clearpycache.py

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ nextcord==3.0.1
numpy==2.2.2
pillow==10.4.0
propcache==0.2.1
psutil==6.1.1
pycparser==2.22
pycryptodomex==3.21.0
pydantic==2.10.6
Expand Down
52 changes: 47 additions & 5 deletions src/commands/web/HTTPServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
Response, \
Request, \
TCPSite
from datetime import datetime, timezone
import psutil
import json
import ssl

from utils.terminal import getlogger

Expand All @@ -20,19 +24,57 @@ def __init__(self, bot : Bot):
self.bot = bot

self.app.router.add_get('/', self.index)
self.app.router.add_get('/api/status', self.api_status)

async def index(self, request : Request):
return Response(text="Hello World!", content_type="text/plain")

async def api_status(self, request : Request):
uptime = datetime.now(timezone.utc) - datetime.fromtimestamp(psutil.boot_time(), timezone.utc)

# Cpu
cpu_count = {'physical': psutil.cpu_count(False), 'logical': psutil.cpu_count()}
cpu_freqs = [{'current': freq.current, 'min': freq.min, 'max': freq.max} for freq in psutil.cpu_freq(True)]
cpu_usage = { 'percpu' : psutil.cpu_percent(percpu=True), 'total' : psutil.cpu_percent()}

# Memory
ram_usage = {'available': (memory:=psutil.virtual_memory()).available,'free' : memory.free,'percent' : memory.percent,'total' : memory.total,'used' : memory.used}

# Disk
disk_usage = { 'total' : (disk:=psutil.disk_usage('/')).total, 'used' : disk.used, 'free' : disk.free, 'percent' : disk.percent }

# Swap

swap_usage = { 'total' : (swap:=psutil.swap_memory()).total, 'used' : swap.used, 'free' : swap.free, 'percent' : swap.percent, 'sin' : swap.sin, 'sout' : swap.sout }

status = {
'uptime' : str(uptime),
'cpu' : {
'count' : cpu_count,
'freqs' : cpu_freqs,
'usage' : cpu_usage
},
'memory' : ram_usage,
'disk' : disk_usage,
'swap' : swap_usage,

'discord' : {
'latency' : self.bot.latency
}
}

return Response(text=json.dumps(status), content_type="application/json")

@Cog.listener()
async def on_ready(self):
runner = AppRunner(self.app)
await runner.setup()
site = TCPSite(runner, self.address, self.port)
await site.start()
logger.info(f"HTTP Server started on {self.protocol}://{self.address}:{self.port}")
try:
runner = AppRunner(self.app)
await runner.setup()
site = TCPSite(runner, self.address, self.port)
await site.start()
logger.info(f"HTTP Server started on {self.protocol}://{self.address}:{self.port}")
except Exception as e:
raise e



Expand Down

0 comments on commit 6c08bf7

Please sign in to comment.