Skip to content

Commit

Permalink
Update my_python_script.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Boves556 authored Jan 23, 2024
1 parent 9eb155b commit 65625ac
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions my_python_script.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 65625ac

Please sign in to comment.