Q5
هذا الالتزام موجود في:
15
q5-mithal-monitor/Dockerfile
Normal file
15
q5-mithal-monitor/Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
FROM python:3.12-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY requirements.txt .
|
||||||
|
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN mv dashboard.html index.html
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
CMD sh -c "python3 monitor.py && python3 -m http.server 8080"
|
||||||
264
q5-mithal-monitor/dashboard.html
Normal file
264
q5-mithal-monitor/dashboard.html
Normal file
@@ -0,0 +1,264 @@
|
|||||||
|
<!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>
|
||||||
|
*{
|
||||||
|
margin:0;
|
||||||
|
padding:0;
|
||||||
|
box-sizing:border-box;
|
||||||
|
font-family:Arial,Helvetica,sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
body{
|
||||||
|
background:#f4f6f9;
|
||||||
|
padding:30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1{
|
||||||
|
text-align:center;
|
||||||
|
margin-bottom:30px;
|
||||||
|
color:#2c3e50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cards{
|
||||||
|
display:grid;
|
||||||
|
grid-template-columns:repeat(auto-fit,minmax(230px,1fr));
|
||||||
|
gap:20px;
|
||||||
|
margin-bottom:30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card{
|
||||||
|
background:white;
|
||||||
|
border-radius:10px;
|
||||||
|
padding:20px;
|
||||||
|
box-shadow:0 3px 8px rgba(0,0,0,.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card h3{
|
||||||
|
color:#555;
|
||||||
|
margin-bottom:10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.value{
|
||||||
|
font-size:30px;
|
||||||
|
font-weight:bold;
|
||||||
|
color:#007BFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
table{
|
||||||
|
width:100%;
|
||||||
|
border-collapse:collapse;
|
||||||
|
background:white;
|
||||||
|
margin-top:30px;
|
||||||
|
box-shadow:0 3px 8px rgba(0,0,0,.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
table th{
|
||||||
|
background:#007BFF;
|
||||||
|
color:white;
|
||||||
|
padding:12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table td{
|
||||||
|
padding:10px;
|
||||||
|
text-align:center;
|
||||||
|
border-bottom:1px solid #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas{
|
||||||
|
background:white;
|
||||||
|
margin-top:30px;
|
||||||
|
padding:20px;
|
||||||
|
border-radius:10px;
|
||||||
|
box-shadow:0 3px 8px rgba(0,0,0,.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
.good{
|
||||||
|
color:green;
|
||||||
|
font-weight:bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bad{
|
||||||
|
color:red;
|
||||||
|
font-weight:bold;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>🚀 Mithal Monitoring Dashboard</h1>
|
||||||
|
|
||||||
|
<div class="cards">
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h3>Uptime (24h)</h3>
|
||||||
|
<div id="uptime" class="value">-- %</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h3>Latency</h3>
|
||||||
|
<div id="latency" class="value">-- ms</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h3>DNS Lookup</h3>
|
||||||
|
<div id="dns" class="value">-- ms</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h3>Search Response</h3>
|
||||||
|
<div id="search" class="value">-- ms</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h3>SSL Expiry</h3>
|
||||||
|
<div id="ssl" class="value" style="font-size:22px;">--</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h3>Days Remaining</h3>
|
||||||
|
<div id="days" class="value">--</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<canvas id="latencyChart" height="100"></canvas>
|
||||||
|
|
||||||
|
<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="history">
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
async function loadData(){
|
||||||
|
|
||||||
|
const response=await fetch("metrics.json");
|
||||||
|
|
||||||
|
const data=await response.json();
|
||||||
|
|
||||||
|
document.getElementById("uptime").innerHTML=data.uptime+" %";
|
||||||
|
|
||||||
|
document.getElementById("latency").innerHTML=data.last_check.latency+" ms";
|
||||||
|
|
||||||
|
document.getElementById("dns").innerHTML=data.last_check.dns+" ms";
|
||||||
|
|
||||||
|
document.getElementById("search").innerHTML=data.last_check.search_latency+" ms";
|
||||||
|
|
||||||
|
document.getElementById("ssl").innerHTML=data.last_check.ssl_expiry;
|
||||||
|
|
||||||
|
document.getElementById("days").innerHTML=data.last_check.ssl_days_left+" days";
|
||||||
|
|
||||||
|
let tbody=document.getElementById("history");
|
||||||
|
|
||||||
|
tbody.innerHTML="";
|
||||||
|
|
||||||
|
data.history.reverse().forEach(item=>{
|
||||||
|
|
||||||
|
tbody.innerHTML+=`
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
|
||||||
|
<td>${item.time}</td>
|
||||||
|
|
||||||
|
<td class="${item.status==200?'good':'bad'}">
|
||||||
|
|
||||||
|
${item.status}
|
||||||
|
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>${item.latency} ms</td>
|
||||||
|
|
||||||
|
<td>${item.dns} ms</td>
|
||||||
|
|
||||||
|
<td>${item.search_latency} ms</td>
|
||||||
|
|
||||||
|
<td>${item.ssl_days_left}</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
`;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
const labels=[];
|
||||||
|
|
||||||
|
for(let i=1;i<=data.latency_chart.length;i++){
|
||||||
|
|
||||||
|
labels.push(i);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
new Chart(document.getElementById("latencyChart"),{
|
||||||
|
|
||||||
|
type:"line",
|
||||||
|
|
||||||
|
data:{
|
||||||
|
|
||||||
|
labels:labels,
|
||||||
|
|
||||||
|
datasets:[{
|
||||||
|
|
||||||
|
label:"Latency (ms)",
|
||||||
|
|
||||||
|
data:data.latency_chart,
|
||||||
|
|
||||||
|
fill:false,
|
||||||
|
|
||||||
|
borderWidth:2
|
||||||
|
|
||||||
|
}]
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
options:{
|
||||||
|
|
||||||
|
responsive:true,
|
||||||
|
|
||||||
|
plugins:{
|
||||||
|
|
||||||
|
legend:{
|
||||||
|
|
||||||
|
display:true
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
loadData();
|
||||||
|
|
||||||
|
setInterval(loadData,60000);
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
117
q5-mithal-monitor/metrics.json
Normal file
117
q5-mithal-monitor/metrics.json
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
{
|
||||||
|
"uptime": 100.0,
|
||||||
|
"last_check": {
|
||||||
|
"time": "2026-07-27 03:13:02",
|
||||||
|
"status": 200,
|
||||||
|
"latency": 78.62,
|
||||||
|
"dns": 0.5,
|
||||||
|
"search_latency": 80.38,
|
||||||
|
"ssl_expiry": "2026-09-15",
|
||||||
|
"ssl_days_left": 50
|
||||||
|
},
|
||||||
|
"history": [
|
||||||
|
{
|
||||||
|
"time": "2026-07-27 03:04:01",
|
||||||
|
"status": 200,
|
||||||
|
"latency": 82.82,
|
||||||
|
"dns": 0.33,
|
||||||
|
"search_latency": 78.14,
|
||||||
|
"ssl_expiry": "2026-09-15",
|
||||||
|
"ssl_days_left": 50
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"time": "2026-07-27 03:05:02",
|
||||||
|
"status": 200,
|
||||||
|
"latency": 89.55,
|
||||||
|
"dns": 0.31,
|
||||||
|
"search_latency": 76.35,
|
||||||
|
"ssl_expiry": "2026-09-15",
|
||||||
|
"ssl_days_left": 50
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"time": "2026-07-27 03:06:01",
|
||||||
|
"status": 200,
|
||||||
|
"latency": 88.39,
|
||||||
|
"dns": 0.67,
|
||||||
|
"search_latency": 81.37,
|
||||||
|
"ssl_expiry": "2026-09-15",
|
||||||
|
"ssl_days_left": 50
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"time": "2026-07-27 03:07:01",
|
||||||
|
"status": 200,
|
||||||
|
"latency": 77.25,
|
||||||
|
"dns": 3.21,
|
||||||
|
"search_latency": 80.14,
|
||||||
|
"ssl_expiry": "2026-09-15",
|
||||||
|
"ssl_days_left": 50
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"time": "2026-07-27 03:08:01",
|
||||||
|
"status": 200,
|
||||||
|
"latency": 86.22,
|
||||||
|
"dns": 0.29,
|
||||||
|
"search_latency": 76.51,
|
||||||
|
"ssl_expiry": "2026-09-15",
|
||||||
|
"ssl_days_left": 50
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"time": "2026-07-27 03:09:01",
|
||||||
|
"status": 200,
|
||||||
|
"latency": 81.52,
|
||||||
|
"dns": 0.55,
|
||||||
|
"search_latency": 74.89,
|
||||||
|
"ssl_expiry": "2026-09-15",
|
||||||
|
"ssl_days_left": 50
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"time": "2026-07-27 03:10:01",
|
||||||
|
"status": 200,
|
||||||
|
"latency": 80.42,
|
||||||
|
"dns": 0.26,
|
||||||
|
"search_latency": 79.42,
|
||||||
|
"ssl_expiry": "2026-09-15",
|
||||||
|
"ssl_days_left": 50
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"time": "2026-07-27 03:11:02",
|
||||||
|
"status": 200,
|
||||||
|
"latency": 82.46,
|
||||||
|
"dns": 0.5,
|
||||||
|
"search_latency": 75.56,
|
||||||
|
"ssl_expiry": "2026-09-15",
|
||||||
|
"ssl_days_left": 50
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"time": "2026-07-27 03:12:01",
|
||||||
|
"status": 200,
|
||||||
|
"latency": 80.94,
|
||||||
|
"dns": 0.26,
|
||||||
|
"search_latency": 85.53,
|
||||||
|
"ssl_expiry": "2026-09-15",
|
||||||
|
"ssl_days_left": 50
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"time": "2026-07-27 03:13:02",
|
||||||
|
"status": 200,
|
||||||
|
"latency": 78.62,
|
||||||
|
"dns": 0.5,
|
||||||
|
"search_latency": 80.38,
|
||||||
|
"ssl_expiry": "2026-09-15",
|
||||||
|
"ssl_days_left": 50
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"latency_chart": [
|
||||||
|
78.97,
|
||||||
|
82.82,
|
||||||
|
89.55,
|
||||||
|
88.39,
|
||||||
|
77.25,
|
||||||
|
86.22,
|
||||||
|
81.52,
|
||||||
|
80.42,
|
||||||
|
82.46,
|
||||||
|
80.94,
|
||||||
|
78.62
|
||||||
|
]
|
||||||
|
}
|
||||||
149
q5-mithal-monitor/monitor.py
Normal file
149
q5-mithal-monitor/monitor.py
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
import requests
|
||||||
|
import socket
|
||||||
|
import ssl
|
||||||
|
import time
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
URL = "https://mithal.space"
|
||||||
|
OUTPUT_FILE = "metrics.json"
|
||||||
|
|
||||||
|
|
||||||
|
def http_check():
|
||||||
|
start = time.time()
|
||||||
|
|
||||||
|
try:
|
||||||
|
r = requests.get(URL, timeout=10)
|
||||||
|
latency = round((time.time() - start) * 1000, 2)
|
||||||
|
return r.status_code, latency
|
||||||
|
except:
|
||||||
|
latency = round((time.time() - start) * 1000, 2)
|
||||||
|
return 0, latency
|
||||||
|
|
||||||
|
|
||||||
|
def dns_lookup():
|
||||||
|
host = urlparse(URL).hostname
|
||||||
|
|
||||||
|
start = time.time()
|
||||||
|
|
||||||
|
try:
|
||||||
|
socket.gethostbyname(host)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return round((time.time() - start) * 1000, 2)
|
||||||
|
|
||||||
|
|
||||||
|
def ssl_info():
|
||||||
|
|
||||||
|
host = urlparse(URL).hostname
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
ctx = ssl.create_default_context()
|
||||||
|
|
||||||
|
with socket.create_connection((host,443),timeout=10) as sock:
|
||||||
|
|
||||||
|
with ctx.wrap_socket(sock,server_hostname=host) as ssock:
|
||||||
|
|
||||||
|
cert = ssock.getpeercert()
|
||||||
|
|
||||||
|
expiry = datetime.strptime(
|
||||||
|
cert["notAfter"],
|
||||||
|
"%b %d %H:%M:%S %Y %Z"
|
||||||
|
)
|
||||||
|
|
||||||
|
days = (expiry-datetime.utcnow()).days
|
||||||
|
|
||||||
|
return expiry.strftime("%Y-%m-%d"),days
|
||||||
|
|
||||||
|
except:
|
||||||
|
|
||||||
|
return "Unavailable",-1
|
||||||
|
|
||||||
|
|
||||||
|
def search_response():
|
||||||
|
|
||||||
|
start=time.time()
|
||||||
|
|
||||||
|
try:
|
||||||
|
requests.get(URL,timeout=10)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return round((time.time()-start)*1000,2)
|
||||||
|
|
||||||
|
|
||||||
|
if os.path.exists(OUTPUT_FILE):
|
||||||
|
|
||||||
|
with open(OUTPUT_FILE,"r") as f:
|
||||||
|
|
||||||
|
data=json.load(f)
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
data={
|
||||||
|
|
||||||
|
"history":[]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
status,latency=http_check()
|
||||||
|
|
||||||
|
record={
|
||||||
|
|
||||||
|
"time":datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
|
|
||||||
|
"status":status,
|
||||||
|
|
||||||
|
"latency":latency,
|
||||||
|
|
||||||
|
"dns":dns_lookup(),
|
||||||
|
|
||||||
|
"search_latency":search_response()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ssl_date,ssl_days=ssl_info()
|
||||||
|
|
||||||
|
record["ssl_expiry"]=ssl_date
|
||||||
|
record["ssl_days_left"]=ssl_days
|
||||||
|
|
||||||
|
data["history"].append(record)
|
||||||
|
|
||||||
|
if len(data["history"])>1440:
|
||||||
|
|
||||||
|
data["history"]=data["history"][-1440:]
|
||||||
|
|
||||||
|
success=len([x for x in data["history"] if x["status"]==200])
|
||||||
|
|
||||||
|
uptime=round(success/len(data["history"])*100,2)
|
||||||
|
|
||||||
|
output={
|
||||||
|
|
||||||
|
"uptime":uptime,
|
||||||
|
|
||||||
|
"last_check":record,
|
||||||
|
|
||||||
|
"history":data["history"][-10:],
|
||||||
|
|
||||||
|
"latency_chart":[x["latency"] for x in data["history"][-60:]]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
with open(OUTPUT_FILE,"w") as f:
|
||||||
|
|
||||||
|
json.dump(output,f,indent=4)
|
||||||
|
|
||||||
|
print("="*40)
|
||||||
|
print("Mithal Monitoring")
|
||||||
|
print("="*40)
|
||||||
|
print("Status :",status)
|
||||||
|
print("Latency :",latency,"ms")
|
||||||
|
print("DNS :",record["dns"],"ms")
|
||||||
|
print("Search :",record["search_latency"],"ms")
|
||||||
|
print("SSL Expiry :",ssl_date)
|
||||||
|
print("Days Left :",ssl_days)
|
||||||
|
print("Uptime :",uptime,"%")
|
||||||
1
q5-mithal-monitor/requirements.txt
Normal file
1
q5-mithal-monitor/requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
requests
|
||||||
المرجع في مشكلة جديدة
حظر مستخدم