A production-ready, Dockerized monitoring solution tailored for the BDCHub ecosystem. This stack automates the collection, aggregation, and visualization of host-level, container-level, and application-specific metrics.
The following diagram illustrates the flow of metrics collection and web traffic routing through the stack:
graph TD
subgraph Host_Infrastructure["Host Infrastructure"]
NodeExp["Node Exporter<br>(Host Metrics - Port 9100)"]
cAdvisor["cAdvisor<br>(Container Metrics - Port 8080)"]
AuthService["Auth Service<br>(Spring Actuator - Port 8080)"]
end
subgraph Monitoring_Core["Monitoring Stack"]
Prometheus["Prometheus Server<br>(TSDB - Port 9090)"]
Grafana["Grafana Dashboard<br>(UI - Port 3000)"]
end
subgraph Gateway["Traffic Routing"]
Traefik["Traefik Reverse Proxy"]
User["Operator / Web Browser"]
end
%% Metrics Scraping
NodeExp -.->|Scrapes /metrics| Prometheus
cAdvisor -.->|Scrapes /metrics| Prometheus
AuthService -.->|Scrapes /actuator/prometheus| Prometheus
%% Data Visualization
Prometheus β->|Query Data| Grafana
%% User Traffic
User β->|HTTP request to bdc.hpcc.vn/monitor| Gateway / Next.js
Gateway / Next.js β->|Proxies to bdc-grafana:3000/monitor| Grafana
- Automated Provisioning: Fully automated datasource configuration and dashboard ingestion on startup.
- Multi-Level Monitoring:
- Host Infrastructure: CPU, Memory, Disk, and Network monitoring via Node Exporter.
- Container Analytics: Real-time resource usage (CPU, RAM, I/O) of all running containers via cAdvisor.
- Application Performance (APM): Direct scraping from Spring Boot Actuator endpoints (e.g.,
auth-service).
- Cross-Platform Bootstrapping: Quick start shell script (
setup.sh) and PowerShell script (setup.ps1) for downloading, repairing, and preparing community dashboards. - Subpath Routing Ready: Pre-configured to run under the
/monitorsubpath (e.g.bdc.hpcc.vn/monitor) to seamlessly integrate with your main domain. - Log Management: Pre-configured JSON file log rotation policy limiting space consumption to max 30MB per container.
BDCmonitoring/
βββ docker-compose.yml # Docker services configuration
βββ setup.sh # Unix/Linux bootstrap script
βββ setup.ps1 # Windows PowerShell bootstrap script
βββ prometheus/
β βββ prometheus.yml # Scrape jobs and target definitions
βββ grafana/
βββ provisioning/ # Grafana config provisioning
β βββ dashboards/
β β βββ dashboards.yml
β βββ datasources/
β βββ datasource.yml
βββ dashboards/ # JSON Dashboards repository (populated by setup scripts)
Before launching the stack, ensure you have the following installed and configured:
-
Docker Engine & Docker Compose (v2.x or higher)
-
Network Dependency: The stack connects to an external network named
bdcapp_app-networkby default. You can create this manually or configure it via compose project name variables.To create the network manually:
docker network create bdcapp_app-network
Follow these steps to configure and boot the monitoring environment:
The bootstrap script creates local directories, pulls the latest production-grade Grafana dashboards, and patches the Prometheus datasource binding issues.
On Linux/macOS:
chmod +x setup.sh
./setup.shOn Windows (PowerShell):
.\setup.ps1Customize your deployment by creating a .env file in the root directory:
COMPOSE_PROJECT_NAME=bdcapp
GRAFANA_ADMIN_USER=admin
GRAFANA_ADMIN_PASSWORD=your_secure_password
GRAFANA_PORT=3010Deploy the services in detached mode using Docker Compose:
docker compose up -dOnce deployed, you can access the tools through the following ports:
| Service | Port (Internal) | Port (Host Default) | External Routing (Subpath) |
|---|---|---|---|
| Grafana | 3000 |
3010 |
bdc.hpcc.vn/monitor (via Next.js/Reverse Proxy) |
| Prometheus | 9090 |
Internal Only | N/A |
| Node Exporter | 9100 |
Internal Only | N/A |
| cAdvisor | 8080 |
Internal Only | N/A |
Since Grafana is configured to run under the /monitor subpath, you need to configure your Next.js application (bdc-frontend) to proxy these requests. Add the following block to your next.config.js file:
module.exports = {
async rewrites() {
return [
{
source: '/monitor/:path*',
destination: 'http://bdc-grafana:3000/monitor/:path*',
},
]
},
}Note: If Next.js and Grafana are not running in the same Docker network, replace bdc-grafana:3000 with your VM's IP address and Grafana's host port (e.g., http://<VM_IP>:3010/monitor/:path*).
The setup process installs two dashboard categories out of the box in Grafana:
- Node Exporter Full (ID:
1860): Total machine resources (Disk I/O, Network traffic, Memory/CPU utilization). - Docker Containers (ID:
14282): Aggregated and container-by-container resource limits and current consumption.
To monitor an additional application or service, add its address to prometheus.yml:
- job_name: 'my-new-service'
metrics_path: '/actuator/prometheus' # Optional if using Spring Boot
static_configs:
- targets: ['my-new-service:8080']After modifying the file, trigger Prometheus configuration reload without restarting the container:
curl -X POST http://localhost:9090/-/reload(Note: --web.enable-lifecycle is enabled to allow this dynamically).
To add more permanent dashboards to Grafana:
- Export the dashboard in JSON format from Grafana UI or find one on Grafana Dashboard Library.
- Place the JSON file under the
./grafana/dashboardsdirectory. - Grafana automatically registers and hot-reloads dashboard changes.
- Change Default Credentials: Never run the stack in production with default credentials. Set the
GRAFANA_ADMIN_PASSWORDenv variable to a secure string. - Network Isolation: Only Grafana is exposed externally or bound to host port by default. Keep Prometheus, cAdvisor, and Node Exporter within the private
app-network.