From 65625acd63115bf1dfa45e13a35486efd26e04e6 Mon Sep 17 00:00:00 2001 From: Boves556 <148862792+Boves556@users.noreply.github.com> Date: Tue, 23 Jan 2024 09:54:49 +0100 Subject: [PATCH] Update my_python_script.py --- my_python_script.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/my_python_script.py b/my_python_script.py index 8b13789..cc8aa40 100644 --- a/my_python_script.py +++ b/my_python_script.py @@ -1 +1,30 @@ +import psutil +import speedtest +import time +def get_cpu_usage(): + return psutil.cpu_percent(interval=1) + +def get_memory_usage(): + return psutil.virtual_memory().percent + +def get_network_speed(): + st = speedtest.Speedtest() + download_speed = st.download() / 10**6 + upload_speed = st.upload() / 10**6 + return download_speed, upload_speed + +def monitor_and_output(): + while True: + cpu_usage = get_cpu_usage() + memory_usage = get_memory_usage() + + download_speed, upload_speed = get_network_speed() + + print(f"CPU Usage: {cpu_usage}% | Memory Usage: {memory_usage}%") + print(f"Download Speed: {download_speed:.2f} Mbps | Upload Speed: {upload_speed:.2f} Mbps") + + time.sleep(5) + +if __name__ == "__main__": + monitor_and_output()