from flask import Flask, jsonify, render_template_string, send_file import os import json import subprocess app = Flask(__name__) METRICS_FILE = os.path.join(os.path.dirname(__file__), "q5-mithal-monitoring", "metrics.json") @app.route('/') def home(): return jsonify({ "status": "healthy", "service": "Ghaymah SRE Engine", "endpoints": [ "/health", "/dashboard", "/mithal-dashboard", "/api/mithal-metrics" ] }), 200 @app.route('/health') def health(): return jsonify({"status": "UP", "database": "connected"}), 200 @app.route('/dashboard') def dashboard(): dashboard_path = os.path.join(os.path.dirname(__file__), 'dashboard.html') if os.path.exists(dashboard_path): return send_file(dashboard_path) return "Dashboard HTML not found", 404 @app.route('/mithal-dashboard') def mithal_dashboard(): # Trigger a fresh check try: subprocess.run(["python3", "q5-mithal-monitoring/monitor.py"], timeout=10) except Exception: pass dashboard_path = os.path.join(os.path.dirname(__file__), 'q5-mithal-monitoring', 'dashboard.html') if os.path.exists(dashboard_path): return send_file(dashboard_path) return "Mithal Dashboard HTML not found", 404 @app.route('/api/mithal-metrics') def mithal_metrics(): if os.path.exists(METRICS_FILE): with open(METRICS_FILE, "r") as f: data = json.load(f) return jsonify(data) return jsonify([]) if __name__ == '__main__': app.run(host='0.0.0.0', port=5000)