feat: Initial commit of existing overlay files
This commit is contained in:
25
system_monitor_overlay/server.py
Normal file
25
system_monitor_overlay/server.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import psutil
|
||||
import http.server
|
||||
import socketserver
|
||||
import json
|
||||
|
||||
PORT = 8000
|
||||
|
||||
class SystemInfoHandler(http.server.SimpleHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
if self.path == '/stats':
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self.send_header('Access-Control-Allow-Origin', '*')
|
||||
self.end_headers()
|
||||
stats = {
|
||||
'cpu_percent': psutil.cpu_percent(interval=1),
|
||||
'memory_percent': psutil.virtual_memory().percent
|
||||
}
|
||||
self.wfile.write(json.dumps(stats).encode('utf-8'))
|
||||
else:
|
||||
super().do_GET()
|
||||
|
||||
with socketserver.TCPServer(('', PORT), SystemInfoHandler) as httpd:
|
||||
print("serving at port", PORT)
|
||||
httpd.serve_forever()
|
||||
Reference in New Issue
Block a user