From f450e23dab1a4ffec5d6b1bfa2b0468ae7f47123 Mon Sep 17 00:00:00 2001 From: Abdelaiz Hassan Date: Wed, 29 Jul 2026 13:28:26 -0400 Subject: [PATCH] Clean Q5 files --- q5-mithal-monitor/dashboard.html | 258 +++++++++++++++++++++------- q5-mithal-monitor/monitor.py | 142 +++++++++++++-- q5-mithal-monitor/monitor_data.json | 82 +++++++++ 3 files changed, 411 insertions(+), 71 deletions(-) create mode 100644 q5-mithal-monitor/monitor_data.json diff --git a/q5-mithal-monitor/dashboard.html b/q5-mithal-monitor/dashboard.html index aed253c..b2f5177 100644 --- a/q5-mithal-monitor/dashboard.html +++ b/q5-mithal-monitor/dashboard.html @@ -1,98 +1,240 @@ + - - - Application Dashboard - +body{ +font-family:Arial; +background:#f4f4f4; +margin:30px; +} + +h1{ +text-align:center; +} + +.cards{ +display:flex; +justify-content:center; +gap:20px; +margin-bottom:30px; +flex-wrap:wrap; +} + +.card{ + +background:white; + +padding:20px; + +width:250px; + +border-radius:10px; + +box-shadow:0 0 10px rgba(0,0,0,.2); + +text-align:center; + +} + +canvas{ + +background:white; + +padding:20px; + +border-radius:10px; + +box-shadow:0 0 10px rgba(0,0,0,.2); + +} + +table{ + +margin-top:30px; + +width:100%; + +border-collapse:collapse; + +background:white; + +} + +th,td{ + +border:1px solid #ddd; + +padding:10px; + +text-align:center; + +} + +th{ + +background:#3498db; + +color:white; + +} + + +

Mithal Monitoring Dashboard

+ +
+
-

Application Dashboard

+

Uptime

-

- Status: - Loading... -

- -

- Requests: - 0 -

- -

- Response Time: - 0 ms -

+

0%

+
+ +

SSL Remaining

+ +

0 Days

+ +
+ +
+ +

Last Status

+ +

-

+ +
+ +
+ + + +

Last 10 Checks

+ + + + + + + + + + + + + + + + + + + + + + + + + +
TimeStatusLatency (ms)DNS (ms)Search (ms)
+ + diff --git a/q5-mithal-monitor/monitor.py b/q5-mithal-monitor/monitor.py index 29f8051..c4cc6a5 100644 --- a/q5-mithal-monitor/monitor.py +++ b/q5-mithal-monitor/monitor.py @@ -1,25 +1,141 @@ import requests +import socket +import ssl +import json import time +import os +from datetime import datetime, timezone +from urllib.parse import urlparse + +URL = "https://mithal.space" +SEARCH_URL = "https://mithal.space/?q=test" +OUTPUT_FILE = "monitor_data.json" + + +def get_latency(): + start = time.time() + response = requests.get(URL, timeout=10) + latency = round((time.time() - start) * 1000, 2) + return latency, response.status_code + + +def get_dns_time(): + host = urlparse(URL).hostname + + start = time.time() + socket.gethostbyname(host) + dns_time = round((time.time() - start) * 1000, 2) + + return dns_time + + +def get_ssl_info(): + host = urlparse(URL).hostname + + context = ssl.create_default_context() + + with socket.create_connection((host, 443), timeout=10) as sock: + with context.wrap_socket(sock, server_hostname=host) as ssock: + cert = ssock.getpeercert() + + expiry = cert["notAfter"] + + expiry_date = datetime.strptime( + expiry, + "%b %d %H:%M:%S %Y %Z" + ).replace(tzinfo=timezone.utc) + + remaining = (expiry_date - datetime.now(timezone.utc)).days + + return remaining, expiry + + +def get_search_latency(): + start = time.time() + + requests.get(SEARCH_URL, timeout=10) + + return round((time.time() - start) * 1000, 2) -URL = "http://127.0.0.1:8000/health" while True: + try: - start = time.time() - response = requests.get(URL) + latency, status = get_latency() - end = time.time() + uptime = "UP" if status == 200 else "DOWN" - response_time = round((end - start) * 1000, 2) + dns_time = get_dns_time() - print("=" * 40) - print("Status Code :", response.status_code) - print("Application :", "UP") - print("Response Time:", response_time, "ms") + ssl_days, ssl_expiry = get_ssl_info() - except Exception: - print("=" * 40) - print("Application : DOWN") + search_latency = get_search_latency() - time.sleep(30) + result = { + + "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + + "uptime": uptime, + + "status_code": status, + + "latency_ms": latency, + + "dns_ms": dns_time, + + "ssl_days_remaining": ssl_days, + + "ssl_expiry": ssl_expiry, + + "search_latency_ms": search_latency + + } + + except Exception as e: + + result = { + + "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + + "uptime": "DOWN", + + "status_code": 0, + + "latency_ms": 0, + + "dns_ms": 0, + + "ssl_days_remaining": 0, + + "ssl_expiry": "Unavailable", + + "search_latency_ms": 0, + + "error": str(e) + + } + + # Load previous history + if os.path.exists(OUTPUT_FILE): + try: + with open(OUTPUT_FILE, "r") as f: + history = json.load(f) + except: + history = [] + else: + history = [] + + # Add new result + history.append(result) + + # Keep only last 24 hours (1440 checks) + history = history[-1440:] + + # Save JSON + with open(OUTPUT_FILE, "w") as f: + json.dump(history, f, indent=4) + + print(result) + + time.sleep(60) diff --git a/q5-mithal-monitor/monitor_data.json b/q5-mithal-monitor/monitor_data.json new file mode 100644 index 0000000..b7d74ff --- /dev/null +++ b/q5-mithal-monitor/monitor_data.json @@ -0,0 +1,82 @@ +[ + { + "timestamp": "2026-07-29 13:21:04", + "uptime": "UP", + "status_code": 200, + "latency_ms": 742.61, + "dns_ms": 19.29, + "ssl_days_remaining": 47, + "ssl_expiry": "Sep 15 13:10:47 2026 GMT", + "search_latency_ms": 711.58 + }, + { + "timestamp": "2026-07-29 13:22:07", + "uptime": "UP", + "status_code": 200, + "latency_ms": 1359.55, + "dns_ms": 19.7, + "ssl_days_remaining": 47, + "ssl_expiry": "Sep 15 13:10:47 2026 GMT", + "search_latency_ms": 738.71 + }, + { + "timestamp": "2026-07-29 13:23:09", + "uptime": "UP", + "status_code": 200, + "latency_ms": 733.29, + "dns_ms": 27.96, + "ssl_days_remaining": 47, + "ssl_expiry": "Sep 15 13:10:47 2026 GMT", + "search_latency_ms": 690.43 + }, + { + "timestamp": "2026-07-29 13:24:10", + "uptime": "UP", + "status_code": 200, + "latency_ms": 678.63, + "dns_ms": 17.48, + "ssl_days_remaining": 47, + "ssl_expiry": "Sep 15 13:10:47 2026 GMT", + "search_latency_ms": 704.29 + }, + { + "timestamp": "2026-07-29 13:25:12", + "uptime": "UP", + "status_code": 200, + "latency_ms": 667.45, + "dns_ms": 18.25, + "ssl_days_remaining": 47, + "ssl_expiry": "Sep 15 13:10:47 2026 GMT", + "search_latency_ms": 700.19 + }, + { + "timestamp": "2026-07-29 13:26:14", + "uptime": "UP", + "status_code": 200, + "latency_ms": 712.69, + "dns_ms": 17.47, + "ssl_days_remaining": 47, + "ssl_expiry": "Sep 15 13:10:47 2026 GMT", + "search_latency_ms": 711.83 + }, + { + "timestamp": "2026-07-29 13:27:16", + "uptime": "UP", + "status_code": 200, + "latency_ms": 673.74, + "dns_ms": 18.32, + "ssl_days_remaining": 47, + "ssl_expiry": "Sep 15 13:10:47 2026 GMT", + "search_latency_ms": 696.53 + }, + { + "timestamp": "2026-07-29 13:28:18", + "uptime": "UP", + "status_code": 200, + "latency_ms": 855.31, + "dns_ms": 17.76, + "ssl_days_remaining": 47, + "ssl_expiry": "Sep 15 13:10:47 2026 GMT", + "search_latency_ms": 685.76 + } +] \ No newline at end of file