Grafana — Monitoring Dashboards
Grafana is the standard open-source platform for building time-series monitoring dashboards. It connects to data sources — Prometheus for metrics, Loki for logs, InfluxDB for IoT and infrastructure, MySQL/PostgreSQL for application data, CloudWatch for AWS — and turns them into visual dashboards with graphs, gauges, and alerts. It's commonly used for infrastructure monitoring, application performance, home server dashboards (Pi-hole, Home Assistant stats), and business metrics.
Grafana's web interface runs on port 3000 by default. Default login is admin / admin — Grafana immediately prompts you to change this on first login.
/etc/grafana/grafana.iniInstall Grafana
# Docker (quickest)
docker run -d \
--name grafana \
-p 3000:3000 \
-v grafana_data:/var/lib/grafana \
--restart unless-stopped \
grafana/grafana-oss:latest
# Ubuntu
sudo apt install -y software-properties-common
wget -q -O - https://apt.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt update && sudo apt install grafana
sudo systemctl start grafana-server
# macOS
brew install grafana
brew services start grafana
Prometheus + Grafana (Most Common Setup)
Prometheus scrapes metrics from exporters (node_exporter for Linux system stats, cAdvisor for Docker, application-specific exporters) and stores them as time-series data. Grafana visualizes Prometheus data. The full stack as Docker Compose:
services:
prometheus:
image: prom/prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prom_data:/prometheus
node-exporter:
image: prom/node-exporter
ports:
- "9100:9100"
grafana:
image: grafana/grafana-oss
ports:
- "3000:3000"
volumes:
- grafana_data:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_PASSWORD=yourpassword
volumes:
prom_data:
grafana_data:
# prometheus.yml — tell Prometheus what to scrape
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'node'
static_configs:
- targets: ['node-exporter:9100']
Adding a Data Source
- Log in at localhost:3000
- Go to Connections → Data sources → Add new data source
- Select your data source type (Prometheus, MySQL, InfluxDB, etc.)
- Enter connection details (URL, credentials)
- Click Save & test — green means connected
Pre-Built Dashboards
Grafana's dashboard library at grafana.com/grafana/dashboards has thousands of pre-built dashboards. Import one by ID:
- Go to Dashboards → Import
- Enter a dashboard ID (popular: 1860 for Node Exporter Full, 893 for Docker, 11835 for Home Assistant)
- Select your Prometheus data source
- Click Import
Alerts
Grafana alerts fire when a metric crosses a threshold. Configure in Alerting → Alert rules → New alert rule. Set conditions (e.g., CPU > 90% for 5 minutes), then configure Contact points (Slack, email, PagerDuty, webhook) in Alerting → Contact points.
Troubleshooting
| Problem | Fix |
|---|---|
| localhost:3000 conflict with Node.js app | Change Grafana to another port: set http_port = 3001 in grafana.ini, or use Docker -p 3001:3000 |
| Data source test fails | In Docker, use the service name (prometheus), not localhost, as the host in Grafana's data source URL |
| Dashboards show "No data" | Check the time range (top right) — default may be "Last 6 hours" but your data is older |
| Forgot admin password | grafana-cli admin reset-admin-password newpassword |
| Permission denied on volume | Grafana container runs as UID 472 — sudo chown -R 472:472 grafana_data/ |