Update app.py
Browse files
app.py
CHANGED
|
@@ -210,61 +210,57 @@ threading.Thread(target=background_updates, daemon=True).start()
|
|
| 210 |
with gr.Blocks(title="Website Status Monitor") as demo:
|
| 211 |
gr.Markdown("# 🚦 Website Status Monitor")
|
| 212 |
|
| 213 |
-
#
|
| 214 |
-
|
| 215 |
-
|
| 216 |
def update_ui():
|
| 217 |
data = monitor.load_data()
|
|
|
|
| 218 |
metrics = monitor.get_metrics(data)
|
|
|
|
| 219 |
plots = monitor.create_plots(metrics)
|
|
|
|
| 220 |
|
| 221 |
-
|
| 222 |
-
children = []
|
| 223 |
-
|
| 224 |
for name, metric in metrics.items():
|
| 225 |
-
with gr.Row()
|
| 226 |
-
# Status Card
|
| 227 |
with gr.Column(scale=1):
|
| 228 |
status_color = "#4CAF50" if metric['current_status'] == 'UP' else "#F44336"
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
)
|
| 235 |
|
| 236 |
-
# Plots
|
| 237 |
with gr.Column(scale=2):
|
| 238 |
response_plot = gr.Plot(plots[f"{name}_response"], label="Response Times")
|
|
|
|
| 239 |
|
| 240 |
with gr.Column(scale=1):
|
| 241 |
uptime_plot = gr.Plot(plots[f"{name}_uptime"], label="Uptime")
|
|
|
|
| 242 |
|
| 243 |
-
# Incident History
|
| 244 |
with gr.Accordion("Incident History", open=False):
|
| 245 |
if not metric['incidents']:
|
| 246 |
-
gr.Markdown("No incidents in past 24 hours")
|
|
|
|
| 247 |
else:
|
| 248 |
for incident in metric['incidents'][-5:]:
|
| 249 |
duration = incident['duration'] or "Ongoing"
|
| 250 |
-
gr.Markdown(
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
)
|
| 255 |
|
| 256 |
-
return
|
| 257 |
|
| 258 |
-
# Initialize UI with
|
| 259 |
-
|
|
|
|
| 260 |
|
| 261 |
-
#
|
| 262 |
-
demo.load(
|
| 263 |
-
fn=update_ui,
|
| 264 |
-
inputs=None,
|
| 265 |
-
outputs=[dashboard],
|
| 266 |
-
every=5 # Refresh interval in seconds
|
| 267 |
-
)
|
| 268 |
|
| 269 |
if __name__ == "__main__":
|
| 270 |
demo.launch(server_name="0.0.0.0", server_port=int(os.getenv("PORT", 7860)))
|
|
|
|
| 210 |
with gr.Blocks(title="Website Status Monitor") as demo:
|
| 211 |
gr.Markdown("# 🚦 Website Status Monitor")
|
| 212 |
|
| 213 |
+
# Placeholder for dynamic components
|
| 214 |
+
status_components = []
|
| 215 |
+
|
| 216 |
def update_ui():
|
| 217 |
data = monitor.load_data()
|
| 218 |
+
print("Loaded data:", data)
|
| 219 |
metrics = monitor.get_metrics(data)
|
| 220 |
+
print("Metrics:", metrics)
|
| 221 |
plots = monitor.create_plots(metrics)
|
| 222 |
+
print("Plots created.")
|
| 223 |
|
| 224 |
+
elements = []
|
|
|
|
|
|
|
| 225 |
for name, metric in metrics.items():
|
| 226 |
+
with gr.Row():
|
|
|
|
| 227 |
with gr.Column(scale=1):
|
| 228 |
status_color = "#4CAF50" if metric['current_status'] == 'UP' else "#F44336"
|
| 229 |
+
status_markdown = gr.Markdown(f"### {name}\n"
|
| 230 |
+
f"**Status:** <span style='color: {status_color}'>"
|
| 231 |
+
f"{metric['current_status']}</span>\n"
|
| 232 |
+
f"**Last Response:** {np.mean(metric['response_times'][-5:]):.2f}s\n"
|
| 233 |
+
f"**24h Uptime:** {metric['uptime']*100:.1f}%")
|
| 234 |
+
elements.append(status_markdown)
|
| 235 |
|
|
|
|
| 236 |
with gr.Column(scale=2):
|
| 237 |
response_plot = gr.Plot(plots[f"{name}_response"], label="Response Times")
|
| 238 |
+
elements.append(response_plot)
|
| 239 |
|
| 240 |
with gr.Column(scale=1):
|
| 241 |
uptime_plot = gr.Plot(plots[f"{name}_uptime"], label="Uptime")
|
| 242 |
+
elements.append(uptime_plot)
|
| 243 |
|
|
|
|
| 244 |
with gr.Accordion("Incident History", open=False):
|
| 245 |
if not metric['incidents']:
|
| 246 |
+
incident_markdown = gr.Markdown("No incidents in past 24 hours")
|
| 247 |
+
elements.append(incident_markdown)
|
| 248 |
else:
|
| 249 |
for incident in metric['incidents'][-5:]:
|
| 250 |
duration = incident['duration'] or "Ongoing"
|
| 251 |
+
incident_markdown = gr.Markdown(f"**Start:** {incident['start']}\n"
|
| 252 |
+
f"**End:** {incident['end'] or 'Still down'}\n"
|
| 253 |
+
f"**Duration:** {duration}s\n")
|
| 254 |
+
elements.append(incident_markdown)
|
|
|
|
| 255 |
|
| 256 |
+
return elements
|
| 257 |
|
| 258 |
+
# Initialize the UI with placeholders
|
| 259 |
+
initial_elements = update_ui()
|
| 260 |
+
status_components.extend(initial_elements)
|
| 261 |
|
| 262 |
+
# Load the UI with the specified components
|
| 263 |
+
demo.load(update_ui, outputs=status_components)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
if __name__ == "__main__":
|
| 266 |
demo.launch(server_name="0.0.0.0", server_port=int(os.getenv("PORT", 7860)))
|