From 8fcc265189c5ebc32197a5acdb6b335139a0d5b4 Mon Sep 17 00:00:00 2001 From: hassan90122 Date: Tue, 28 Jul 2026 18:29:19 +0000 Subject: [PATCH] Enable CORS for dashboard --- app.py | 4 +-- dashboard/index.html | 34 ++++++++++++++++++++++ dashboard/script.js | 67 +++++++++++++++++++++++++++++++++++++++++++ dashboard/style.css | 32 +++++++++++++++++++++ monitoring/monitor.py | 49 +++++++++++++++++++++++++++++++ 5 files changed, 184 insertions(+), 2 deletions(-) create mode 100644 dashboard/index.html create mode 100644 dashboard/script.js create mode 100644 dashboard/style.css create mode 100644 monitoring/monitor.py diff --git a/app.py b/app.py index d1be3bd..03c0d56 100644 --- a/app.py +++ b/app.py @@ -1,8 +1,8 @@ from flask import Flask, jsonify from datetime import datetime - +from flask_cors import CORS app = Flask(__name__) - +CORS(app) request_count = 0 diff --git a/dashboard/index.html b/dashboard/index.html new file mode 100644 index 0000000..8930b22 --- /dev/null +++ b/dashboard/index.html @@ -0,0 +1,34 @@ + + + + + Ghaymah SRE Dashboard + + + + + +

Ghaymah SRE Dashboard

+ + +
+ +

Status

+

Checking...

+ + +

Response Time

+

-

+ + +

Total Requests

+

-

+ +
+ + + + + + + diff --git a/dashboard/script.js b/dashboard/script.js new file mode 100644 index 0000000..b4717e8 --- /dev/null +++ b/dashboard/script.js @@ -0,0 +1,67 @@ +const API_URL = +"https://ghaymah-sre-api-20e343cababc.hosted.ghaymah.systems"; + + +async function checkApplication(){ + + try { + + let start = Date.now(); + + + let healthResponse = + await fetch(API_URL + "/health"); + + + let end = Date.now(); + + + let responseTime = + end - start; + + + + let statsResponse = + await fetch(API_URL + "/stats"); + + + let stats = + await statsResponse.json(); + + + + document.getElementById("status").innerHTML = + healthResponse.ok ? "UP" : "DOWN"; + + + document.getElementById("response").innerHTML = + responseTime + " ms"; + + + document.getElementById("requests").innerHTML = + stats.requests; + + + + } + + catch(error){ + + document.getElementById("status").innerHTML = + "DOWN"; + + console.log(error); + + } + +} + + + +checkApplication(); + + +setInterval( + checkApplication, + 30000 +); diff --git a/dashboard/style.css b/dashboard/style.css new file mode 100644 index 0000000..af9cdac --- /dev/null +++ b/dashboard/style.css @@ -0,0 +1,32 @@ +body { + + font-family: Arial, sans-serif; + text-align: center; + background: #f4f4f4; + +} + + +h1 { + + margin-top: 40px; + +} + + +.card { + + background: white; + width: 350px; + margin: 40px auto; + padding: 25px; + border-radius: 10px; + +} + + +p { + + font-size: 22px; + +} diff --git a/monitoring/monitor.py b/monitoring/monitor.py new file mode 100644 index 0000000..988cc04 --- /dev/null +++ b/monitoring/monitor.py @@ -0,0 +1,49 @@ +import requests +import time +from datetime import datetime + + +URL = "https://ghaymah-sre-api-20e343cababc.hosted.ghaymah.systems/health" + + +while True: + + try: + start = time.time() + + response = requests.get(URL) + + end = time.time() + + response_time = round(end - start, 3) + + + if response.status_code == 200: + + print( + datetime.now(), + "UP", + "Response time:", + response_time, + "seconds" + ) + + else: + + print( + datetime.now(), + "DOWN", + response.status_code + ) + + + except Exception as e: + + print( + datetime.now(), + "ERROR", + e + ) + + + time.sleep(30)