Prometheus + Grafana
Industry-standard monitoring stack with Prometheus metrics collection and Grafana visualization dashboards.
Overview
Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud in 2012, designed around a pull-based architecture that scrapes metrics from configured targets at given intervals. Unlike traditional push-based monitoring systems, Prometheus actively discovers and pulls metrics from services, storing them as time-series data with powerful labeling capabilities and querying them through PromQL (Prometheus Query Language). This approach makes it exceptionally well-suited for dynamic environments like Kubernetes clusters and microservices architectures.
This monitoring stack combines Prometheus's robust metric collection and storage capabilities with Grafana's industry-leading visualization platform to create a comprehensive observability solution. Prometheus handles the heavy lifting of metric ingestion, storage, and alerting logic, while Grafana transforms that raw time-series data into meaningful dashboards, graphs, and visual analytics. The integration between these tools is particularly tight, with Grafana natively supporting PromQL queries and Prometheus providing the dimensional data model that Grafana excels at visualizing.
DevOps teams, SRE professionals, and infrastructure engineers gravitate toward this combination because it offers enterprise-grade monitoring capabilities without vendor lock-in or licensing costs. The stack excels in cloud-native environments where traditional monitoring solutions struggle with ephemeral infrastructure and rapid deployment cycles. Organizations choosing this setup gain deep visibility into application performance, infrastructure health, and business metrics through a single pane of glass, while maintaining full control over their monitoring data and retention policies.
Key Features
- Pull-based metrics collection with automatic service discovery for Kubernetes, Docker, and DNS
- PromQL query language for complex time-series analysis and aggregation across multiple dimensions
- Multi-dimensional data model using labels for flexible metric organization and filtering
- Grafana's 50+ data source integrations beyond Prometheus including InfluxDB, Elasticsearch, and cloud providers
- Rich visualization library with graphs, heatmaps, stat panels, and geographical maps
- Built-in alerting with Prometheus Alertmanager and Grafana's notification channels
- Dashboard templating with variables for dynamic, reusable monitoring views
- 15-day metric retention configured with TSDB storage optimization
Common Use Cases
- 1Kubernetes cluster monitoring with pod, node, and application-level metrics visibility
- 2Microservices observability tracking request rates, error rates, and latency across service boundaries
- 3Infrastructure monitoring for servers, databases, and network equipment using various exporters
- 4Application performance monitoring with custom business metrics and SLI/SLO tracking
- 5DevOps pipeline monitoring including build times, deployment frequency, and failure rates
- 6IoT and sensor data visualization for time-series environmental or industrial monitoring
- 7Cost optimization dashboards tracking cloud resource usage and spending patterns
Prerequisites
- Minimum 1.5GB RAM total (1GB for Prometheus, 512MB for Grafana) for basic monitoring workloads
- Docker and Docker Compose installed with sufficient storage for time-series data retention
- Network access to target systems you want to monitor on their metrics endpoints
- Basic understanding of time-series data concepts and metric types (counters, gauges, histograms)
- Prometheus configuration file (prometheus.yml) with scrape targets defined for your environment
- GRAFANA_USER and GRAFANA_PASSWORD environment variables set for initial admin access
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 prometheus: 3 image: prom/prometheus:latest4 container_name: prometheus5 restart: unless-stopped6 command: 7 - '--config.file=/etc/prometheus/prometheus.yml'8 - '--storage.tsdb.path=/prometheus'9 - '--storage.tsdb.retention.time=15d'10 - '--web.enable-lifecycle'11 volumes: 12 - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro13 - prometheus_data:/prometheus14 ports: 15 - "9090:9090"16 networks: 17 - monitoring1819 grafana: 20 image: grafana/grafana:latest21 container_name: grafana22 restart: unless-stopped23 environment: 24 GF_SECURITY_ADMIN_USER: ${GRAFANA_USER}25 GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD}26 GF_INSTALL_PLUGINS: grafana-clock-panel,grafana-piechart-panel27 volumes: 28 - grafana_data:/var/lib/grafana29 ports: 30 - "3000:3000"31 depends_on: 32 - prometheus33 networks: 34 - monitoring3536volumes: 37 prometheus_data: 38 grafana_data: 3940networks: 41 monitoring: 42 driver: bridge.env Template
.env
1# Grafana Configuration2GRAFANA_USER=admin3GRAFANA_PASSWORD=changemeUsage Notes
- 1Docs: https://prometheus.io/docs/ and https://grafana.com/docs/
- 2Grafana at http://localhost:3000 (admin/GRAFANA_PASSWORD)
- 3Prometheus at http://localhost:9090 - query interface and target status
- 4Create prometheus/prometheus.yml with scrape_configs for your services
- 5Add Prometheus data source in Grafana: http://prometheus:9090
- 6Import dashboards from https://grafana.com/grafana/dashboards/
Individual Services(2 services)
Copy individual services to mix and match with your existing compose files.
prometheus
prometheus:
image: prom/prometheus:latest
container_name: prometheus
restart: unless-stopped
command:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--storage.tsdb.retention.time=15d"
- "--web.enable-lifecycle"
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
ports:
- "9090:9090"
networks:
- monitoring
grafana
grafana:
image: grafana/grafana:latest
container_name: grafana
restart: unless-stopped
environment:
GF_SECURITY_ADMIN_USER: ${GRAFANA_USER}
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD}
GF_INSTALL_PLUGINS: grafana-clock-panel,grafana-piechart-panel
volumes:
- grafana_data:/var/lib/grafana
ports:
- "3000:3000"
depends_on:
- prometheus
networks:
- monitoring
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 prometheus:5 image: prom/prometheus:latest6 container_name: prometheus7 restart: unless-stopped8 command:9 - '--config.file=/etc/prometheus/prometheus.yml'10 - '--storage.tsdb.path=/prometheus'11 - '--storage.tsdb.retention.time=15d'12 - '--web.enable-lifecycle'13 volumes:14 - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro15 - prometheus_data:/prometheus16 ports:17 - "9090:9090"18 networks:19 - monitoring2021 grafana:22 image: grafana/grafana:latest23 container_name: grafana24 restart: unless-stopped25 environment:26 GF_SECURITY_ADMIN_USER: ${GRAFANA_USER}27 GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD}28 GF_INSTALL_PLUGINS: grafana-clock-panel,grafana-piechart-panel29 volumes:30 - grafana_data:/var/lib/grafana31 ports:32 - "3000:3000"33 depends_on:34 - prometheus35 networks:36 - monitoring3738volumes:39 prometheus_data:40 grafana_data:4142networks:43 monitoring:44 driver: bridge45EOF4647# 2. Create the .env file48cat > .env << 'EOF'49# Grafana Configuration50GRAFANA_USER=admin51GRAFANA_PASSWORD=changeme52EOF5354# 3. Start the services55docker compose up -d5657# 4. View logs58docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/prometheus-grafana/run | bashTroubleshooting
- Prometheus targets showing as 'DOWN': Verify network connectivity and that target applications expose metrics on configured ports
- Grafana shows 'No data points' error: Check Prometheus data source configuration uses http://prometheus:9090 URL within Docker network
- High memory usage in Prometheus: Reduce metric retention time or increase scrape intervals in prometheus.yml configuration
- PromQL queries timing out: Optimize query complexity, reduce time ranges, or increase Prometheus query timeout settings
- Grafana dashboards not persisting: Ensure grafana_data volume is properly mounted and container has write permissions
- Missing metrics from exporters: Verify exporter compatibility with Prometheus version and check scrape_configs job names match targets
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Components
prometheusgrafana
Tags
#metrics#monitoring#visualization#alerting#observability
Category
Monitoring & ObservabilityAd Space
Shortcuts: C CopyF FavoriteD Download