diff --git a/app.py b/app.py new file mode 100644 index 0000000..6681545 --- /dev/null +++ b/app.py @@ -0,0 +1,88 @@ +from flask import Flask +import time + +app = Flask(__name__) + +request_count = 0 + +@app.before_request +def count_requests(): + global request_count + request_count += 1 + +@app.route("/") +def home(): + return f""" + + + + Ghaymah Systems API + + + + +
+

🚀 Ghaymah Systems API

+ +

The API is running successfully.

+ +

Total Requests: {request_count}

+ + Health Check +
+ + + + """ + +@app.route("/health") +def health(): + return { + "status": "healthy", + "timestamp": int(time.time()), + "requests": request_count + } + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=5000) diff --git a/q1-deploy-monitor/Dockerfile b/q1-deploy-monitor/Dockerfile new file mode 100644 index 0000000..29cab9b --- /dev/null +++ b/q1-deploy-monitor/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.12-slim + +WORKDIR /app + +COPY requirements.txt . + +RUN pip install --no-cache-dir -r requirements.txt + +COPY app.py . + +EXPOSE 5000 + +CMD ["python", "app.py"] diff --git a/q1-deploy-monitor/dashboard.html b/q1-deploy-monitor/dashboard.html new file mode 100644 index 0000000..cc71fc8 --- /dev/null +++ b/q1-deploy-monitor/dashboard.html @@ -0,0 +1,92 @@ + + + + +Ghaymah SRE Dashboard + + + + + + +
+ +

Ghaymah API Monitoring Dashboard

+ +
+

Status

+
Checking...
+
+ +
+

Latency

+
-- ms
+
+ +
+

Total Requests

+
0
+
+ +
+ + + + + diff --git a/q1-deploy-monitor/health-check.sh b/q1-deploy-monitor/health-check.sh new file mode 100755 index 0000000..2c3b4d5 --- /dev/null +++ b/q1-deploy-monitor/health-check.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +URL="http://localhost:5000/health" + +while true +do + START=$(date +%s%3N) + + STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$URL") + + END=$(date +%s%3N) + + LATENCY=$((END-START)) + + if [ "$STATUS" -eq 200 ]; then + echo "$(date) | UP | ${LATENCY}ms" + else + echo "$(date) | DOWN" + fi + + sleep 30 +done diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9ea9c8a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask==3.0.3 +gunicorn==23.0.0