From 79c2b0d2ce6eb0d9c5b043a6b2835ddfb799a6b4 Mon Sep 17 00:00:00 2001 From: mina Date: Tue, 28 Jul 2026 13:31:34 +0300 Subject: [PATCH] Standalone app for Q5 deployment --- Dockerfile | 15 +++++++ dashboard.html | 102 +++++++++++++++++++++++++++++++++++++++++++++++ monitor.py | 84 ++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 + start.sh | 3 ++ 5 files changed, 206 insertions(+) create mode 100644 Dockerfile create mode 100644 dashboard.html create mode 100755 monitor.py create mode 100644 requirements.txt create mode 100755 start.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8be3062 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.11-slim + +WORKDIR /app + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY monitor.py . +COPY dashboard.html . +COPY start.sh . +RUN chmod +x start.sh + +EXPOSE 8080 + +CMD ["./start.sh"] diff --git a/dashboard.html b/dashboard.html new file mode 100644 index 0000000..2a26f19 --- /dev/null +++ b/dashboard.html @@ -0,0 +1,102 @@ + + + + +مراقبة mithal.space + + + +

لوحة مراقبة mithal.space

+ +
+
+
نسبة التشغيل (24 ساعة)
+
-
+
+
+
حالة SSL
+
-
+
+
+
آخر زمن استجابة
+
-
+
+
+ +
+
زمن الاستجابة — آخر ساعة
+ +
+ +
+

آخر 10 فحوصات

+ + + +
الوقتالحالةالاستجابةSSLDNS
+
+ + + + + diff --git a/monitor.py b/monitor.py new file mode 100755 index 0000000..3cfac7d --- /dev/null +++ b/monitor.py @@ -0,0 +1,84 @@ +import requests +import socket +import ssl +import time +import json +from datetime import datetime, timezone +from urllib.parse import urlparse + +TARGET_URL = "https://mithal.space" +SEARCH_URL = "https://mithal.space/search?q=test" +LOG_FILE = "mithal_monitor_log.json" +CHECK_INTERVAL = 60 + + +def check_latency_and_uptime(url): + try: + start = time.time() + response = requests.get(url, timeout=10) + latency_ms = round((time.time() - start) * 1000, 2) + return { + "up": response.status_code < 500, + "status_code": response.status_code, + "latency_ms": latency_ms + } + except requests.exceptions.RequestException as e: + return {"up": False, "status_code": None, "latency_ms": None, "error": str(e)} + + +def check_ssl(hostname): + try: + context = ssl.create_default_context() + with socket.create_connection((hostname, 443), timeout=10) as sock: + with context.wrap_socket(sock, server_hostname=hostname) as ssock: + cert = ssock.getpeercert() + expiry_str = cert['notAfter'] + expiry_date = datetime.strptime(expiry_str, '%b %d %H:%M:%S %Y %Z') + days_left = (expiry_date - datetime.utcnow()).days + return {"valid": True, "days_until_expiry": days_left} + except Exception as e: + return {"valid": False, "error": str(e)} + + +def check_dns(hostname): + try: + start = time.time() + socket.gethostbyname(hostname) + dns_time_ms = round((time.time() - start) * 1000, 2) + return {"resolved": True, "dns_time_ms": dns_time_ms} + except Exception as e: + return {"resolved": False, "error": str(e)} + + +def check_search_response(url): + try: + start = time.time() + response = requests.get(url, timeout=10) + latency_ms = round((time.time() - start) * 1000, 2) + return {"success": response.status_code == 200, "latency_ms": latency_ms} + except requests.exceptions.RequestException as e: + return {"success": False, "error": str(e)} + + +def run_check(): + hostname = urlparse(TARGET_URL).hostname + + result = { + "timestamp": datetime.now(timezone.utc).isoformat(), + "uptime": check_latency_and_uptime(TARGET_URL), + "ssl": check_ssl(hostname), + "dns": check_dns(hostname), + "search": check_search_response(SEARCH_URL) + } + + with open(LOG_FILE, "a") as f: + f.write(json.dumps(result) + "\n") + + print(f"[{result['timestamp']}] Check complete — up: {result['uptime']['up']}") + return result + + +if __name__ == "__main__": + while True: + run_check() + time.sleep(CHECK_INTERVAL) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7d11685 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests +dnspython diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..077c4c4 --- /dev/null +++ b/start.sh @@ -0,0 +1,3 @@ +#!/bin/sh +python3 monitor.py & +python3 -m http.server 8080