Linuxmonitoring

Add a Prometheus Data Source to Grafana + Import a Dashboard

Provision a Prometheus data source and the Node Exporter Full dashboard (ID 1860) as config files, so a fresh Grafana comes up already showing metrics.

Shellbash
Updated
Script
bash
# ── Wire a Prometheus data source into Grafana and import the Node Exporter
# ── Full dashboard (ID 1860) as code, so a fresh Grafana starts up showing data.
# ── Concept walkthrough: /blog/what-is-grafana/
# ── Run on the Grafana host (Debian/RPM package install). Needs sudo.

# 1. Provision the Prometheus data source (declarative — survives restarts)
sudo tee /etc/grafana/provisioning/datasources/prometheus.yaml >/dev/null <<'EOF'
apiVersion: 1
datasources:
  - name: Prometheus
    uid: prometheus
    type: prometheus
    access: proxy
    url: http://localhost:9090   # change if Prometheus runs on another host
    isDefault: true
    editable: false
EOF

# 2. Register a file-based dashboard provider
sudo mkdir -p /var/lib/grafana/dashboards
sudo tee /etc/grafana/provisioning/dashboards/homelab.yaml >/dev/null <<'EOF'
apiVersion: 1
providers:
  - name: homelab
    orgId: 1
    type: file
    disableDeletion: false
    updateIntervalSeconds: 30
    allowUiUpdates: true
    options:
      path: /var/lib/grafana/dashboards
      foldersFromFilesStructure: false
EOF

# 3. Download dashboard 1860 and hard-bind every panel to the data source above.
#    The download references a ${ds_prometheus} datasource variable; rewriting it
#    to the fixed uid 'prometheus' is what stops every panel reading "No data".
curl -sSL https://grafana.com/api/dashboards/1860/revisions/latest/download \
  | sed 's/${ds_prometheus}/prometheus/g' \
  | sudo tee /var/lib/grafana/dashboards/node-exporter-full.json >/dev/null

# 4. Load the provisioning files
sudo systemctl restart grafana-server

# 5. Confirm Grafana is healthy (unauthenticated endpoint)
curl -s http://localhost:3000/api/health

What this does

Provisions a Prometheus data source and the Node Exporter Full dashboard (ID 1860) as configuration files that Grafana reads on startup. A freshly installed Grafana comes up already connected to Prometheus and showing a full system dashboard — no clicking through the import wizard, and it all survives a restart. This is the copy-paste companion to What Is Grafana?.

Prerequisites

  • Grafana installed from the Debian/RPM package, so the config lives in /etc/grafana and dashboards in /var/lib/grafana (for the Docker image, see Notes)
  • A running Prometheus already scraping node_exporter on the hosts you want to see
  • Root / sudo on the Grafana host

Notes

  • Make these values your own before you run this. The only machine-specific value is the Prometheus URL: http://localhost:9090 assumes Prometheus runs on the same host as Grafana. If it runs elsewhere, change it to http://YOUR_PROM_HOST:9090. Everything else — the data source uid: prometheus, the file paths — can stay as written. Rule of thumb: if a value looks specific to one machine, it’s a placeholder to change, not a literal to copy.
  • Why the sed line matters. Dashboard 1860 ships with a datasource variable (${ds_prometheus}) rather than a hard-coded source. Rewriting it to the fixed uid: prometheus binds all 127 panels to the data source from step 1. Skip this and the dashboard imports bound to nothing and every panel reads “No data”.
  • “No data” after a clean import almost always means Prometheus isn’t scraping node_exporter yet — check your Prometheus Status → Targets page first. Grafana only ever draws what Prometheus already holds.
  • Docker install: the paths differ. Mount the two YAML files under /etc/grafana/provisioning/ and the JSON under /var/lib/grafana/dashboards/ inside the container, then recreate it instead of systemctl restart.
  • Any dashboard, same steps. Swap 1860 for another dashboard ID to import it the same way; the ${ds_prometheus} rewrite is standard for community dashboards that expose a datasource variable.
  • The reasoning behind data sources, dashboards, and panels: What Is Grafana?. To build the Prometheus + exporters side first, see Node Exporter + pve-exporter.