diff --git a/Dockerfile b/Dockerfile index 49538b8..f8c2323 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,8 @@ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt COPY ./src/app /code/app +RUN mkdir -p /tmp/prometheus_multiproc + # -------- replace with comment to run with gunicorn -------- CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"] # CMD ["gunicorn", "app.main:app", "-w", "4", "-k", "uvicorn.workers.UvicornWorker". "-b", "0.0.0.0:8000"] diff --git a/README.md b/README.md index aec89f5..2a7f094 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ - [`Docker Compose`](https://docs.docker.com/compose/) With a single command, create and start all the services from your configuration. - [`NGINX`](https://nginx.org/en/) High-performance low resource consumption web server used for Reverse Proxy and Load Balancing. -> \[!TIP\] +> \[!TIP\] > If you want the `SQLModel` version instead, head to [SQLModel-boilerplate](https://github.com/igorbenav/SQLModel-boilerplate). ## 1. Features @@ -66,6 +66,8 @@ - πŸ€Έβ€β™‚οΈ Flexible - 🚚 Easy running with docker compose - βš–οΈ NGINX Reverse Proxy and Load Balancing +- πŸ“Š Prometheus metrics with Grafana dashboards for monitoring +- πŸ“– Loki and open telemetrics for logging ## 2. Contents @@ -100,9 +102,10 @@ 1. [ARQ Job Queues](#510-arq-job-queues) 1. [Rate Limiting](#511-rate-limiting) 1. [JWT Authentication](#512-jwt-authentication) - 1. [Running](#513-running) - 1. [Create Application](#514-create-application) - 2. [Opting Out of Services](#515-opting-out-of-services) + 1. [Monitoring](#513-monitoring) + 1. [Running](#514-running) + 1. [Create Application](#515-create-application) + 1. [Opting Out of Services](#516-opting-out-of-services) 1. [Running in Production](#6-running-in-production) 1. [Uvicorn Workers with Gunicorn](#61-uvicorn-workers-with-gunicorn) 1. [Running With NGINX](#62-running-with-nginx) @@ -581,6 +584,7 @@ First, you may want to take a look at the project structure and understand what β”‚ β”‚ β”œβ”€β”€ schemas.py # Pydantic schemas for data validation. β”‚ β”‚ β”œβ”€β”€ security.py # Security utilities, such as password hashing. β”‚ β”‚ β”œβ”€β”€ setup.py # Setup file for the FastAPI app instance. + β”‚ β”‚ β”œβ”€β”€ tracking.py # Metrics endpoint and open telemetrics setup β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ db # Core Database related modules. β”‚ β”‚ β”‚ β”œβ”€β”€ __init__.py @@ -619,6 +623,7 @@ First, you may want to take a look at the project structure and understand what β”‚ β”‚ β”‚ β”œβ”€β”€ middleware # Middleware components for the application. β”‚ β”‚ └── client_cache_middleware.py # Middleware for client-side caching. + β”‚ β”‚ └── prometheus_middleware.py # Middleware for prometheus metrics. β”‚ β”‚ β”‚ β”œβ”€β”€ models # ORM models for the application. β”‚ β”‚ β”œβ”€β”€ __init__.py @@ -1500,7 +1505,55 @@ What you should do with the client is: This authentication setup in the provides a robust, secure, and user-friendly way to handle user sessions in your API applications. -### 5.13 Running +### 5.13 Monitoring + +For real-time monitoring, make sure to uncomment the containers related to monitoring: + +- loki +- prometheus +- grafana +- tempo + +Inside of `.env`, create the following setting: + +``` +# ------------- monitoring settings ------------- +MONITORING=true +``` + +Also, for propper uniform logging, uncomment the x-logging and add the default logging to the worker and web. + +```Dockerfile +x-logging: &default-logging + driver: loki + options: + loki-url: 'http://localhost:3100/api/prom/push' + loki-pipeline-stages: | + - multiline: + firstline: '^\d{4}-\d{2}-\d{2} \d{1,2}:\d{2}:\d{2}' + max_wait_time: 3s + - regex: + expression: '^(?P