Complete Ghaymah Internship Assessment

هذا الالتزام موجود في:
2026-07-27 19:30:45 +02:00
التزام 58dda08466
13 ملفات معدلة مع 899 إضافات و0 حذوفات

عرض الملف

@@ -0,0 +1,174 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mithal Monitoring Dashboard</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
body{
font-family:Arial;
background:#f5f5f5;
padding:30px;
}
.card{
background:white;
padding:20px;
margin:20px;
border-radius:10px;
box-shadow:0 0 10px #ccc;
}
table{
width:100%;
border-collapse:collapse;
}
th,td{
padding:10px;
border:1px solid #ddd;
text-align:center;
}
</style>
</head>
<body>
<h1>Mithal.space Monitoring Dashboard</h1>
<div class="card">
<h2>Uptime (24h)</h2>
<div id="uptime"></div>
</div>
<div class="card">
<h2>SSL Status</h2>
<div id="ssl"></div>
</div>
<div class="card">
<h2>Latency (Last Hour)</h2>
<canvas id="chart"></canvas>
</div>
<div class="card">
<h2>Last 10 Checks</h2>
<table>
<thead>
<tr>
<th>Time</th>
<th>Status</th>
<th>Latency</th>
<th>DNS</th>
<th>Search</th>
</tr>
</thead>
<tbody id="table"></tbody>
</table>
</div>
<script>
fetch("monitor_data.json")
.then(r=>r.json())
.then(data=>{
let success=data.filter(x=>x.uptime).length;
let uptime=((success/data.length)*100).toFixed(2);
document.getElementById("uptime").innerHTML=uptime+" %";
let last=data[data.length-1];
document.getElementById("ssl").innerHTML=
last.ssl_remaining_days+" days remaining";
let hour=data.slice(-60);
new Chart(document.getElementById("chart"),{
type:"line",
data:{
labels:hour.map(x=>x.time),
datasets:[{
label:"Latency",
data:hour.map(x=>x.latency)
}]
}
});
let html="";
data.slice(-10).reverse().forEach(x=>{
html+=`
<tr>
<td>${x.time}</td>
<td>${x.status}</td>
<td>${x.latency} ms</td>
<td>${x.dns} ms</td>
<td>${x.search_response} ms</td>
</tr>
`;
});
document.getElementById("table").innerHTML=html;
});
</script>
</body>
</html>

103
mithal-monitor/monitor.py Normal file
عرض الملف

@@ -0,0 +1,103 @@
import requests
import socket
import ssl
import time
import json
import os
from datetime import datetime
URL = "https://mithal.space"
SEARCH_URL = "https://mithal.space/search?q=test"
DATA_FILE = "monitor_data.json"
def get_latency():
start = time.time()
r = requests.get(URL, timeout=10)
latency = (time.time() - start) * 1000
return round(latency, 2), r.status_code
def get_dns_time():
start = time.time()
socket.gethostbyname("mithal.space")
dns = (time.time() - start) * 1000
return round(dns, 2)
def get_ssl():
hostname = "mithal.space"
ctx = ssl.create_default_context()
with ctx.wrap_socket(socket.socket(), server_hostname=hostname) as s:
s.settimeout(5)
s.connect((hostname, 443))
cert = s.getpeercert()
expiry = cert["notAfter"]
expire_date = datetime.strptime(expiry, "%b %d %H:%M:%S %Y %Z")
remaining = (expire_date - datetime.utcnow()).days
return expiry, remaining
def get_search_time():
start = time.time()
try:
requests.get(SEARCH_URL, timeout=10)
except:
pass
return round((time.time() - start) * 1000, 2)
def save():
latency, status = get_latency()
dns = get_dns_time()
ssl_expiry, ssl_days = get_ssl()
search = get_search_time()
data = {
"time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"latency": latency,
"status": status,
"uptime": status == 200,
"dns": dns,
"ssl_expiry": ssl_expiry,
"ssl_remaining_days": ssl_days,
"search_response": search
}
if os.path.exists(DATA_FILE):
with open(DATA_FILE, "r") as f:
history = json.load(f)
else:
history = []
history.append(data)
history = history[-1440:]
with open(DATA_FILE, "w") as f:
json.dump(history, f, indent=4)
if __name__ == "__main__":
while True:
save()
print("Saved:", datetime.now())
time.sleep(60)