From 692e82ef4f5ee582198c33a06265546713e964bc Mon Sep 17 00:00:00 2001 From: Barden Date: Sun, 22 Feb 2026 12:54:57 +0300 Subject: [PATCH] Adding prometheus and grafana --- .github/workflows/first_pipeline.yml | 1 + app/main.py | 3 +++ docker-compose.yml | 19 ++++++++++++++++++- prometheus.yml | 21 +++++++++++++++++++++ requirements.txt | Bin 606 -> 690 bytes 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 prometheus.yml diff --git a/.github/workflows/first_pipeline.yml b/.github/workflows/first_pipeline.yml index ebd0d14..e151632 100644 --- a/.github/workflows/first_pipeline.yml +++ b/.github/workflows/first_pipeline.yml @@ -21,6 +21,7 @@ jobs: --health-timeout 5s --health-retries 5 + if: github.ref == 'refs/heads/dev' steps: - name: Checkout uses: actions/checkout@v4 diff --git a/app/main.py b/app/main.py index 3ed7ff9..27ba690 100644 --- a/app/main.py +++ b/app/main.py @@ -3,6 +3,7 @@ import redis.asyncio as asyncredis import uvicorn from fastapi import FastAPI +from prometheus_fastapi_instrumentator import Instrumentator from slowapi import _rate_limit_exceeded_handler from slowapi.errors import RateLimitExceeded @@ -22,6 +23,8 @@ async def lifespan(app: FastAPI): app = FastAPI(lifespan=lifespan) +Instrumentator().instrument(app).expose(app) + app.include_router(router) app.state.limiter = limiter diff --git a/docker-compose.yml b/docker-compose.yml index ee0d482..6e8d165 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -49,6 +49,21 @@ services: - certbot_conf:/etc/letsencrypt - certbot_www:/var/www/certbot + prometheus: + image: prom/prometheus + ports: + - "9090:9090" + volumes: + - ./prometheus.yml:/etc/prometheus/prometheus.yml + - prometheus_data:/prometheus + + grafana: + image: grafana/grafana + ports: + - "3000:3000" + volumes: + - grafana_data:/var/lib/grafana + certbot: image: certbot/certbot:latest volumes: @@ -59,4 +74,6 @@ services: volumes: postgres_data: certbot_conf: - certbot_www: \ No newline at end of file + certbot_www: + grafana_data: + prometheus_data: \ No newline at end of file diff --git a/prometheus.yml b/prometheus.yml new file mode 100644 index 0000000..1eb7c64 --- /dev/null +++ b/prometheus.yml @@ -0,0 +1,21 @@ +global: + scrape_interval: 15s + scrape_timeout: 10s + evaluation_interval: 15s +scrape_configs: + - job_name: prometheus + honor_timestamps: true + scrape_interval: 15s + scrape_timeout: 10s + metrics_path: /metrics + scheme: http + follow_redirects: true + static_configs: + - targets: + - localhost:9090 + - job_name: 'fastapi' + scrape_interval: 10s + metrics_path: /metrics + static_configs: + - targets: ['web:8000'] + diff --git a/requirements.txt b/requirements.txt index e17e5e32e0d59bc2f725b4e00fd58bbc4acbeace..737591fee09d356be625197bb306044f1c4bc4fc 100644 GIT binary patch delta 91 zcmcb|vWay=8KZvzLlHwhLoP!qLkU9$kSt{=X3%9wV@L$jB|x%(Arr{YWXJ>ai-7VV bwRvE<5}?i^23sIBXV7CX1Y(29g^X_j)$|k% delta 11 ScmdnQdXHs88RO(rj4uEj{sjjB