Monitoring system performance and application health is crucial for maintaining reliability and efficiency. This article walks through setting up Grafana, Prometheus, and Node Exporter using Docker.
Prerequisites
- Docker and Docker Compose installed on your system
Docker Compose Configuration
Below is a docker-compose.yml file that sets up Grafana, Prometheus, and Node Exporter:
services:
grafana:
image: grafana/grafana-enterprise
container_name: grafana
restart: unless-stopped
ports:
- '3000:3000'
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
- GF_PLUGINS_PREINSTALL=grafana-clock-panel
- GF_SERVER_ROOT_URL=http://localhost:3000/
volumes:
- grafana_data:/var/lib/grafana
prometheus:
image: prom/prometheus
container_name: prometheus
restart: unless-stopped
ports:
- '9090:9090'
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
node-exporter:
image: prom/node-exporter
container_name: node-exporter
restart: unless-stopped
ports:
- '9100:9100'
volumes:
grafana_data: {}
prometheus_data: {}
Explanation of Services
- Grafana
- Runs on port 3000
- Uses admin/admin as the default credentials (can be changed).
- Preinstalls the grafana-clock-panel plugin.
- Stores data in a named volume grafana_data.
- Prometheus
- Runs on port 9090.
- Uses a configuration file prometheus.yml (to be created separately).
- Stores data in prometheus_data volume.
- Node Exporter
- Runs on port 9100.
- Collects system metrics (CPU, memory, disk, network, etc.).
Setting Up Prometheus Configuration
Create a prometheus.yml file in the same directory as docker-compose.yml:
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['prometheus:9090']
- job_name: 'grafana'
static_configs:
- targets: ['grafana:3000']
- job_name: 'node-exporter'
static_configs:
- targets: ['node-exporter:9100']
Running the Setup
Navigate to the directory containing docker-compose.yml and run:
docker-compose up -d
Accessing the Services
Adding Prometheus as a Data Source in Grafana
- Open Grafana at http://localhost:3000/.
- Log in with admin / admin.
- Go to Configuration > Data Sources.
- Click Add data source and choose Prometheus.
- Set http://prometheus:9090 as the URL
- Click Save & Test.