Edit code and Dockerfile
هذا الالتزام موجود في:
@@ -8,8 +8,6 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN mv dashboard.html index.html
|
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
CMD sh -c "python3 monitor.py && python3 -m http.server 8080"
|
CMD ["python3","app.py"]
|
||||||
|
|||||||
51
q5-mithal-monitor/app.py
Normal file
51
q5-mithal-monitor/app.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
from flask import Flask, send_file, jsonify
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
from monitor import collect_metrics
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def monitor_loop():
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
collect_metrics()
|
||||||
|
print("Metrics updated.")
|
||||||
|
except Exception as e:
|
||||||
|
print("Monitor error:", e)
|
||||||
|
|
||||||
|
time.sleep(60)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def dashboard():
|
||||||
|
return send_file("dashboard.html")
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/metrics.json")
|
||||||
|
def metrics():
|
||||||
|
if os.path.exists("metrics.json"):
|
||||||
|
with open("metrics.json") as f:
|
||||||
|
return jsonify(json.load(f))
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"uptime": 0,
|
||||||
|
"last_check": {},
|
||||||
|
"history": [],
|
||||||
|
"latency_chart": []
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# Run one check immediately
|
||||||
|
collect_metrics()
|
||||||
|
|
||||||
|
# Start background monitoring
|
||||||
|
thread = threading.Thread(target=monitor_loop, daemon=True)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
# Start Flask
|
||||||
|
app.run(host="0.0.0.0", port=8080)
|
||||||
@@ -8,255 +8,195 @@
|
|||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
*{
|
|
||||||
margin:0;
|
|
||||||
padding:0;
|
|
||||||
box-sizing:border-box;
|
|
||||||
font-family:Arial,Helvetica,sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
body{
|
body{
|
||||||
background:#f4f6f9;
|
font-family:Arial,sans-serif;
|
||||||
padding:30px;
|
background:#f4f4f4;
|
||||||
|
margin:20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1{
|
h1{
|
||||||
text-align:center;
|
text-align:center;
|
||||||
margin-bottom:30px;
|
|
||||||
color:#2c3e50;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.cards{
|
.cards{
|
||||||
display:grid;
|
display:grid;
|
||||||
grid-template-columns:repeat(auto-fit,minmax(230px,1fr));
|
grid-template-columns:repeat(auto-fit,minmax(220px,1fr));
|
||||||
gap:20px;
|
gap:20px;
|
||||||
margin-bottom:30px;
|
margin:20px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card{
|
.card{
|
||||||
background:white;
|
background:white;
|
||||||
border-radius:10px;
|
|
||||||
padding:20px;
|
padding:20px;
|
||||||
box-shadow:0 3px 8px rgba(0,0,0,.15);
|
border-radius:10px;
|
||||||
|
box-shadow:0 2px 6px rgba(0,0,0,.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
.card h3{
|
|
||||||
color:#555;
|
|
||||||
margin-bottom:10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.value{
|
.value{
|
||||||
font-size:30px;
|
font-size:28px;
|
||||||
|
color:#007bff;
|
||||||
font-weight:bold;
|
font-weight:bold;
|
||||||
color:#007BFF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
table{
|
table{
|
||||||
width:100%;
|
width:100%;
|
||||||
border-collapse:collapse;
|
border-collapse:collapse;
|
||||||
background:white;
|
|
||||||
margin-top:30px;
|
margin-top:30px;
|
||||||
box-shadow:0 3px 8px rgba(0,0,0,.15);
|
background:white;
|
||||||
}
|
}
|
||||||
|
th,td{
|
||||||
table th{
|
border:1px solid #ddd;
|
||||||
background:#007BFF;
|
|
||||||
color:white;
|
|
||||||
padding:12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
table td{
|
|
||||||
padding:10px;
|
padding:10px;
|
||||||
text-align:center;
|
text-align:center;
|
||||||
border-bottom:1px solid #ddd;
|
|
||||||
}
|
}
|
||||||
|
th{
|
||||||
|
background:#007bff;
|
||||||
|
color:white;
|
||||||
|
}
|
||||||
canvas{
|
canvas{
|
||||||
background:white;
|
|
||||||
margin-top:30px;
|
margin-top:30px;
|
||||||
padding:20px;
|
background:white;
|
||||||
|
padding:15px;
|
||||||
border-radius:10px;
|
border-radius:10px;
|
||||||
box-shadow:0 3px 8px rgba(0,0,0,.15);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.good{
|
.good{
|
||||||
color:green;
|
color:green;
|
||||||
font-weight:bold;
|
font-weight:bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bad{
|
.bad{
|
||||||
color:red;
|
color:red;
|
||||||
font-weight:bold;
|
font-weight:bold;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
|
||||||
|
|
||||||
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>🚀 Mithal Monitoring Dashboard</h1>
|
<h1>Mithal Monitoring Dashboard</h1>
|
||||||
|
|
||||||
<div class="cards">
|
<div class="cards">
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h3>Uptime (24h)</h3>
|
<h3>Uptime</h3>
|
||||||
<div id="uptime" class="value">-- %</div>
|
<div id="uptime" class="value">--</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h3>Latency</h3>
|
<h3>Latency</h3>
|
||||||
<div id="latency" class="value">-- ms</div>
|
<div id="latency" class="value">--</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h3>DNS Lookup</h3>
|
<h3>DNS</h3>
|
||||||
<div id="dns" class="value">-- ms</div>
|
<div id="dns" class="value">--</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h3>Search Response</h3>
|
<h3>Search</h3>
|
||||||
<div id="search" class="value">-- ms</div>
|
<div id="search" class="value">--</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h3>SSL Expiry</h3>
|
<h3>SSL Expiry</h3>
|
||||||
<div id="ssl" class="value" style="font-size:22px;">--</div>
|
<div id="ssl" class="value" style="font-size:18px">--</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h3>Days Remaining</h3>
|
<h3>Days Left</h3>
|
||||||
<div id="days" class="value">--</div>
|
<div id="days" class="value">--</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<canvas id="latencyChart" height="100"></canvas>
|
<canvas id="chart"></canvas>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
|
|
||||||
<thead>
|
<thead>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
|
|
||||||
<th>Time</th>
|
<th>Time</th>
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
<th>Latency</th>
|
<th>Latency</th>
|
||||||
<th>DNS</th>
|
<th>DNS</th>
|
||||||
<th>Search</th>
|
<th>Search</th>
|
||||||
<th>SSL Days</th>
|
<th>SSL Days</th>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody id="history">
|
<tbody id="history"></tbody>
|
||||||
|
|
||||||
</tbody>
|
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
async function loadData(){
|
let chart=null;
|
||||||
|
|
||||||
const response=await fetch("metrics.json");
|
async function loadMetrics(){
|
||||||
|
|
||||||
const data=await response.json();
|
const response=await fetch("/metrics.json");
|
||||||
|
|
||||||
document.getElementById("uptime").innerHTML=data.uptime+" %";
|
const data=await response.json();
|
||||||
|
|
||||||
document.getElementById("latency").innerHTML=data.last_check.latency+" ms";
|
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;
|
||||||
|
|
||||||
document.getElementById("dns").innerHTML=data.last_check.dns+" ms";
|
const tbody=document.getElementById("history");
|
||||||
|
|
||||||
document.getElementById("search").innerHTML=data.last_check.search_latency+" ms";
|
tbody.innerHTML="";
|
||||||
|
|
||||||
document.getElementById("ssl").innerHTML=data.last_check.ssl_expiry;
|
[...data.history].reverse().forEach(item=>{
|
||||||
|
|
||||||
document.getElementById("days").innerHTML=data.last_check.ssl_days_left+" days";
|
tbody.innerHTML+=`
|
||||||
|
<tr>
|
||||||
|
<td>${item.time}</td>
|
||||||
|
<td class="${item.status==200?'good':'bad'}">${item.status}</td>
|
||||||
|
<td>${item.latency}</td>
|
||||||
|
<td>${item.dns}</td>
|
||||||
|
<td>${item.search_latency}</td>
|
||||||
|
<td>${item.ssl_days_left}</td>
|
||||||
|
</tr>`;
|
||||||
|
});
|
||||||
|
|
||||||
let tbody=document.getElementById("history");
|
const labels=data.latency_chart.map((_,i)=>i+1);
|
||||||
|
|
||||||
tbody.innerHTML="";
|
if(chart){
|
||||||
|
chart.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
data.history.reverse().forEach(item=>{
|
chart=new Chart(document.getElementById("chart"),{
|
||||||
|
|
||||||
tbody.innerHTML+=`
|
type:"line",
|
||||||
|
|
||||||
<tr>
|
data:{
|
||||||
|
|
||||||
<td>${item.time}</td>
|
labels:labels,
|
||||||
|
|
||||||
<td class="${item.status==200?'good':'bad'}">
|
datasets:[{
|
||||||
|
|
||||||
${item.status}
|
label:"Latency (ms)",
|
||||||
|
|
||||||
</td>
|
data:data.latency_chart,
|
||||||
|
|
||||||
<td>${item.latency} ms</td>
|
borderColor:"#007bff",
|
||||||
|
|
||||||
<td>${item.dns} ms</td>
|
fill:false,
|
||||||
|
|
||||||
<td>${item.search_latency} ms</td>
|
tension:.3
|
||||||
|
|
||||||
<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"),{
|
loadMetrics();
|
||||||
|
|
||||||
type:"line",
|
setInterval(loadMetrics,60000);
|
||||||
|
|
||||||
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>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,117 +0,0 @@
|
|||||||
{
|
|
||||||
"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
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -11,139 +11,82 @@ URL = "https://mithal.space"
|
|||||||
OUTPUT_FILE = "metrics.json"
|
OUTPUT_FILE = "metrics.json"
|
||||||
|
|
||||||
|
|
||||||
def http_check():
|
def collect_metrics():
|
||||||
|
hostname = urlparse(URL).hostname
|
||||||
|
|
||||||
|
# HTTP latency & uptime
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = requests.get(URL, timeout=10)
|
response = requests.get(URL, timeout=10)
|
||||||
latency = round((time.time() - start) * 1000, 2)
|
latency = round((time.time() - start) * 1000, 2)
|
||||||
return r.status_code, latency
|
status = response.status_code
|
||||||
except:
|
except Exception:
|
||||||
latency = round((time.time() - start) * 1000, 2)
|
latency = -1
|
||||||
return 0, latency
|
status = 0
|
||||||
|
|
||||||
|
|
||||||
def dns_lookup():
|
|
||||||
host = urlparse(URL).hostname
|
|
||||||
|
|
||||||
|
# DNS lookup
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
socket.gethostbyname(host)
|
socket.gethostbyname(hostname)
|
||||||
except:
|
dns = round((time.time() - start) * 1000, 2)
|
||||||
pass
|
except Exception:
|
||||||
|
dns = -1
|
||||||
return round((time.time() - start) * 1000, 2)
|
|
||||||
|
|
||||||
|
|
||||||
def ssl_info():
|
|
||||||
|
|
||||||
host = urlparse(URL).hostname
|
|
||||||
|
|
||||||
|
# SSL expiry
|
||||||
|
ssl_expiry = "Unavailable"
|
||||||
|
ssl_days = -1
|
||||||
try:
|
try:
|
||||||
|
context = ssl.create_default_context()
|
||||||
ctx = ssl.create_default_context()
|
with socket.create_connection((hostname, 443), timeout=10) as sock:
|
||||||
|
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
|
||||||
with socket.create_connection((host,443),timeout=10) as sock:
|
|
||||||
|
|
||||||
with ctx.wrap_socket(sock,server_hostname=host) as ssock:
|
|
||||||
|
|
||||||
cert = ssock.getpeercert()
|
cert = ssock.getpeercert()
|
||||||
|
|
||||||
expiry = datetime.strptime(
|
expiry = datetime.strptime(cert["notAfter"], "%b %d %H:%M:%S %Y %Z")
|
||||||
cert["notAfter"],
|
ssl_expiry = expiry.strftime("%Y-%m-%d")
|
||||||
"%b %d %H:%M:%S %Y %Z"
|
ssl_days = (expiry - datetime.utcnow()).days
|
||||||
)
|
except Exception:
|
||||||
|
|
||||||
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
|
pass
|
||||||
|
|
||||||
return round((time.time()-start)*1000,2)
|
# Search response
|
||||||
|
start = time.time()
|
||||||
|
try:
|
||||||
|
requests.get(URL, timeout=10)
|
||||||
|
search_latency = round((time.time() - start) * 1000, 2)
|
||||||
|
except Exception:
|
||||||
|
search_latency = -1
|
||||||
|
|
||||||
|
if os.path.exists(OUTPUT_FILE):
|
||||||
|
with open(OUTPUT_FILE) as f:
|
||||||
|
data = json.load(f)
|
||||||
|
else:
|
||||||
|
data = {"history": []}
|
||||||
|
|
||||||
if os.path.exists(OUTPUT_FILE):
|
history = data.get("history", [])
|
||||||
|
|
||||||
with open(OUTPUT_FILE,"r") as f:
|
history.append({
|
||||||
|
"time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
|
"status": status,
|
||||||
|
"latency": latency,
|
||||||
|
"dns": dns,
|
||||||
|
"ssl_expiry": ssl_expiry,
|
||||||
|
"ssl_days_left": ssl_days,
|
||||||
|
"search_latency": search_latency
|
||||||
|
})
|
||||||
|
|
||||||
data=json.load(f)
|
history = history[-1440:]
|
||||||
|
|
||||||
else:
|
uptime = round(
|
||||||
|
len([x for x in history if x["status"] == 200]) /
|
||||||
data={
|
len(history) * 100,
|
||||||
|
2
|
||||||
"history":[]
|
)
|
||||||
|
|
||||||
|
output = {
|
||||||
|
"uptime": uptime,
|
||||||
|
"last_check": history[-1],
|
||||||
|
"history": history[-10:],
|
||||||
|
"latency_chart": [x["latency"] for x in history[-60:]]
|
||||||
}
|
}
|
||||||
|
|
||||||
status,latency=http_check()
|
with open(OUTPUT_FILE, "w") as f:
|
||||||
|
json.dump(output, f, indent=4)
|
||||||
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 +1,2 @@
|
|||||||
|
Flask
|
||||||
requests
|
requests
|
||||||
|
|||||||
المرجع في مشكلة جديدة
حظر مستخدم