Monitoring your Linux VPS is essential to track system performance and prevent potential issues. In this guide, you'll learn how to set up monitoring using Node Exporter, Prometheus, and Grafana Cloud.
1. Install and Configure Node Exporter
Node Exporter collects system metrics from the Linux VPS.
Step 1: Download Node Exporter
wget https://github.com/prometheus/node_exporter/releases/download/v1.9.0/node_exporter-1.9.0.linux-amd64.tar.gz
Step 2: Extract and Move the Binary
tar -xvf node_exporter-1.9.0.linux-amd64.tar.gz sudo mv node_exporter-1.9.0.linux-amd64/node_exporter /usr/local/bin/
Step 3: Create a System User
sudo useradd --system --no-create-home --shell /bin/false node_exporter
Step 4: Set Up Node Exporter as a Service
Create the service file:
sudo vim /etc/systemd/system/node_exporter.service
Add the following content:
[Unit] Description=Node Exporter After=network.target Wants=network-online.target [Service] User=node_exporter Group=node_exporter Type=simple ExecStart=/usr/local/bin/node_exporter # Securtiy Settings ProtectHome=true NoNewPrivileges=true ProtectSystem=strict PrivateTmp=true PrivateDevices=true ProtectKernelTunables=true ProtectKernelModules=true ProtectControlGroups=true RestrictNamespaces=true RestrictRealtime=true RestrictSUIDSGID=true # Resources LimitNPROC=8192 LimitNOFILE=65535 LimitCORE=infinity # Restart Restart=always RestartSec=5 [Install] WantedBy=multi-user.target
Step 5: Start and Enable Node Exporter
sudo systemctl daemon-reload sudo systemctl start node_exporter sudo systemctl enable node_exporter
Step 6: Verify Node Exporter
ss -aplnt | grep 9100 curl http://localhost:9100/metrics
2. Install and Configure Prometheus
Prometheus scrapes metrics from Node Exporter.
Step 1: Download Prometheus
wget https://github.com/prometheus/prometheus/releases/download/v3.2.0/prometheus-3.2.0.linux-amd64.tar.gz
Step 2: Extract and Move Files
tar -xvf prometheus-3.2.0.linux-amd64.tar.gz sudo mv prometheus-3.2.0.linux-amd64/prometheus /usr/local/bin/ sudo mv prometheus-3.2.0.linux-amd64/promtool /usr/local/bin/ sudo mkdir -p /etc/prometheus /var/lib/prometheus/data /var/lib/prometheus/query_log sudo mv prometheus-3.2.0.linux-amd64/prometheus.yml /etc/prometheus/
Step 3: Edit the Configuration File
sudo vim /etc/prometheus/prometheus.yml
Add:
scrape_configs: - job_name: 'node' static_configs: - targets: ['localhost:9100', 'localhost:9090'] scrape_interval: 15s scrape_timeout: 5s
Verify the config:
promtool check config /etc/prometheus/prometheus.yml
Step 4: Set Up Prometheus as a Service
sudo useradd -rs /bin/false prometheus
sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus /usr/local/bin/prometheus /usr/local/bin/promtool sudo chmod -R 755 /var/lib/prometheus
Create the service file:
sudo vim /etc/systemd/system/prometheus.service
Add:
[Unit] Description=Prometheus Monitoring System Documentation=https://prometheus.io/docs/prometheus/latest/installation/ After=network-online.target Wants=network-online.target [Service] Type=simple User=prometheus Group=prometheus WorkingDirectory=/var/lib/prometheus ExecStart=/usr/local/bin/prometheus \ --config.file=/etc/prometheus/prometheus.yml \ --storage.tsdb.path=/var/lib/prometheus/data \ --web.console.templates=/etc/prometheus/consoles \ --web.console.libraries=/etc/prometheus/console_libraries \ --query.lookback-delta=5m \ --enable-feature=memory-snapshot-on-shutdown # Security Settings ProtectHome=true NoNewPrivileges=true ProtectSystem=false PrivateTmp=true PrivateDevices=true ProtectKernelTunables=true ProtectKernelModules=true ProtectControlGroups=true RestrictNamespaces=true RestrictRealtime=true RestrictSUIDSGID=true # Resource Limits LimitNOFILE=65535 LimitNPROC=4096 LimitCORE=infinity # Restart Configuration Restart=always RestartSec=5 [Install] WantedBy=multi-user.target
Step 5: Start and Enable Prometheus
sudo systemctl daemon-reload sudo systemctl start prometheus sudo systemctl enable prometheus
Step 6: Verify Prometheus
ss -aplnt | grep 9090 curl localhost:9090/metrics
3. Set Up Grafana Cloud Dashboard
Grafana visualizes metrics collected by Prometheus.
Step 1: Sign Up for Grafana Cloud
- Create an account on Grafana Cloud.
- Obtain your Prometheus remote write URL and API key.
Step 2: Configure Prometheus for Remote Write
Edit /etc/prometheus/prometheus.yml
:
remote_write: - url: "https://prometheus-blocks-prod-us-central1.grafana.net/api/v1/write" basic_auth: username: "<your-grafana-cloud-instance-id>" password: "<your-api-key>"
Step 3: Restart Prometheus
sudo systemctl restart prometheus
Step 4: Import Dashboards in Grafana Cloud
- Log in to Grafana Cloud.
- Add Prometheus as a data source.
- Import this pre-built Node Exporter dashboard.
4. Verify Setup
- Access Grafana Cloud at
https://<your-grafana-instance>.grafana.net
. - View metrics such as CPU usage, memory consumption, and disk I/O in real-time.
References
- Installing Prometheus and Node Exporter
- Step-by-step guide for Prometheus and Grafana
- Configuring Prometheus Remote Write
- How to Monitor Linux Servers with Prometheus
- Official Prometheus Documentation
Now, your Linux VPS is fully monitored with Node Exporter, Prometheus, and Grafana Cloud. 🎉 Let me know in the comments if you have any questions! 🚀
Top comments (0)