Enable CORS for dashboard
هذا الالتزام موجود في:
4
app.py
4
app.py
@@ -1,8 +1,8 @@
|
|||||||
from flask import Flask, jsonify
|
from flask import Flask, jsonify
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from flask_cors import CORS
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
CORS(app)
|
||||||
request_count = 0
|
request_count = 0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
34
dashboard/index.html
Normal file
34
dashboard/index.html
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Ghaymah SRE Dashboard</title>
|
||||||
|
<link rel="stylesheet" href="style.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>Ghaymah SRE Dashboard</h1>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
|
||||||
|
<h2>Status</h2>
|
||||||
|
<p id="status">Checking...</p>
|
||||||
|
|
||||||
|
|
||||||
|
<h2>Response Time</h2>
|
||||||
|
<p id="response">-</p>
|
||||||
|
|
||||||
|
|
||||||
|
<h2>Total Requests</h2>
|
||||||
|
<p id="requests">-</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script src="script.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
67
dashboard/script.js
Normal file
67
dashboard/script.js
Normal file
@@ -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
|
||||||
|
);
|
||||||
32
dashboard/style.css
Normal file
32
dashboard/style.css
Normal file
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
49
monitoring/monitor.py
Normal file
49
monitoring/monitor.py
Normal file
@@ -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)
|
||||||
المرجع في مشكلة جديدة
حظر مستخدم