This repository contains a containerized monitoring and database stack used for analyzing and visualizing the performance of a MongoDB-based FastAPI blog system. It includes MongoDB, Prometheus, Grafana, and Node/MongoDB exporters — all orchestrated via Docker Compose.
git clone https://github.com/jiangfz1997/Blog_MongoDB.git
cd Blog_MongoDBNOTE: Make sure Docker and Docker Compose are installed on your system.
docker-compose up -dSystem will be running at:
- Grafana: http://localhost:3000
- Prometheus: http://localhost:9090
- MongoDB:
mongodb://localhost:27017 - FastAPI backend api doc: http://localhost:8001/docs
- Frontend: http://localhost:5173
For FastAPI backend or script usage:
# python version 3.11+
pip install -r requirements.txtNote: Backend FastAPI server is not included in the Docker Compose setup for development purposes. It needs to be run separately (see below). Start all services in detached mode:
docker compose up -dTo stop all services:
docker compose downIf you want to clean up unused containers:
docker compose down --remove-orphansRun the backend manually:
uvicorn src.main:app --reload --host 0.0.0.0 --port 8000This backend connects to the same MongoDB instance (default URI mongodb://localhost:27017).
Swagger UI is available at: http://localhost:8000/docs
Locust is used for load testing the FastAPI backend. To run locust:
locust -f locust_test.py --host http://localhost:8000Then open http://localhost:8089 in your browser to access the Locust web interface.
Log tracking still under development.
| Service | Description | Port |
|---|---|---|
| MongoDB | Primary database storing blog posts, user data, etc. | 27017 |
| Mongo Exporter | Exposes MongoDB internal metrics to Prometheus. | 9216 |
| Node Exporter | Exposes host & container-level metrics (CPU, memory, disk). | 9100 |
| Prometheus | Scrapes metrics from exporters, stores time-series data. | 9090 |
| Grafana | Visualization layer for metrics dashboards. | 3000 |
Once the containers are up:
-
Visit Grafana UI → http://localhost:3000
-
Default credentials: user:
adminpassword:admin -
Add the Prometheus data source (URL:
http://prometheus:9090) -
Import dashboards from the
dashboards/folder:MongoDB_Instances_Overview.json– MongoDB operations and latency visualization- Other panels include CPU, memory, and request throughput
To remove all containers and volumes:
docker compose down -vTo view logs for debugging:
docker compose logs -f mongo
docker compose logs -f prometheus
docker compose logs -f grafana- The Node Exporter installation script automatically runs inside the MongoDB container (see
node-exporter-install.sh). - If using Linux or MACOS, cadvisor can be used instead of Node Exporter for container metrics.
- You can modify
prometheus.ymlto add more targets or scrape intervals. - Grafana dashboards can be customized by exporting new JSONs from the UI.