diff --git a/q1-deploy-monitor/Dockerfile b/q1-deploy-monitor/Dockerfile index e69de29..45818e6 100644 --- a/q1-deploy-monitor/Dockerfile +++ 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 . . + +EXPOSE 8000 + +CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/q1-deploy-monitor/__pycache__/app.cpython-313.pyc b/q1-deploy-monitor/__pycache__/app.cpython-313.pyc new file mode 100644 index 0000000..830c605 Binary files /dev/null and b/q1-deploy-monitor/__pycache__/app.cpython-313.pyc differ diff --git a/q1-deploy-monitor/app.py b/q1-deploy-monitor/app.py new file mode 100644 index 0000000..914857d --- /dev/null +++ b/q1-deploy-monitor/app.py @@ -0,0 +1,40 @@ +from fastapi import FastAPI +import time + +app = FastAPI() + +request_count = 0 + + +@app.get("/") +def home(): + global request_count + request_count += 1 + + return { + "message": "Application is running" + } + + +@app.get("/health") +def health(): + return { + "status": "UP" + } + + +@app.get("/stats") +def stats(): + global request_count + + start = time.time() + + request_count += 1 + + response_time = round((time.time() - start) * 1000, 2) + + return { + "status": "UP", + "requests": request_count, + "response_time": response_time + } diff --git a/q1-deploy-monitor/dashboard.html b/q1-deploy-monitor/dashboard.html index e69de29..aed253c 100644 --- a/q1-deploy-monitor/dashboard.html +++ b/q1-deploy-monitor/dashboard.html @@ -0,0 +1,98 @@ + + + + + + Application Dashboard + + + + + + + +
+ +

Application Dashboard

+ +

+ Status: + Loading... +

+ +

+ Requests: + 0 +

+ +

+ Response Time: + 0 ms +

+ +
+ + + + + diff --git a/q1-deploy-monitor/health-check.sh b/q1-deploy-monitor/health-check.sh old mode 100644 new mode 100755 index e69de29..ee1c54a --- a/q1-deploy-monitor/health-check.sh +++ b/q1-deploy-monitor/health-check.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +URL="http://localhost:8000/health" + +while true +do + response=$(curl -s -o /dev/null -w "%{http_code}" $URL) + + if [ "$response" -eq 200 ]; then + echo "$(date): Application is UP" + else + echo "$(date): Application is DOWN" + fi + + sleep 30 +done diff --git a/q1-deploy-monitor/requirements.txt b/q1-deploy-monitor/requirements.txt new file mode 100644 index 0000000..97dc7cd --- /dev/null +++ b/q1-deploy-monitor/requirements.txt @@ -0,0 +1,2 @@ +fastapi +uvicorn