Add all assessment files
هذا الالتزام موجود في:
292
q5-mithal-monitor/dashboard.html
Normal file
292
q5-mithal-monitor/dashboard.html
Normal file
@@ -0,0 +1,292 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Mithal Monitoring Dashboard</title>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
|
||||
<style>
|
||||
|
||||
body{
|
||||
font-family:Arial,sans-serif;
|
||||
background:#f4f6f8;
|
||||
margin:30px;
|
||||
}
|
||||
|
||||
h1{
|
||||
text-align:center;
|
||||
color:#333;
|
||||
}
|
||||
|
||||
.cards{
|
||||
display:flex;
|
||||
gap:20px;
|
||||
margin-bottom:25px;
|
||||
}
|
||||
|
||||
.card{
|
||||
flex:1;
|
||||
background:white;
|
||||
padding:20px;
|
||||
border-radius:10px;
|
||||
box-shadow:0 2px 6px rgba(0,0,0,.15);
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
.card h2{
|
||||
margin:0;
|
||||
color:#666;
|
||||
}
|
||||
|
||||
.card p{
|
||||
font-size:28px;
|
||||
margin-top:15px;
|
||||
color:#1976d2;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
.chart-container{
|
||||
background:white;
|
||||
padding:20px;
|
||||
border-radius:10px;
|
||||
box-shadow:0 2px 6px rgba(0,0,0,.15);
|
||||
}
|
||||
|
||||
table{
|
||||
|
||||
width:100%;
|
||||
margin-top:30px;
|
||||
border-collapse:collapse;
|
||||
background:white;
|
||||
box-shadow:0 2px 6px rgba(0,0,0,.15);
|
||||
|
||||
}
|
||||
|
||||
th{
|
||||
|
||||
background:#1976d2;
|
||||
color:white;
|
||||
padding:10px;
|
||||
|
||||
}
|
||||
|
||||
td{
|
||||
|
||||
text-align:center;
|
||||
padding:10px;
|
||||
border-bottom:1px solid #ddd;
|
||||
|
||||
}
|
||||
|
||||
.up{
|
||||
|
||||
color:green;
|
||||
font-weight:bold;
|
||||
|
||||
}
|
||||
|
||||
.down{
|
||||
|
||||
color:red;
|
||||
font-weight:bold;
|
||||
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>Mithal Monitoring Dashboard</h1>
|
||||
|
||||
<div class="cards">
|
||||
|
||||
<div class="card">
|
||||
|
||||
<h2>Uptime (24h)</h2>
|
||||
|
||||
<p id="uptime">--</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
|
||||
<h2>SSL Remaining</h2>
|
||||
|
||||
<p id="ssl">--</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
|
||||
<h2>Latest Latency</h2>
|
||||
|
||||
<p id="latency">--</p>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="chart-container">
|
||||
|
||||
<canvas id="chart"></canvas>
|
||||
|
||||
</div>
|
||||
|
||||
<h2>Last 10 Checks</h2>
|
||||
|
||||
<table>
|
||||
|
||||
<thead>
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Time</th>
|
||||
|
||||
<th>Status</th>
|
||||
|
||||
<th>Latency</th>
|
||||
|
||||
<th>DNS</th>
|
||||
|
||||
<th>Search</th>
|
||||
|
||||
<th>SSL Days</th>
|
||||
|
||||
</tr>
|
||||
|
||||
</thead>
|
||||
|
||||
<tbody id="tableBody">
|
||||
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
<script>
|
||||
|
||||
let chart=null;
|
||||
|
||||
async function refresh(){
|
||||
|
||||
const response=await fetch("/api/data");
|
||||
|
||||
const data=await response.json();
|
||||
|
||||
if(data.length===0)
|
||||
return;
|
||||
|
||||
const last=data[data.length-1];
|
||||
|
||||
document.getElementById("latency").innerHTML=
|
||||
last.latency_ms+" ms";
|
||||
|
||||
document.getElementById("ssl").innerHTML=
|
||||
last.ssl_remaining_days+" days";
|
||||
|
||||
const success=data.filter(x=>x.uptime).length;
|
||||
|
||||
const uptime=((success/data.length)*100).toFixed(2);
|
||||
|
||||
document.getElementById("uptime").innerHTML=
|
||||
uptime+"%";
|
||||
|
||||
const hour=data.slice(-60);
|
||||
|
||||
const labels=hour.map(x=>x.timestamp.substring(11));
|
||||
|
||||
const values=hour.map(x=>x.latency_ms);
|
||||
|
||||
if(chart)
|
||||
chart.destroy();
|
||||
|
||||
chart=new Chart(
|
||||
|
||||
document.getElementById("chart"),
|
||||
|
||||
{
|
||||
|
||||
type:"line",
|
||||
|
||||
data:{
|
||||
|
||||
labels:labels,
|
||||
|
||||
datasets:[{
|
||||
|
||||
label:"Latency (ms)",
|
||||
|
||||
data:values,
|
||||
|
||||
borderWidth:2,
|
||||
|
||||
fill:false
|
||||
|
||||
}]
|
||||
|
||||
},
|
||||
|
||||
options:{
|
||||
|
||||
responsive:true,
|
||||
|
||||
plugins:{
|
||||
|
||||
legend:{
|
||||
display:true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
const tbody=document.getElementById("tableBody");
|
||||
|
||||
tbody.innerHTML="";
|
||||
|
||||
data.slice(-10).reverse().forEach(item=>{
|
||||
|
||||
tbody.innerHTML+=`
|
||||
|
||||
<tr>
|
||||
|
||||
<td>${item.timestamp}</td>
|
||||
|
||||
<td class="${item.uptime?'up':'down'}">
|
||||
|
||||
${item.uptime?'UP':'DOWN'}
|
||||
|
||||
</td>
|
||||
|
||||
<td>${item.latency_ms} ms</td>
|
||||
|
||||
<td>${item.dns_ms} ms</td>
|
||||
|
||||
<td>${item.search_latency_ms} ms</td>
|
||||
|
||||
<td>${item.ssl_remaining_days}</td>
|
||||
|
||||
</tr>
|
||||
|
||||
`;
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
refresh();
|
||||
|
||||
setInterval(refresh,60000);
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
177
q5-mithal-monitor/monitor.py
Normal file
177
q5-mithal-monitor/monitor.py
Normal file
@@ -0,0 +1,177 @@
|
||||
import requests
|
||||
import socket
|
||||
import ssl
|
||||
import json
|
||||
import time
|
||||
import threading
|
||||
from datetime import datetime
|
||||
from flask import Flask, jsonify, send_from_directory
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
BASE_URL = "https://mithal.space"
|
||||
SEARCH_URL = "https://mithal.space/search?q=test"
|
||||
|
||||
DATA_FILE = "monitor_data.json"
|
||||
|
||||
CHECK_INTERVAL = 60
|
||||
|
||||
|
||||
def load_data():
|
||||
try:
|
||||
with open(DATA_FILE, "r") as f:
|
||||
return json.load(f)
|
||||
except:
|
||||
return []
|
||||
|
||||
|
||||
def save_data(data):
|
||||
with open(DATA_FILE, "w") as f:
|
||||
json.dump(data, f, indent=4)
|
||||
|
||||
|
||||
def get_latency():
|
||||
start = time.time()
|
||||
|
||||
response = requests.get(BASE_URL, timeout=10)
|
||||
|
||||
latency = round((time.time() - start) * 1000, 2)
|
||||
|
||||
return latency, response.status_code
|
||||
|
||||
|
||||
def get_dns_time():
|
||||
|
||||
start = time.time()
|
||||
|
||||
socket.gethostbyname("mithal.space")
|
||||
|
||||
return round((time.time() - start) * 1000, 2)
|
||||
|
||||
|
||||
def get_ssl_info():
|
||||
|
||||
hostname = "mithal.space"
|
||||
|
||||
context = ssl.create_default_context()
|
||||
|
||||
with context.wrap_socket(
|
||||
socket.socket(),
|
||||
server_hostname=hostname
|
||||
) as s:
|
||||
|
||||
s.settimeout(10)
|
||||
|
||||
s.connect((hostname, 443))
|
||||
|
||||
cert = s.getpeercert()
|
||||
|
||||
expiry = datetime.strptime(
|
||||
cert["notAfter"],
|
||||
"%b %d %H:%M:%S %Y %Z"
|
||||
)
|
||||
|
||||
remaining = (expiry - datetime.utcnow()).days
|
||||
|
||||
return expiry.strftime("%Y-%m-%d"), remaining
|
||||
|
||||
|
||||
def get_search_latency():
|
||||
|
||||
start = time.time()
|
||||
|
||||
response = requests.get(
|
||||
SEARCH_URL,
|
||||
timeout=10
|
||||
)
|
||||
|
||||
latency = round((time.time() - start) * 1000, 2)
|
||||
|
||||
return latency, response.status_code
|
||||
|
||||
def monitor():
|
||||
|
||||
while True:
|
||||
|
||||
try:
|
||||
|
||||
latency, status = get_latency()
|
||||
|
||||
dns = get_dns_time()
|
||||
|
||||
ssl_expiry, ssl_days = get_ssl_info()
|
||||
|
||||
search_latency, search_status = get_search_latency()
|
||||
|
||||
entry = {
|
||||
|
||||
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||
|
||||
"uptime": status == 200,
|
||||
|
||||
"status_code": status,
|
||||
|
||||
"latency_ms": latency,
|
||||
|
||||
"dns_ms": dns,
|
||||
|
||||
"ssl_expiry": ssl_expiry,
|
||||
|
||||
"ssl_remaining_days": ssl_days,
|
||||
|
||||
"search_latency_ms": search_latency,
|
||||
|
||||
"search_status": search_status
|
||||
|
||||
}
|
||||
|
||||
data = load_data()
|
||||
|
||||
data.append(entry)
|
||||
|
||||
data = data[-1440:]
|
||||
|
||||
save_data(data)
|
||||
|
||||
print(entry)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print("Monitoring Error:", e)
|
||||
|
||||
time.sleep(CHECK_INTERVAL)
|
||||
|
||||
|
||||
@app.route("/api/data")
|
||||
def api_data():
|
||||
|
||||
return jsonify(load_data())
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
|
||||
return {
|
||||
"message": "Mithal Monitoring API",
|
||||
"dashboard": "/dashboard"
|
||||
}
|
||||
|
||||
|
||||
@app.route("/dashboard")
|
||||
def dashboard():
|
||||
|
||||
return send_from_directory(".", "dashboard.html")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
thread = threading.Thread(target=monitor)
|
||||
|
||||
thread.daemon = True
|
||||
|
||||
thread.start()
|
||||
|
||||
app.run(
|
||||
host="0.0.0.0",
|
||||
port=5002
|
||||
)
|
||||
13
q5-mithal-monitor/monitor_data.json
Normal file
13
q5-mithal-monitor/monitor_data.json
Normal file
@@ -0,0 +1,13 @@
|
||||
[
|
||||
{
|
||||
"timestamp": "2026-07-28 15:09:54",
|
||||
"uptime": true,
|
||||
"status_code": 200,
|
||||
"latency_ms": 1388.97,
|
||||
"dns_ms": 65.85,
|
||||
"ssl_expiry": "2026-09-15",
|
||||
"ssl_remaining_days": 49,
|
||||
"search_latency_ms": 1204.14,
|
||||
"search_status": 200
|
||||
}
|
||||
]
|
||||
المرجع في مشكلة جديدة
حظر مستخدم