bashadvanced

Prometheus Monitoring Setup

Docker Compose setup for Prometheus with Grafana, node exporter, and alerting rules.

bash
# docker-compose.monitoring.yml
version: '3.8'

services:
  prometheus:
    image: prom/prometheus:latest
    ports:
      - '9090:9090'
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - ./alerts.yml:/etc/prometheus/alerts.yml:ro
      - prometheus-data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.retention.time=30d'
    restart: unless-stopped

  grafana:
    image: grafana/grafana:latest
    ports:
      - '3001:3000'
    environment:
      GF_SECURITY_ADMIN_PASSWORD: admin
    volumes:
      - grafana-data:/var/lib/grafana
    depends_on:
      - prometheus
    restart: unless-stopped

  node-exporter:
    image: prom/node-exporter:latest
    ports:
      - '9100:9100'
    restart: unless-stopped

volumes:
  prometheus-data:
  grafana-data:

# prometheus.yml
# global:
#   scrape_interval: 15s
# rule_files:
#   - alerts.yml
# scrape_configs:
#   - job_name: 'node'
#     static_configs:
#       - targets: ['node-exporter:9100']
#   - job_name: 'app'
#     static_configs:
#       - targets: ['host.docker.internal:3000']

Use Cases

  • Infrastructure monitoring with metrics collection
  • Setting up dashboards for application observability
  • Alerting on system performance thresholds

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.