reco-admin / app.py
rkonan's picture
version améliorée
3d9b28f
import streamlit as st
from endpoints_config import API_ENDPOINTS, ENV
from services.cache_admin import purge_cache
from services.stats_logs import fetch_stats_data, fetch_logs_data
from log import logger
logger.info(f"ENV : {ENV}")
st.set_page_config(page_title="Admin Recoplante", page_icon="🛠️", layout="wide")
st.title("🛠️ Tableau de bord d'administration Recoplante")
st.markdown("### ⚙️ Actions globales")
# Initialisation
if "confirm_clear_pred" not in st.session_state:
st.session_state.confirm_clear_pred = False
if "confirm_clear_heatmap" not in st.session_state:
st.session_state.confirm_clear_heatmap = False
col_global1, col_global2, col_global3 = st.columns(3)
# === Purge Prédictions ===
with col_global1:
if not st.session_state.confirm_clear_pred:
if st.button("🧹 Purger toutes les prédictions"):
st.session_state.confirm_clear_pred = True
st.rerun()
else:
st.warning("⚠️ Cette action supprimera toutes les prédictions en cache.")
if st.button("✅ Confirmer purge prédictions"):
for service_name, config in API_ENDPOINTS.items():
if "clear_pred" in config:
purge_cache(config, "clear_pred")
st.success("✅ Prédictions purgées.")
st.session_state.confirm_clear_pred = False
st.rerun()
if st.button("❌ Annuler", key="cancel_pred"):
st.session_state.confirm_clear_pred = False
st.rerun()
# === Purge Heatmaps ===
with col_global2:
if not st.session_state.confirm_clear_heatmap:
if st.button("🔥 Purger toutes les heatmaps"):
st.session_state.confirm_clear_heatmap = True
st.rerun()
else:
st.warning("⚠️ Cette action supprimera toutes les heatmaps en cache.")
if st.button("✅ Confirmer purge heatmaps"):
for service_name, config in API_ENDPOINTS.items():
if "clear_heatmap" in config:
purge_cache(config, "clear_heatmap")
st.success("✅ Heatmaps purgées.")
st.session_state.confirm_clear_heatmap = False
st.rerun()
if st.button("❌ Annuler", key="cancel_heatmap"):
st.session_state.confirm_clear_heatmap = False
st.rerun()
# === Rafraîchir toute la page ===
with col_global3:
if st.button("🔄 Rafraîchir tout"):
st.rerun()
# Pour chaque service/API
for service_name, config in API_ENDPOINTS.items():
st.markdown(f"## 🔹 {service_name}")
# Fetch live stats
stats = fetch_stats_data(config)
# Ligne d'état principale
col1, col2, col3, col4, col5, col6 = st.columns([1.5, 1, 1, 1, 1, 3])
with col1:
st.metric("Statut", "✅ OK" if stats else "❌ OFFLINE")
with col2:
st.metric("RAM", stats.get("memory_usage_mb", "–") if stats else "–", "MB")
with col3:
st.metric("Uptime", stats.get("uptime_human", "–") if stats else "–")
with col4:
st.metric("Requêtes", stats.get("request_count", "–") if stats else "–")
with col5:
st.metric("Cache", stats.get("cache_items", "–") if stats else "–")
with col6:
colb1, colb2, colb3 = st.columns(3)
with colb1:
if "logs" in config and st.button("📜 Logs", key=f"logs_{service_name}"):
logs = fetch_logs_data(config)
with st.expander(f"📜 Logs détaillés - {service_name}"):
st.code("".join(logs), language="bash")
with colb2:
if "clear_pred" in config and st.button("🧹 Pred", key=f"pred_{service_name}"):
purge_cache(config, "clear_pred")
with colb3:
if "clear_heatmap" in config and st.button("🔥 Heatmap", key=f"hm_{service_name}"):
purge_cache(config, "clear_heatmap")
if "clear_state" in config and st.button("♻️ Reset orchestrateur", key=f"reset_{service_name}"):
purge_cache(config, "clear_state")
st.markdown("---")
st.caption("⚙️ Interface Admin Recoplante — Pilotage centralisé de l’infrastructure")