A comprehensive guide for setting up Prometheus and Node Exporter on a VPS, then connecting to Grafana locally for system monitoring and visualization.
Keep your system packages up to date for security and compatibility.
sudo apt update && sudo apt upgrade -yCreate a dedicated system user for Prometheus with no login capabilities for security purposes.
sudo useradd --no-create-home --shell /bin/false prometheusSet up the configuration and data storage directories for Prometheus.
sudo mkdir /etc/prometheus /var/lib/prometheusGrant the Prometheus user ownership of its directories.
sudo chown prometheus:prometheus /var/lib/prometheus /etc/prometheusNavigate to the temporary directory and download the latest Prometheus release. Check prometheus.io for the most recent version.
cd /tmp
wget https://github.com/prometheus/prometheus/releases/download/v2.53.0/prometheus-2.53.0.linux-amd64.tar.gzUnpack the downloaded tarball.
tar xvfz prometheus-2.53.0.linux-amd64.tar.gzMove into the newly extracted Prometheus directory.
cd prometheus-2.53.0.linux-amd64Install Prometheus binaries to the system-wide binary directory.
sudo cp prometheus /usr/local/bin/
sudo cp promtool /usr/local/bin/Ensure the Prometheus user owns the binaries.
sudo chown prometheus:prometheus /usr/local/bin/prometheus /usr/local/bin/promtoolSet up the default configuration and console files.
sudo cp -r consoles /etc/prometheus
sudo cp -r console_libraries /etc/prometheus
sudo cp prometheus.yml /etc/prometheus/Edit the configuration file to customize your monitoring setup. The default configuration is a good starting point.
sudo nvim /etc/prometheus/prometheus.ymlExample basic configuration:
global:
scrape_interval: 15s
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]Grant the Prometheus user ownership of the configuration file.
sudo chown prometheus:prometheus /etc/prometheus/prometheus.ymlSet up Prometheus as a systemd service for automatic startup and easy management.
sudo nvim /etc/systemd/system/prometheus.serviceService file contents:
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.targetReload systemd, start the service, and enable it to run on boot.
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheusCheck the service status to ensure everything started correctly.
sudo systemctl status prometheusIf you see errors, check the logs with:
sudo journalctl -u prometheus -fPrometheus should now be accessible via your web browser at:
http://YOUR_VPS_IP:9090
Node Exporter collects hardware and OS metrics from your VPS, making them available to Prometheus.
Create a dedicated system user for Node Exporter.
sudo useradd --no-create-home --shell /bin/false node_exporterNavigate to the temp directory and download the latest release. Check the Node Exporter releases for the newest version.
cd /tmp
wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gzUnpack the downloaded tarball.
tar xvfz node_exporter-1.8.2.linux-amd64.tar.gzMove into the Node Exporter directory.
cd node_exporter-1.8.2.linux-amd64Install the Node Exporter binary.
sudo cp node_exporter /usr/local/bin/Grant ownership to the node_exporter user.
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporterSet up Node Exporter as a systemd service.
sudo nvim /etc/systemd/system/node_exporter.serviceService file contents:
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.targetReload systemd, start the service, and enable it for automatic startup.
sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl enable node_exporterCheck the service status.
sudo systemctl status node_exporterNode Exporter should now be running on port 9100.
Add Node Exporter as a scrape target so Prometheus can collect system metrics.
sudo nvim /etc/prometheus/prometheus.ymlAdd this job to your scrape_configs section:
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "node"
static_configs:
- targets: ["localhost:9100"]
labels:
app: "node_exporter"Apply the configuration changes.
sudo systemctl restart prometheusVisit the Prometheus web UI at http://YOUR_VPS_IP:9090, navigate to Status > Targets, and confirm that both the prometheus and node jobs show as "UP".
Use Homebrew to install Grafana on your local machine.
brew install grafanaThe standard brew services start grafana command may not properly find the config file. This alias ensures Grafana starts with the correct paths.
alias grafanaGo="grafana server --config /opt/homebrew/etc/grafana/grafana.ini --homepath /opt/homebrew/opt/grafana/share/grafana web"Make the alias permanent by adding it to your shell configuration file.
echo 'alias grafanaGo="grafana server --config /opt/homebrew/etc/grafana/grafana.ini --homepath /opt/homebrew/opt/grafana/share/grafana web"' >> ~/.zshrcApply the changes to your current session.
source ~/.zshrcLaunch Grafana using the alias.
grafanaGoGrafana will start on port 3000 by default. Access it at:
http://localhost:3000
Default credentials:
- Username:
admin - Password:
admin
You'll be prompted to change the password on first login.
Custom credentials:
- Set the username and password flags in grafana.ini file
Proxy the Prometheus port from your VPS to your local machine using an SSH tunnel. This allows Grafana to access Prometheus securely without exposing it to the internet.
Replace lightsail2to6x with your VPS hostname or IP address (you can set up an SSH alias in ~/.ssh/config).
ssh -L 9090:localhost:9090 lightsail2to6xThis keeps the tunnel open. Run this in a separate terminal window or use -f to background it.
Alternative with key:
ssh -L 9090:localhost:9090 -i ~/.ssh/your_key user@YOUR_VPS_IPOpen your browser and navigate to:
http://localhost:3000
Log in with the default credentials (admin/admin) or the password you set.
- Navigate to Connections > Data sources in the left sidebar
- Click Add data source
- Select Prometheus
- In the configuration page:
- Name: Prometheus (or any name you prefer)
- URL:
http://localhost:9090(the proxied VPS Prometheus)
- Scroll down and click Save & Test
You should see a green success message confirming the connection.
Grafana has a rich library of community dashboards. We'll use a popular Node Exporter dashboard.
- Navigate to Dashboards in the left sidebar
- Click Import
- Enter dashboard ID: 1860
- Click Load
- Configure the import:
- Name: Node Exporter Full (or customize)
- Folder: Select or create a folder
- Prometheus: Select your Prometheus data source
- UID: Change if necessary (optional)
- Click Import
You should now see a comprehensive dashboard displaying all your VPS system metrics including CPU, memory, disk, network, and more.
You can also visit:
http://localhost:3000/dashboard/import
Then follow the same steps above.
Check the service status and logs:
sudo systemctl status prometheus
sudo journalctl -u prometheus -fCommon issues:
- Configuration syntax errors in
prometheus.yml - Port 9090 already in use
- Permission issues with
/var/lib/prometheus
Check the service status and logs:
sudo systemctl status node_exporter
sudo journalctl -u node_exporter -fCommon issues:
- Port 9100 already in use
- Binary permissions not set correctly
- Ensure the SSH tunnel is active
- Verify Prometheus is running on the VPS:
http://YOUR_VPS_IP:9090 - Check that the data source URL is
http://localhost:9090(not the VPS IP) - Verify your firewall allows port 9090 on the VPS
- Confirm Node Exporter is running:
sudo systemctl status node_exporter - Check Prometheus targets are UP:
http://localhost:9090/targets - Verify the time range in Grafana matches when data collection started
- Ensure the correct Prometheus data source is selected in the dashboard
Happy Monitoring! 📊