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