From 6fa7a014f7839880800968ddd6af9249c070789a Mon Sep 17 00:00:00 2001 From: hassan90122 Date: Tue, 28 Jul 2026 21:52:22 +0000 Subject: [PATCH] Add Question 5 Mithal monitoring dashboard --- q5-mithal-monitor/dashboard.html | 179 +++++++++++++++++++++++++++++++ q5-mithal-monitor/metrics.csv | 2 + q5-mithal-monitor/monitor.py | 94 ++++++++++++++++ 3 files changed, 275 insertions(+) create mode 100644 q5-mithal-monitor/dashboard.html create mode 100644 q5-mithal-monitor/metrics.csv create mode 100644 q5-mithal-monitor/monitor.py diff --git a/q5-mithal-monitor/dashboard.html b/q5-mithal-monitor/dashboard.html new file mode 100644 index 0000000..fdde84f --- /dev/null +++ b/q5-mithal-monitor/dashboard.html @@ -0,0 +1,179 @@ + + + + + + + + +Mithal Monitoring Dashboard + + + + + + + + + +

Mithal Monitoring Dashboard

+ +
+ +

Uptime (24 Hours)

+ +

Loading...

+ +
+ +
+ +

SSL Certificate

+ +

Loading...

+ +
+ +
+ +

Latency (Last Hour)

+ + + +
+ +
+ +

Last 10 Checks

+ +
+ +
+ + + + + + diff --git a/q5-mithal-monitor/metrics.csv b/q5-mithal-monitor/metrics.csv new file mode 100644 index 0000000..1f2ea43 --- /dev/null +++ b/q5-mithal-monitor/metrics.csv @@ -0,0 +1,2 @@ +timestamp,latency_ms,status_code,ssl_days_left,dns_ms,search_ms +2026-07-28 21:48:04,1089.54,200,48,3.73,9141.39 diff --git a/q5-mithal-monitor/monitor.py b/q5-mithal-monitor/monitor.py new file mode 100644 index 0000000..be2791b --- /dev/null +++ b/q5-mithal-monitor/monitor.py @@ -0,0 +1,94 @@ +import csv +import os +import time +import ssl +import socket +from datetime import datetime + +import requests +import dns.resolver +from OpenSSL import crypto + +URL = "https://mithal.space" +SEARCH_URL = "https://mithal.space" + +CSV_FILE = "metrics.csv" + +if not os.path.exists(CSV_FILE): + with open(CSV_FILE, "w", newline="") as file: + writer = csv.writer(file) + writer.writerow([ + "timestamp", + "latency_ms", + "status_code", + "ssl_days_left", + "dns_ms", + "search_ms" + ]) + +while True: + + timestamp = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + + # HTTP Latency + Uptime + try: + start = time.time() + response = requests.get(URL, timeout=10) + latency = round((time.time() - start) * 1000, 2) + status = response.status_code + except: + latency = -1 + status = 0 + + # SSL + try: + cert = ssl.get_server_certificate(("mithal.space", 443)) + cert = crypto.load_certificate( + crypto.FILETYPE_PEM, + cert + ) + + expire = datetime.strptime( + cert.get_notAfter().decode(), + "%Y%m%d%H%M%SZ" + ) + + ssl_days = (expire - datetime.utcnow()).days + + except: + ssl_days = -1 + + # DNS + try: + start = time.time() + dns.resolver.resolve("mithal.space", "A") + dns_time = round((time.time() - start) * 1000, 2) + except: + dns_time = -1 + + # Search + try: + start = time.time() + requests.get( + SEARCH_URL, + params={"q": "cloud"}, + timeout=10 + ) + search_time = round((time.time() - start) * 1000, 2) + except: + search_time = -1 + + with open(CSV_FILE, "a", newline="") as file: + writer = csv.writer(file) + writer.writerow([ + timestamp, + latency, + status, + ssl_days, + dns_time, + search_time + ]) + + print(timestamp, status, latency) + + time.sleep(60)