From ab92c09b921b3358b4dfc75261dd9aaf5d19f1ca Mon Sep 17 00:00:00 2001 From: youyeon11 Date: Thu, 2 Oct 2025 15:53:32 +0900 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20docker=20=EB=AA=85=EB=A0=B9=EC=96=B4?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC=20=EC=B0=B8=EC=A1=B0=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deployment/deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/deploy.sh b/deployment/deploy.sh index 9f012d4..9ba080b 100644 --- a/deployment/deploy.sh +++ b/deployment/deploy.sh @@ -22,8 +22,8 @@ fi echo "Pulling new image" # docker pull -docker compose pull app-${AFTER_COMPOSE_COLOR} -docker compose up -d --no-deps --force-recreate app-${AFTER_COMPOSE_COLOR} +docker compose -f docker-compose.yml pull app-${AFTER_COMPOSE_COLOR} +docker compose -f docker-compose.yml up -d --no-deps --force-recreate app-${AFTER_COMPOSE_COLOR} # 새 컨테이너가 running 될 때까지 대기 From 9708ad08d274ccdc960fb9e785c395a822ebf093 Mon Sep 17 00:00:00 2001 From: youyeon11 Date: Thu, 2 Oct 2025 15:53:58 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=EB=AA=A8=EB=8B=88=ED=84=B0?= =?UTF-8?q?=EB=A7=81=20=ED=99=98=EA=B2=BD=20=EC=B6=94=EA=B0=80(prometheus/?= =?UTF-8?q?grafana)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deployment/docker-compose.monitoring.yml | 33 +++++++++++++++++++++++ deployment/prometheus-rule.yml | 17 ++++++++++++ deployment/prometheus.yml | 34 ++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 deployment/docker-compose.monitoring.yml create mode 100644 deployment/prometheus-rule.yml create mode 100644 deployment/prometheus.yml diff --git a/deployment/docker-compose.monitoring.yml b/deployment/docker-compose.monitoring.yml new file mode 100644 index 0000000..a26403f --- /dev/null +++ b/deployment/docker-compose.monitoring.yml @@ -0,0 +1,33 @@ +services: + prometheus: + user: ${PROMETHEUS_USER} + image: prom/prometheus:latest + container_name: prometheus + volumes: + - /home/ubuntu/dearbelly/deployment/prometheus.yml:/etc/prometheus/prometheus.yml:ro + - /home/ubuntu/prometheus/volume:/prometheus/data + ports: + - 9090:9090 + command: + - '--web.enable-lifecycle' + - '--config.file=/etc/prometheus/prometheus.yml' + - '--storage.tsdb.retention.time=15d' + restart: always + networks: + - mynetwork + + grafana: + user: ${GRAFANA_USER} + image: grafana/grafana:latest + container_name: grafana + ports: + - 3000:3000 + volumes: + - /home/ubuntu/grafana/volume:/var/lib/grafana + restart: always + networks: + - mynetwork + +networks: + mynetwork: + driver: bridge \ No newline at end of file diff --git a/deployment/prometheus-rule.yml b/deployment/prometheus-rule.yml new file mode 100644 index 0000000..2c72a59 --- /dev/null +++ b/deployment/prometheus-rule.yml @@ -0,0 +1,17 @@ +groups: + - name: example + rules: + - alert: InstanceDown + expr: up == 0 + for: 5m + labels: + severity: page + annotations: + summary: "Instance {{ $labels.instance }} down" + description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes." + - alert: APIHighRequestLatency + expr: api_http_request_latencies_second{quantile="0.5"} > 1 + for: 10m + annotations: + summary: "High request latency on {{ $labels.instance }}" + description: "{{ $labels.instance }} has a median request latency above 1s (current value: {{ $value }}s)" \ No newline at end of file diff --git a/deployment/prometheus.yml b/deployment/prometheus.yml new file mode 100644 index 0000000..13bda8f --- /dev/null +++ b/deployment/prometheus.yml @@ -0,0 +1,34 @@ +global: + scrape_interval: 15s + scrape_timeout: 15s + evaluation_interval: 2m + external_labels: + monitor: 'codelab-monitor' + query_log_file: query_log_file.log +rule_files: + - "prometheus-rule.yml" +scrape_configs: + - job_name: 'prometheus' + scrape_interval: 10s + scrape_timeout: 10s + metrics_path: '/metrics' + honor_labels: false + honor_timestamps: false + scheme: 'http' + static_configs: + - targets: ['${REMOTE_HOST}:9090'] + labels: + service: 'monitor-1' + - job_name: 'node' + static_configs: + - targets: ['${REMOTE_HOST}:9090'] + - job_name: 'fastapi-actuator-blue' + metrics_path: '/actuator/prometheus' + scrape_interval: 1m + static_configs: + - targets: [ 'app-blue:8000' ] + - job_name: 'fastapi-actuator-green' + metrics_path: '/actuator/prometheus' + scrape_interval: 1m + static_configs: + - targets: [ 'app-green:8001' ] \ No newline at end of file From 0da15a15365e595b0a15c84fc3d65d89259e7f50 Mon Sep 17 00:00:00 2001 From: youyeon11 Date: Thu, 2 Oct 2025 15:54:11 +0900 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=EB=A9=94=ED=8A=B8=EB=A6=AD=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20path=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/main.py b/app/main.py index 3e852a0..19c2ffc 100644 --- a/app/main.py +++ b/app/main.py @@ -2,6 +2,7 @@ from app.core.lifespan import lifespan from app.api.endpoints import predictions from app.core.logging_config import setup_logging +from prometheus_fastapi_instrumentator import Instrumentator setup_logging() app = FastAPI( @@ -11,6 +12,8 @@ lifespan=lifespan ) +instrumentator = Instrumentator().instrument(app) +instrumentator.expose(app, include_in_schema=False, endpoint="/actuator/prometheus") app.include_router(predictions.router, prefix="/api/v1", tags=["Prediction"]) @app.get("/health") From 8aebacfeb142a5c00e69a4e3e15b0f44d6e35c06 Mon Sep 17 00:00:00 2001 From: youyeon11 Date: Thu, 2 Oct 2025 15:57:16 +0900 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20transfer=20=EA=B2=BD=EB=A1=9C=20?= =?UTF-8?q?=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index d502246..d234b64 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -44,7 +44,7 @@ jobs: username: ${{ secrets.REMOTE_USER }} key: ${{ secrets.SSH_PRIVATE_KEY }} source: ./deployment/ - target: /home/ubuntu/deployment + target: /home/ubuntu/dearbelly deploy: name: Deploy From cd73df11efaf6ab3b63921ce59ece75abaf172ab Mon Sep 17 00:00:00 2001 From: youyeon11 Date: Thu, 2 Oct 2025 15:57:30 +0900 Subject: [PATCH 5/5] =?UTF-8?q?chore:=20prometheus=20=EB=9D=BC=EC=9D=B4?= =?UTF-8?q?=EB=B8=8C=EB=9F=AC=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 339d3b7..e904539 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,6 @@ Pillow==11.3.0 dotenv openai timm -logging \ No newline at end of file +logging +prometheus-client==0.19.0 +prometheus-fastapi-instrumentator==6.1.0 \ No newline at end of file