Update pages/dashboard.py
Browse files- pages/dashboard.py +98 -1
pages/dashboard.py
CHANGED
@@ -217,4 +217,101 @@ def create_realtime_section():
|
|
217 |
auto_refresh = st.checkbox("Enable Auto-refresh", value=False)
|
218 |
|
219 |
if auto_refresh:
|
220 |
-
refresh_interval = st.slider("Refresh Interval (seconds)",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
auto_refresh = st.checkbox("Enable Auto-refresh", value=False)
|
218 |
|
219 |
if auto_refresh:
|
220 |
+
refresh_interval = st.slider("Refresh Interval (seconds)", 1, 60, 5)
|
221 |
+
st.info(f"Data will refresh every {refresh_interval} seconds")
|
222 |
+
|
223 |
+
# Real-time metrics
|
224 |
+
col1, col2, col3 = st.columns(3)
|
225 |
+
|
226 |
+
# Generate real-time data
|
227 |
+
current_time = datetime.now()
|
228 |
+
|
229 |
+
with col1:
|
230 |
+
cpu_usage = np.random.uniform(20, 80)
|
231 |
+
st.metric("CPU Usage", f"{cpu_usage:.1f}%", f"{np.random.uniform(-5, 5):.1f}%")
|
232 |
+
|
233 |
+
with col2:
|
234 |
+
memory_usage = np.random.uniform(30, 90)
|
235 |
+
st.metric("Memory Usage", f"{memory_usage:.1f}%", f"{np.random.uniform(-3, 3):.1f}%")
|
236 |
+
|
237 |
+
with col3:
|
238 |
+
active_connections = np.random.randint(100, 500)
|
239 |
+
st.metric("Active Connections", active_connections, np.random.randint(-10, 20))
|
240 |
+
|
241 |
+
# Real-time chart
|
242 |
+
st.subheader("π Real-time Performance")
|
243 |
+
|
244 |
+
# Generate time series data
|
245 |
+
time_points = pd.date_range(end=current_time, periods=50, freq='1T')
|
246 |
+
performance_data = {
|
247 |
+
'Time': time_points,
|
248 |
+
'CPU': np.random.uniform(20, 80, 50),
|
249 |
+
'Memory': np.random.uniform(30, 90, 50),
|
250 |
+
'Network': np.random.uniform(10, 60, 50)
|
251 |
+
}
|
252 |
+
|
253 |
+
df_realtime = pd.DataFrame(performance_data)
|
254 |
+
|
255 |
+
# Create multi-line chart
|
256 |
+
fig = go.Figure()
|
257 |
+
|
258 |
+
for metric in ['CPU', 'Memory', 'Network']:
|
259 |
+
fig.add_trace(go.Scatter(
|
260 |
+
x=df_realtime['Time'],
|
261 |
+
y=df_realtime[metric],
|
262 |
+
mode='lines+markers',
|
263 |
+
name=f'{metric} %',
|
264 |
+
line=dict(width=2)
|
265 |
+
))
|
266 |
+
|
267 |
+
fig.update_layout(
|
268 |
+
title='System Performance Over Time',
|
269 |
+
xaxis_title='Time',
|
270 |
+
yaxis_title='Usage (%)',
|
271 |
+
hovermode='x unified'
|
272 |
+
)
|
273 |
+
|
274 |
+
st.plotly_chart(fig, use_container_width=True)
|
275 |
+
|
276 |
+
# Status indicators
|
277 |
+
st.subheader("π¨ System Status")
|
278 |
+
|
279 |
+
col1, col2, col3, col4 = st.columns(4)
|
280 |
+
|
281 |
+
with col1:
|
282 |
+
status = "π’ Online" if np.random.random() > 0.1 else "π΄ Offline"
|
283 |
+
st.write(f"**Database:** {status}")
|
284 |
+
|
285 |
+
with col2:
|
286 |
+
status = "π’ Healthy" if np.random.random() > 0.05 else "π‘ Warning"
|
287 |
+
st.write(f"**API:** {status}")
|
288 |
+
|
289 |
+
with col3:
|
290 |
+
status = "π’ Running" if np.random.random() > 0.02 else "π΄ Down"
|
291 |
+
st.write(f"**Services:** {status}")
|
292 |
+
|
293 |
+
with col4:
|
294 |
+
status = "π’ Good" if np.random.random() > 0.15 else "π‘ Slow"
|
295 |
+
st.write(f"**Network:** {status}")
|
296 |
+
|
297 |
+
# Recent events log
|
298 |
+
st.subheader("π Recent Events")
|
299 |
+
|
300 |
+
events = [
|
301 |
+
{"time": current_time - timedelta(minutes=2), "event": "System backup completed", "type": "info"},
|
302 |
+
{"time": current_time - timedelta(minutes=5), "event": "High CPU usage detected", "type": "warning"},
|
303 |
+
{"time": current_time - timedelta(minutes=8), "event": "New user registration", "type": "info"},
|
304 |
+
{"time": current_time - timedelta(minutes=12), "event": "Database connection restored", "type": "success"},
|
305 |
+
{"time": current_time - timedelta(minutes=15), "event": "Scheduled maintenance started", "type": "info"},
|
306 |
+
]
|
307 |
+
|
308 |
+
for event in events:
|
309 |
+
icon = {"info": "βΉοΈ", "warning": "β οΈ", "success": "β
", "error": "β"}.get(event["type"], "π")
|
310 |
+
st.write(f"{icon} **{event['time'].strftime('%H:%M:%S')}** - {event['event']}")
|
311 |
+
|
312 |
+
# Auto-refresh functionality
|
313 |
+
if auto_refresh:
|
314 |
+
# Use Streamlit's rerun to refresh the page
|
315 |
+
import time
|
316 |
+
time.sleep(refresh_interval)
|
317 |
+
st.rerun()
|