From 0c27e4dd2488d10147ca8cd396582b8a6de152d6 Mon Sep 17 00:00:00 2001 From: Abdelaiz Hassan Date: Mon, 27 Jul 2026 19:57:44 -0400 Subject: [PATCH] Complete all exam tasks --- q1-deploy-monitor/Dockerfile | 13 +++ .../__pycache__/app.cpython-313.pyc | Bin 0 -> 1215 bytes q1-deploy-monitor/app.py | 40 +++++++ q1-deploy-monitor/dashboard.html | 98 ++++++++++++++++++ q1-deploy-monitor/health-check.sh | 16 +++ q1-deploy-monitor/requirements.txt | 2 + 6 files changed, 169 insertions(+) create mode 100644 q1-deploy-monitor/__pycache__/app.cpython-313.pyc create mode 100644 q1-deploy-monitor/app.py mode change 100644 => 100755 q1-deploy-monitor/health-check.sh create mode 100644 q1-deploy-monitor/requirements.txt 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 0000000000000000000000000000000000000000..830c6059328b6645d37e17e5928b1c6406151818 GIT binary patch literal 1215 zcmaJ=&1(}u6rb7I-6XbKn~#3?5Tyt~wyR);stAQDw#8Dr^wdIGn>AUEUh?>bn_AVXy4tM!z$v*#o@s@mv1uDc)qH5!s&O}OmJC3sjG9{c zqMA3olDnzeu4DNw)eO&@^fm*LJEFbdGy#)kLDbN18A++_JA2|_?RH&8iPXpR`8pAL zuB$SrrYA2w;2 zjEfrL;gj1F$D_*{cgOw;F2aSd{=1-b*MAxI$495v9JI=r3rEBhUX|J>9TxxZWd*5_ zi!P{e6FM~V=wMy!cwfP~G)aJed6CKx!1@W#J>*b&8bprJK3IZyL^ z>>m6E!?P%_JRJZL5NNH|8%e?R!`=#64WDwH_V_j1%~wk1b;^GY{}s#zQ70JVuW0Nu z>iI4!TUL#H>rd7c=mtT0JoISjNqTF%A;?&65+wB1xmHiLZ6o_Q-4IC2n5lEE-rF_~ Q@8eWMP+CTSffhFOAJS#!vj6}9 literal 0 HcmV?d00001 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