feat: initialize repository with SRE infrastructure, monitoring dashboard, and deployment documentation
هذا الالتزام موجود في:
337
q5-mithal-monitor/dashbourd.html
Normal file
337
q5-mithal-monitor/dashbourd.html
Normal file
@@ -0,0 +1,337 @@
|
||||
<!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: #f4f6f8;
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.cards {
|
||||
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
gap: 20px;
|
||||
margin-bottom: 30px;
|
||||
|
||||
}
|
||||
|
||||
.card {
|
||||
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 3px 12px rgba(0, 0, 0, .1);
|
||||
|
||||
}
|
||||
|
||||
.card h3 {
|
||||
|
||||
margin-bottom: 10px;
|
||||
color: #666;
|
||||
|
||||
}
|
||||
|
||||
.value {
|
||||
|
||||
font-size: 32px;
|
||||
font-weight: bold;
|
||||
|
||||
}
|
||||
|
||||
.chart {
|
||||
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 3px 12px rgba(0, 0, 0, .1);
|
||||
margin-bottom: 30px;
|
||||
|
||||
}
|
||||
|
||||
table {
|
||||
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
background: white;
|
||||
|
||||
}
|
||||
|
||||
th {
|
||||
|
||||
background: #202124;
|
||||
color: white;
|
||||
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
|
||||
padding: 12px;
|
||||
text-align: center;
|
||||
border-bottom: 1px solid #ddd;
|
||||
|
||||
}
|
||||
|
||||
.ok {
|
||||
|
||||
color: green;
|
||||
font-weight: bold;
|
||||
|
||||
}
|
||||
|
||||
.fail {
|
||||
|
||||
color: red;
|
||||
font-weight: bold;
|
||||
|
||||
}
|
||||
|
||||
footer {
|
||||
|
||||
margin-top: 30px;
|
||||
text-align: center;
|
||||
color: #777;
|
||||
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>📈 Mithal Monitoring Dashboard</h1>
|
||||
|
||||
<div class="cards">
|
||||
|
||||
<div class="card">
|
||||
|
||||
<h3>Uptime (24h)</h3>
|
||||
|
||||
<div class="value" id="uptime">--</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
|
||||
<h3>Average Latency</h3>
|
||||
|
||||
<div class="value" id="latency">--</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
|
||||
<h3>SSL Days Left</h3>
|
||||
|
||||
<div class="value" id="ssl">--</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
|
||||
<h3>Total Checks</h3>
|
||||
|
||||
<div class="value" id="checks">--</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="chart">
|
||||
|
||||
<canvas id="latencyChart"></canvas>
|
||||
|
||||
</div>
|
||||
|
||||
<h2 style="margin-bottom:15px;">Last 10 Checks</h2>
|
||||
|
||||
<table>
|
||||
|
||||
<thead>
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Time</th>
|
||||
<th>Status</th>
|
||||
<th>Latency</th>
|
||||
<th>DNS</th>
|
||||
<th>SSL</th>
|
||||
<th>Search</th>
|
||||
|
||||
</tr>
|
||||
|
||||
</thead>
|
||||
|
||||
<tbody id="tableBody">
|
||||
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
<footer>
|
||||
|
||||
Refreshes every 60 seconds
|
||||
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
|
||||
let chart;
|
||||
|
||||
async function loadMetrics() {
|
||||
|
||||
const response = await fetch("metrics.json");
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
async function render() {
|
||||
|
||||
const data = await loadMetrics();
|
||||
|
||||
if (data.length === 0)
|
||||
return;
|
||||
|
||||
const checks = data.length;
|
||||
|
||||
const uptime = data.filter(x => x.uptime).length;
|
||||
|
||||
const uptimePercent = ((uptime / checks) * 100).toFixed(2);
|
||||
|
||||
document.getElementById("uptime").innerHTML = uptimePercent + "%";
|
||||
|
||||
document.getElementById("checks").innerHTML = checks;
|
||||
|
||||
const avgLatency = (
|
||||
|
||||
data.reduce((a, b) => a + b.latency_ms, 0) / checks
|
||||
|
||||
).toFixed(2);
|
||||
|
||||
document.getElementById("latency").innerHTML = avgLatency + " ms";
|
||||
|
||||
document.getElementById("ssl").innerHTML =
|
||||
|
||||
data[data.length - 1].ssl.days_left + " days";
|
||||
|
||||
|
||||
|
||||
const lastHour = data.slice(-60);
|
||||
|
||||
const labels = lastHour.map(x => {
|
||||
|
||||
const d = new Date(x.timestamp);
|
||||
|
||||
return d.toLocaleTimeString();
|
||||
|
||||
});
|
||||
|
||||
const latency = lastHour.map(x => x.latency_ms);
|
||||
|
||||
if (chart)
|
||||
chart.destroy();
|
||||
|
||||
chart = new Chart(
|
||||
|
||||
document.getElementById("latencyChart"),
|
||||
|
||||
{
|
||||
|
||||
type: "line",
|
||||
|
||||
data: {
|
||||
|
||||
labels: labels,
|
||||
|
||||
datasets: [{
|
||||
|
||||
label: "Latency (ms)",
|
||||
|
||||
data: latency,
|
||||
|
||||
fill: false,
|
||||
|
||||
tension: .2
|
||||
|
||||
}]
|
||||
|
||||
},
|
||||
|
||||
options: {
|
||||
|
||||
responsive: true
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
|
||||
|
||||
const tbody = document.getElementById("tableBody");
|
||||
|
||||
tbody.innerHTML = "";
|
||||
|
||||
data.slice(-10).reverse().forEach(item => {
|
||||
|
||||
tbody.innerHTML += `
|
||||
|
||||
<tr>
|
||||
|
||||
<td>${new Date(item.timestamp).toLocaleString()}</td>
|
||||
|
||||
<td class="${item.uptime ? 'ok' : 'fail'}">
|
||||
|
||||
${item.status_code}
|
||||
|
||||
</td>
|
||||
|
||||
<td>${item.latency_ms} ms</td>
|
||||
|
||||
<td>${item.dns_lookup_ms} ms</td>
|
||||
|
||||
<td>${item.ssl.days_left} days</td>
|
||||
|
||||
<td>${item.search.response_ms} ms</td>
|
||||
|
||||
</tr>
|
||||
|
||||
`;
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
render();
|
||||
|
||||
setInterval(render, 60000);
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
107
q5-mithal-monitor/metrics.json
Normal file
107
q5-mithal-monitor/metrics.json
Normal file
@@ -0,0 +1,107 @@
|
||||
[
|
||||
{
|
||||
"timestamp": "2026-07-28T09:59:01.075371",
|
||||
"latency_ms": 1021.86,
|
||||
"status_code": 200,
|
||||
"uptime": true,
|
||||
"dns_lookup_ms": 6.92,
|
||||
"ssl": {
|
||||
"expires_at": "2026-09-15T13:10:47",
|
||||
"days_left": 49
|
||||
},
|
||||
"search": {
|
||||
"status": 200,
|
||||
"response_ms": 958.41
|
||||
}
|
||||
},
|
||||
{
|
||||
"timestamp": "2026-07-28T10:00:03.486672",
|
||||
"latency_ms": 1078.94,
|
||||
"status_code": 200,
|
||||
"uptime": true,
|
||||
"dns_lookup_ms": 7.81,
|
||||
"ssl": {
|
||||
"expires_at": "2026-09-15T13:10:47",
|
||||
"days_left": 49
|
||||
},
|
||||
"search": {
|
||||
"status": 200,
|
||||
"response_ms": 875.35
|
||||
}
|
||||
},
|
||||
{
|
||||
"timestamp": "2026-07-28T10:01:05.991518",
|
||||
"latency_ms": 1063.59,
|
||||
"status_code": 200,
|
||||
"uptime": true,
|
||||
"dns_lookup_ms": 6.1,
|
||||
"ssl": {
|
||||
"expires_at": "2026-09-15T13:10:47",
|
||||
"days_left": 49
|
||||
},
|
||||
"search": {
|
||||
"status": 200,
|
||||
"response_ms": 872.83
|
||||
}
|
||||
},
|
||||
{
|
||||
"timestamp": "2026-07-28T10:02:08.495565",
|
||||
"latency_ms": 1022.08,
|
||||
"status_code": 200,
|
||||
"uptime": true,
|
||||
"dns_lookup_ms": 5.8,
|
||||
"ssl": {
|
||||
"expires_at": "2026-09-15T13:10:47",
|
||||
"days_left": 49
|
||||
},
|
||||
"search": {
|
||||
"status": 200,
|
||||
"response_ms": 919.46
|
||||
}
|
||||
},
|
||||
{
|
||||
"timestamp": "2026-07-28T10:03:10.815308",
|
||||
"latency_ms": 944.67,
|
||||
"status_code": 200,
|
||||
"uptime": true,
|
||||
"dns_lookup_ms": 7.7,
|
||||
"ssl": {
|
||||
"expires_at": "2026-09-15T13:10:47",
|
||||
"days_left": 49
|
||||
},
|
||||
"search": {
|
||||
"status": 200,
|
||||
"response_ms": 883.18
|
||||
}
|
||||
},
|
||||
{
|
||||
"timestamp": "2026-07-28T10:04:12.942249",
|
||||
"latency_ms": 809.59,
|
||||
"status_code": 200,
|
||||
"uptime": true,
|
||||
"dns_lookup_ms": 5.28,
|
||||
"ssl": {
|
||||
"expires_at": "2026-09-15T13:10:47",
|
||||
"days_left": 49
|
||||
},
|
||||
"search": {
|
||||
"status": 200,
|
||||
"response_ms": 849.83
|
||||
}
|
||||
},
|
||||
{
|
||||
"timestamp": "2026-07-28T10:05:15.376909",
|
||||
"latency_ms": 909.74,
|
||||
"status_code": 200,
|
||||
"uptime": true,
|
||||
"dns_lookup_ms": 4.95,
|
||||
"ssl": {
|
||||
"expires_at": "2026-09-15T13:10:47",
|
||||
"days_left": 49
|
||||
},
|
||||
"search": {
|
||||
"status": 200,
|
||||
"response_ms": 803.56
|
||||
}
|
||||
}
|
||||
]
|
||||
204
q5-mithal-monitor/monitor.py
Normal file
204
q5-mithal-monitor/monitor.py
Normal file
@@ -0,0 +1,204 @@
|
||||
import requests
|
||||
import socket
|
||||
import ssl
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
# -----------------------------
|
||||
# Configuration
|
||||
# -----------------------------
|
||||
BASE_URL = "https://mithal.space"
|
||||
SEARCH_URL = "https://mithal.space/search?q=test"
|
||||
|
||||
OUTPUT_FILE = "metrics.json"
|
||||
INTERVAL = 60 # seconds
|
||||
|
||||
MAX_RECORDS = 1440 # 24 hours (1 record/min)
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# HTTP Latency + Uptime
|
||||
# -----------------------------
|
||||
def check_http():
|
||||
start = time.perf_counter()
|
||||
|
||||
try:
|
||||
response = requests.get(BASE_URL, timeout=10)
|
||||
|
||||
latency = round((time.perf_counter() - start) * 1000, 2)
|
||||
|
||||
return {
|
||||
"status_code": response.status_code,
|
||||
"uptime": response.status_code == 200,
|
||||
"latency_ms": latency
|
||||
}
|
||||
|
||||
except Exception:
|
||||
latency = round((time.perf_counter() - start) * 1000, 2)
|
||||
|
||||
return {
|
||||
"status_code": None,
|
||||
"uptime": False,
|
||||
"latency_ms": latency
|
||||
}
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# DNS Lookup Time
|
||||
# -----------------------------
|
||||
def check_dns():
|
||||
host = BASE_URL.replace("https://", "").replace("http://", "").split("/")[0]
|
||||
|
||||
start = time.perf_counter()
|
||||
|
||||
try:
|
||||
socket.gethostbyname(host)
|
||||
dns_time = round((time.perf_counter() - start) * 1000, 2)
|
||||
|
||||
except Exception:
|
||||
dns_time = None
|
||||
|
||||
return dns_time
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# SSL Expiry
|
||||
# -----------------------------
|
||||
def check_ssl():
|
||||
host = BASE_URL.replace("https://", "").replace("http://", "").split("/")[0]
|
||||
|
||||
try:
|
||||
context = ssl.create_default_context()
|
||||
|
||||
with context.wrap_socket(
|
||||
socket.socket(socket.AF_INET),
|
||||
server_hostname=host
|
||||
) as s:
|
||||
|
||||
s.settimeout(10)
|
||||
s.connect((host, 443))
|
||||
|
||||
cert = s.getpeercert()
|
||||
|
||||
expire = datetime.strptime(
|
||||
cert["notAfter"],
|
||||
"%b %d %H:%M:%S %Y %Z"
|
||||
)
|
||||
|
||||
remaining = (expire - datetime.utcnow()).days
|
||||
|
||||
return {
|
||||
"expires_at": expire.isoformat(),
|
||||
"days_left": remaining
|
||||
}
|
||||
|
||||
except Exception:
|
||||
|
||||
return {
|
||||
"expires_at": None,
|
||||
"days_left": None
|
||||
}
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Search Response Time
|
||||
# -----------------------------
|
||||
def check_search():
|
||||
start = time.perf_counter()
|
||||
|
||||
try:
|
||||
response = requests.get(
|
||||
SEARCH_URL,
|
||||
timeout=10
|
||||
)
|
||||
|
||||
elapsed = round((time.perf_counter() - start) * 1000, 2)
|
||||
|
||||
return {
|
||||
"status": response.status_code,
|
||||
"response_ms": elapsed
|
||||
}
|
||||
|
||||
except Exception:
|
||||
|
||||
elapsed = round((time.perf_counter() - start) * 1000, 2)
|
||||
|
||||
return {
|
||||
"status": None,
|
||||
"response_ms": elapsed
|
||||
}
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Load JSON
|
||||
# -----------------------------
|
||||
def load_metrics():
|
||||
|
||||
if not os.path.exists(OUTPUT_FILE):
|
||||
return []
|
||||
|
||||
try:
|
||||
with open(OUTPUT_FILE, "r") as f:
|
||||
return json.load(f)
|
||||
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Save JSON
|
||||
# -----------------------------
|
||||
def save_metrics(data):
|
||||
|
||||
with open(OUTPUT_FILE, "w") as f:
|
||||
json.dump(data, f, indent=4)
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Main Monitor Loop
|
||||
# -----------------------------
|
||||
def monitor():
|
||||
|
||||
print("Starting Mithal Monitor...")
|
||||
|
||||
while True:
|
||||
|
||||
http = check_http()
|
||||
dns = check_dns()
|
||||
ssl_info = check_ssl()
|
||||
search = check_search()
|
||||
|
||||
record = {
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
|
||||
"latency_ms": http["latency_ms"],
|
||||
|
||||
"status_code": http["status_code"],
|
||||
|
||||
"uptime": http["uptime"],
|
||||
|
||||
"dns_lookup_ms": dns,
|
||||
|
||||
"ssl": ssl_info,
|
||||
|
||||
"search": search
|
||||
}
|
||||
|
||||
data = load_metrics()
|
||||
|
||||
data.append(record)
|
||||
|
||||
if len(data) > MAX_RECORDS:
|
||||
data = data[-MAX_RECORDS:]
|
||||
|
||||
save_metrics(data)
|
||||
|
||||
print(record)
|
||||
|
||||
time.sleep(INTERVAL)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
monitor()
|
||||
المرجع في مشكلة جديدة
حظر مستخدم