Configuration
Prometheus configuration
The Prometheus config file is at /etc/prometheus/prometheus.yml. It is pre-configured to scrape Node Exporter on localhost.
To add additional scrape targets, edit this file:
# /etc/prometheus/prometheus.yml
scrape_configs:
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']
# Add your own targets:
- job_name: 'my-app'
static_configs:
- targets: ['app-server-ip:8080']
After editing, reload Prometheus:
sudo systemctl reload prometheus
# or
curl -X POST http://localhost:9090/-/reload
Adding Grafana dashboards
- Log in to Grafana at
http://<ec2-ip>:3000 - Go to Dashboards → Import
- Enter a dashboard ID from grafana.com/grafana/dashboards
Popular dashboards:
- 1860 — Node Exporter Full
- 11074 — Node Exporter for Prometheus Dashboard
- 3662 — Prometheus 2.0 Stats
Grafana data source
Grafana is pre-configured with a Prometheus data source pointing to http://localhost:9090. You can verify or modify this at Configuration → Data Sources → Prometheus.
Alerting
To set up alerting rules in Prometheus, create rule files and reference them in prometheus.yml:
rule_files:
- /etc/prometheus/rules/*.yml
Example alert rule:
# /etc/prometheus/rules/node-alerts.yml
groups:
- name: node
rules:
- alert: HighCPU
expr: 100 - (avg by(instance)(rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
for: 5m
labels:
severity: warning
annotations:
summary: "High CPU usage on {{ $labels.instance }}"