#!/bin/sh # Install Prometheus node_exporter on an exe.dev VM (Ubuntu) as a systemd # service on port 9100, so a Grafana VM can read this VM's CPU, memory, # disk, network and systemd metrics. https://exe.dev/deploy/grafana # Port 9100 is private: through exe.dev's HTTPS proxy only you, people you # share the VM with, and your VM-to-VM integrations can reach it. set -eu VERSION="${NODE_EXPORTER_VERSION:-1.12.1}" ARCH="$(dpkg --print-architecture)" NAME="node_exporter-$VERSION.linux-$ARCH" URL="https://github.com/prometheus/node_exporter/releases/download/v$VERSION" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT cd "$tmp" curl -fsSLO "$URL/$NAME.tar.gz" curl -fsSL "$URL/sha256sums.txt" | grep " $NAME.tar.gz\$" | sha256sum -c - tar -xzf "$NAME.tar.gz" sudo install -m 755 "$NAME/node_exporter" /usr/local/bin/node_exporter grep -q "^node_exporter:" /etc/passwd || sudo useradd --system --no-create-home --shell /usr/sbin/nologin node_exporter sudo tee /etc/systemd/system/node_exporter.service >/dev/null <<'UNIT' [Unit] Description=Prometheus node_exporter Wants=network-online.target After=network-online.target [Service] User=node_exporter ExecStart=/usr/local/bin/node_exporter --web.listen-address=:9100 --collector.systemd Restart=on-failure [Install] WantedBy=multi-user.target UNIT sudo systemctl daemon-reload sudo systemctl enable node_exporter >/dev/null 2>&1 sudo systemctl restart node_exporter for i in 1 2 3 4 5 6 7 8 9 10; do if curl -fsS http://localhost:9100/metrics >/dev/null 2>&1; then break; fi sleep 1 done curl -fsS http://localhost:9100/metrics | grep '^node_exporter_build_info' echo "node_exporter $VERSION is running on $(hostname):9100"