Update ui.py
Browse files
ui.py
CHANGED
|
@@ -13,10 +13,14 @@ def get_system_metrics():
|
|
| 13 |
|
| 14 |
# Function to get internet speed
|
| 15 |
def get_internet_speed():
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Function to create a gauge chart
|
| 22 |
def create_gauge_chart(value, title, min_value=0, max_value=100):
|
|
@@ -34,9 +38,11 @@ def create_gauge_chart(value, title, min_value=0, max_value=100):
|
|
| 34 |
# Streamlit layout
|
| 35 |
st.title("System Monitoring Dashboard")
|
| 36 |
|
| 37 |
-
# Create
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# Update the metrics in real-time
|
| 42 |
while True:
|
|
@@ -44,14 +50,20 @@ while True:
|
|
| 44 |
download_speed, upload_speed = get_internet_speed()
|
| 45 |
|
| 46 |
# Create gauge charts
|
| 47 |
-
with
|
| 48 |
st.plotly_chart(create_gauge_chart(cpu_usage, "CPU Usage"), use_container_width=True)
|
| 49 |
-
with
|
| 50 |
st.plotly_chart(create_gauge_chart(memory_usage, "Memory Usage"), use_container_width=True)
|
| 51 |
-
with
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
# Refresh the metrics every
|
| 57 |
-
time.sleep(
|
|
|
|
| 13 |
|
| 14 |
# Function to get internet speed
|
| 15 |
def get_internet_speed():
|
| 16 |
+
try:
|
| 17 |
+
st = speedtest.Speedtest()
|
| 18 |
+
st.get_best_server()
|
| 19 |
+
download_speed = st.download() / 1_000_000 # Convert to Mbps
|
| 20 |
+
upload_speed = st.upload() / 1_000_000 # Convert to Mbps
|
| 21 |
+
return download_speed, upload_speed
|
| 22 |
+
except:
|
| 23 |
+
return None, None
|
| 24 |
|
| 25 |
# Function to create a gauge chart
|
| 26 |
def create_gauge_chart(value, title, min_value=0, max_value=100):
|
|
|
|
| 38 |
# Streamlit layout
|
| 39 |
st.title("System Monitoring Dashboard")
|
| 40 |
|
| 41 |
+
# Create placeholders for each gauge
|
| 42 |
+
cpu_placeholder = st.empty()
|
| 43 |
+
memory_placeholder = st.empty()
|
| 44 |
+
download_placeholder = st.empty()
|
| 45 |
+
upload_placeholder = st.empty()
|
| 46 |
|
| 47 |
# Update the metrics in real-time
|
| 48 |
while True:
|
|
|
|
| 50 |
download_speed, upload_speed = get_internet_speed()
|
| 51 |
|
| 52 |
# Create gauge charts
|
| 53 |
+
with cpu_placeholder:
|
| 54 |
st.plotly_chart(create_gauge_chart(cpu_usage, "CPU Usage"), use_container_width=True)
|
| 55 |
+
with memory_placeholder:
|
| 56 |
st.plotly_chart(create_gauge_chart(memory_usage, "Memory Usage"), use_container_width=True)
|
| 57 |
+
with download_placeholder:
|
| 58 |
+
if download_speed is not None:
|
| 59 |
+
st.plotly_chart(create_gauge_chart(download_speed, "Download Speed (Mbps)", 0, 1000), use_container_width=True)
|
| 60 |
+
else:
|
| 61 |
+
st.write("Error retrieving download speed")
|
| 62 |
+
with upload_placeholder:
|
| 63 |
+
if upload_speed is not None:
|
| 64 |
+
st.plotly_chart(create_gauge_chart(upload_speed, "Upload Speed (Mbps)", 0, 1000), use_container_width=True)
|
| 65 |
+
else:
|
| 66 |
+
st.write("Error retrieving upload speed")
|
| 67 |
|
| 68 |
+
# Refresh the metrics every 10 seconds
|
| 69 |
+
time.sleep(10)
|