Tools: Server Monitoring with Prometheus and Grafana on VPS - 2025 Update

Tools: Server Monitoring with Prometheus and Grafana on VPS - 2025 Update

Why Monitor Your VPS?

Understanding the Tools: Prometheus and Grafana

The Relationship: Prometheus Feeds Grafana

Setting Up Prometheus on Your VPS

Step 1: Download Prometheus

Step 2: Install Prometheus Binaries

Step 3: Configure Prometheus (prometheus.yml)

Step 4: Install Node Exporter

Step 5: Configure Prometheus to Scrape Node Exporter

Step 6: Create a Systemd Service for Prometheus

Setting Up Grafana on Your VPS

Step 1: Install Grafana

Step 2: Start and Enable Grafana Service

Step 4: Import a Pre-built Dashboard

What to Monitor and Why

Advanced Considerations

Conclusion

Disclosure Are you tired of your Virtual Private Server (VPS) performance dropping without warning? Understanding your server's health is crucial for smooth operations, and this article will guide you through setting up server monitoring with Prometheus and Grafana on your VPS. We'll cover installing these powerful tools and configuring them to give you actionable insights into your server's performance. Imagine driving a car without a dashboard. You wouldn't know your speed, fuel level, or if the engine is overheating. Server monitoring provides that essential dashboard for your VPS. Without it, you're flying blind, risking sudden performance degradation, downtime, and unhappy users. Proactive monitoring allows you to identify and address potential issues before they escalate into critical problems. Before we dive into the setup, let's quickly define our key players. Prometheus is an open-source systems monitoring and alerting toolkit. Think of it as a highly efficient data collector. It scrapes (fetches) metrics from configured targets (your server and applications) at given intervals and stores them as time-series data. This data is essentially a series of measurements taken over time, like CPU usage every minute. Grafana is an open-source analytics and interactive visualization web application. It's the dashboard builder. Grafana connects to data sources like Prometheus and allows you to create beautiful, informative dashboards to visualize the metrics Prometheus collects. It turns raw data into easy-to-understand graphs and charts. Prometheus gathers the raw performance data, and Grafana presents it in a human-readable format. This combination is a standard, powerful setup for monitoring applications and infrastructure. We'll start by installing Prometheus on your VPS. This process typically involves downloading the binary and configuring it. For this guide, we'll assume you're using a Linux-based VPS. Many providers offer excellent Linux VPS options, such as PowerVPS and Immers Cloud, which provide a solid foundation for running monitoring tools. First, SSH into your VPS. You'll want to download the latest stable release of Prometheus. You can find the download links on the official Prometheus website. After extracting, you'll have a directory with Prometheus binaries and configuration files. It's good practice to move these to a dedicated location and create a dedicated user for Prometheus. The prometheus.yml file is Prometheus's main configuration file. It tells Prometheus where to find targets to scrape and how often. For basic server monitoring, we need to configure Prometheus to scrape itself and the Node Exporter. Node Exporter is a Prometheus exporter that exposes hardware and OS metrics. You'll need to install this separately. First, let's configure Prometheus to scrape itself. Edit /etc/prometheus/prometheus.yml: Now, let's install Node Exporter. The process is very similar to installing Prometheus. Now, update your /etc/prometheus/prometheus.yml to include Node Exporter as a target. To ensure Prometheus starts automatically and runs in the background, we'll create a systemd service file. Paste the following content into the file: Now, enable and start the Prometheus service: You should now be able to access the Prometheus web UI at http://your_vps_ip:9090. You can verify that Prometheus is scraping Node Exporter by going to "Status" -> "Targets". With Prometheus collecting data, it's time to visualize it with Grafana. Grafana provides official packages for Debian/Ubuntu and RHEL/CentOS. For Debian/Ubuntu: Similar to Prometheus, we'll create a systemd service for Grafana. Grafana typically runs on port 3000. You should be able to access it at http://your_vps_ip:3000. The default login is admin with the password admin. You'll be prompted to change this immediately. While you can create custom dashboards, importing pre-built ones is a great way to get started quickly. A popular choice for Node Exporter is the "Node Exporter Full" dashboard. You should now see a comprehensive dashboard showing CPU usage, memory, disk I/O, network traffic, and more for your VPS. Now that you have your monitoring setup, what should you actually be looking at? Setting up server monitoring with Prometheus and Grafana on your VPS provides invaluable insight into your server's health and performance. By understanding metrics like CPU, memory, and disk I/O, you can proactively address issues, optimize performance, and prevent unexpected downtime. This powerful combination empowers you to manage your infrastructure with confidence. This article contains affiliate links for PowerVPS and Im Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse

Command

Copy

# Navigate to a temporary directory cd /tmp # Download the latest Prometheus release (replace with the actual latest version) -weight: 500;">wget https://github.com/prometheus/prometheus/releases/download/v2.48.0/prometheus-2.48.0.linux-amd64.tar.gz # Extract the downloaded archive tar xvfz prometheus-*.linux-amd64.tar.gz # Navigate to a temporary directory cd /tmp # Download the latest Prometheus release (replace with the actual latest version) -weight: 500;">wget https://github.com/prometheus/prometheus/releases/download/v2.48.0/prometheus-2.48.0.linux-amd64.tar.gz # Extract the downloaded archive tar xvfz prometheus-*.linux-amd64.tar.gz # Navigate to a temporary directory cd /tmp # Download the latest Prometheus release (replace with the actual latest version) -weight: 500;">wget https://github.com/prometheus/prometheus/releases/download/v2.48.0/prometheus-2.48.0.linux-amd64.tar.gz # Extract the downloaded archive tar xvfz prometheus-*.linux-amd64.tar.gz # Move the binaries to a system-wide location -weight: 600;">sudo mv prometheus-*.linux-amd64/prometheus /usr/local/bin/ -weight: 600;">sudo mv prometheus-*.linux-amd64/promtool /usr/local/bin/ # Create a Prometheus user and group -weight: 600;">sudo groupadd --system prometheus -weight: 600;">sudo useradd --system --no-create-home --shell /bin/false prometheus # Create directories for Prometheus data and configuration -weight: 600;">sudo mkdir /etc/prometheus -weight: 600;">sudo mkdir /var/lib/prometheus # Move configuration files -weight: 600;">sudo mv prometheus-*.linux-amd64/consoles /etc/prometheus -weight: 600;">sudo mv prometheus-*.linux-amd64/console_libraries /etc/prometheus -weight: 600;">sudo mv prometheus-*.linux-amd64/prometheus.yml /etc/prometheus/ -weight: 600;">sudo mv prometheus-*.linux-amd64/notifier.yml /etc/prometheus/ # If you have notifier config # Set ownership for Prometheus directories -weight: 600;">sudo chown -R prometheus:prometheus /etc/prometheus -weight: 600;">sudo chown -R prometheus:prometheus /var/lib/prometheus # Move the binaries to a system-wide location -weight: 600;">sudo mv prometheus-*.linux-amd64/prometheus /usr/local/bin/ -weight: 600;">sudo mv prometheus-*.linux-amd64/promtool /usr/local/bin/ # Create a Prometheus user and group -weight: 600;">sudo groupadd --system prometheus -weight: 600;">sudo useradd --system --no-create-home --shell /bin/false prometheus # Create directories for Prometheus data and configuration -weight: 600;">sudo mkdir /etc/prometheus -weight: 600;">sudo mkdir /var/lib/prometheus # Move configuration files -weight: 600;">sudo mv prometheus-*.linux-amd64/consoles /etc/prometheus -weight: 600;">sudo mv prometheus-*.linux-amd64/console_libraries /etc/prometheus -weight: 600;">sudo mv prometheus-*.linux-amd64/prometheus.yml /etc/prometheus/ -weight: 600;">sudo mv prometheus-*.linux-amd64/notifier.yml /etc/prometheus/ # If you have notifier config # Set ownership for Prometheus directories -weight: 600;">sudo chown -R prometheus:prometheus /etc/prometheus -weight: 600;">sudo chown -R prometheus:prometheus /var/lib/prometheus # Move the binaries to a system-wide location -weight: 600;">sudo mv prometheus-*.linux-amd64/prometheus /usr/local/bin/ -weight: 600;">sudo mv prometheus-*.linux-amd64/promtool /usr/local/bin/ # Create a Prometheus user and group -weight: 600;">sudo groupadd --system prometheus -weight: 600;">sudo useradd --system --no-create-home --shell /bin/false prometheus # Create directories for Prometheus data and configuration -weight: 600;">sudo mkdir /etc/prometheus -weight: 600;">sudo mkdir /var/lib/prometheus # Move configuration files -weight: 600;">sudo mv prometheus-*.linux-amd64/consoles /etc/prometheus -weight: 600;">sudo mv prometheus-*.linux-amd64/console_libraries /etc/prometheus -weight: 600;">sudo mv prometheus-*.linux-amd64/prometheus.yml /etc/prometheus/ -weight: 600;">sudo mv prometheus-*.linux-amd64/notifier.yml /etc/prometheus/ # If you have notifier config # Set ownership for Prometheus directories -weight: 600;">sudo chown -R prometheus:prometheus /etc/prometheus -weight: 600;">sudo chown -R prometheus:prometheus /var/lib/prometheus # Global configuration global: scrape_interval: 15s # How often to scrape targets by default # Alerting rules # alerting: # alertmanagers: # - static_configs: # - targets: ['localhost:9093'] # Replace with your Alertmanager address if you have one # Load rules once and all a rule files rule_files: # - "first_rules.yml" # - "second_rules.yml" # Scrape configurations scrape_configs: # Scrape Prometheus itself - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] # Global configuration global: scrape_interval: 15s # How often to scrape targets by default # Alerting rules # alerting: # alertmanagers: # - static_configs: # - targets: ['localhost:9093'] # Replace with your Alertmanager address if you have one # Load rules once and all a rule files rule_files: # - "first_rules.yml" # - "second_rules.yml" # Scrape configurations scrape_configs: # Scrape Prometheus itself - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] # Global configuration global: scrape_interval: 15s # How often to scrape targets by default # Alerting rules # alerting: # alertmanagers: # - static_configs: # - targets: ['localhost:9093'] # Replace with your Alertmanager address if you have one # Load rules once and all a rule files rule_files: # - "first_rules.yml" # - "second_rules.yml" # Scrape configurations scrape_configs: # Scrape Prometheus itself - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] # Navigate to a temporary directory cd /tmp # Download the latest Node Exporter release (replace with the actual latest version) -weight: 500;">wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz # Extract the downloaded archive tar xvfz node_exporter-*.linux-amd64.tar.gz # Move the binary -weight: 600;">sudo mv node_exporter-*.linux-amd64/node_exporter /usr/local/bin/ # Create a user for Node Exporter -weight: 600;">sudo groupadd --system node_exporter -weight: 600;">sudo useradd --system --no-create-home --shell /bin/false node_exporter # Clean up rm -rf node_exporter-*.linux-amd64.tar.gz node_exporter-*.linux-amd64 # Navigate to a temporary directory cd /tmp # Download the latest Node Exporter release (replace with the actual latest version) -weight: 500;">wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz # Extract the downloaded archive tar xvfz node_exporter-*.linux-amd64.tar.gz # Move the binary -weight: 600;">sudo mv node_exporter-*.linux-amd64/node_exporter /usr/local/bin/ # Create a user for Node Exporter -weight: 600;">sudo groupadd --system node_exporter -weight: 600;">sudo useradd --system --no-create-home --shell /bin/false node_exporter # Clean up rm -rf node_exporter-*.linux-amd64.tar.gz node_exporter-*.linux-amd64 # Navigate to a temporary directory cd /tmp # Download the latest Node Exporter release (replace with the actual latest version) -weight: 500;">wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz # Extract the downloaded archive tar xvfz node_exporter-*.linux-amd64.tar.gz # Move the binary -weight: 600;">sudo mv node_exporter-*.linux-amd64/node_exporter /usr/local/bin/ # Create a user for Node Exporter -weight: 600;">sudo groupadd --system node_exporter -weight: 600;">sudo useradd --system --no-create-home --shell /bin/false node_exporter # Clean up rm -rf node_exporter-*.linux-amd64.tar.gz node_exporter-*.linux-amd64 # Global configuration global: scrape_interval: 15s scrape_configs: # Scrape Prometheus itself - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] # Scrape Node Exporter for OS and hardware metrics - job_name: 'node_exporter' static_configs: - targets: ['localhost:9100'] # Node Exporter's default port # Global configuration global: scrape_interval: 15s scrape_configs: # Scrape Prometheus itself - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] # Scrape Node Exporter for OS and hardware metrics - job_name: 'node_exporter' static_configs: - targets: ['localhost:9100'] # Node Exporter's default port # Global configuration global: scrape_interval: 15s scrape_configs: # Scrape Prometheus itself - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] # Scrape Node Exporter for OS and hardware metrics - job_name: 'node_exporter' static_configs: - targets: ['localhost:9100'] # Node Exporter's default port -weight: 600;">sudo nano /etc/systemd/system/prometheus.-weight: 500;">service -weight: 600;">sudo nano /etc/systemd/system/prometheus.-weight: 500;">service -weight: 600;">sudo nano /etc/systemd/system/prometheus.-weight: 500;">service [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.target [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.target [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.target -weight: 600;">sudo -weight: 500;">systemctl daemon-reload -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable prometheus -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start prometheus -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status prometheus # Check if it's running -weight: 600;">sudo -weight: 500;">systemctl daemon-reload -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable prometheus -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start prometheus -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status prometheus # Check if it's running -weight: 600;">sudo -weight: 500;">systemctl daemon-reload -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable prometheus -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start prometheus -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status prometheus # Check if it's running # Install dependencies -weight: 600;">sudo -weight: 500;">apt-get -weight: 500;">update -weight: 600;">sudo -weight: 500;">apt-get -weight: 500;">install -y -weight: 500;">apt-transport-https software-properties-common -weight: 500;">wget # Import GPG key -weight: 500;">wget -q -O - https://-weight: 500;">apt.grafana.com/gpg.key | -weight: 600;">sudo -weight: 500;">apt-key add - # Add Grafana repository echo "deb https://-weight: 500;">apt.grafana.com stable main" | -weight: 600;">sudo tee /etc/-weight: 500;">apt/sources.list.d/grafana.list # Install Grafana -weight: 600;">sudo -weight: 500;">apt-get -weight: 500;">update -weight: 600;">sudo -weight: 500;">apt-get -weight: 500;">install grafana # Install dependencies -weight: 600;">sudo -weight: 500;">apt-get -weight: 500;">update -weight: 600;">sudo -weight: 500;">apt-get -weight: 500;">install -y -weight: 500;">apt-transport-https software-properties-common -weight: 500;">wget # Import GPG key -weight: 500;">wget -q -O - https://-weight: 500;">apt.grafana.com/gpg.key | -weight: 600;">sudo -weight: 500;">apt-key add - # Add Grafana repository echo "deb https://-weight: 500;">apt.grafana.com stable main" | -weight: 600;">sudo tee /etc/-weight: 500;">apt/sources.list.d/grafana.list # Install Grafana -weight: 600;">sudo -weight: 500;">apt-get -weight: 500;">update -weight: 600;">sudo -weight: 500;">apt-get -weight: 500;">install grafana # Install dependencies -weight: 600;">sudo -weight: 500;">apt-get -weight: 500;">update -weight: 600;">sudo -weight: 500;">apt-get -weight: 500;">install -y -weight: 500;">apt-transport-https software-properties-common -weight: 500;">wget # Import GPG key -weight: 500;">wget -q -O - https://-weight: 500;">apt.grafana.com/gpg.key | -weight: 600;">sudo -weight: 500;">apt-key add - # Add Grafana repository echo "deb https://-weight: 500;">apt.grafana.com stable main" | -weight: 600;">sudo tee /etc/-weight: 500;">apt/sources.list.d/grafana.list # Install Grafana -weight: 600;">sudo -weight: 500;">apt-get -weight: 500;">update -weight: 600;">sudo -weight: 500;">apt-get -weight: 500;">install grafana -weight: 600;">sudo -weight: 500;">systemctl daemon-reload -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable grafana-server -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start grafana-server -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status grafana-server # Check if it's running -weight: 600;">sudo -weight: 500;">systemctl daemon-reload -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable grafana-server -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start grafana-server -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status grafana-server # Check if it's running -weight: 600;">sudo -weight: 500;">systemctl daemon-reload -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable grafana-server -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start grafana-server -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status grafana-server # Check if it's running - Log in to your Grafana instance. - Click on the gear icon (Configuration) on the left sidebar, then select Data sources. - Click Add data source. - Search for and select Prometheus. - In the URL field, enter http://localhost:9090 (assuming Prometheus is running on the same VPS as Grafana). - Leave other settings as default for now and click Save & test. You should see a "Data source is working" message. - In Grafana, click the plus icon (Create) on the left sidebar, then select Import. - In the Import via grafana.com field, enter 1860 (the ID for the Node Exporter Full dashboard) and click Load. - On the next screen, select your Prometheus data source from the dropdown. - Click Import. - CPU Usage: High CPU can indicate an overloaded server or inefficient code. Watch for sustained high usage. - Memory Usage: Running out of RAM leads to swapping (using disk as RAM), which drastically slows down your server. Monitor both used and free memory. - Disk I/O: Slow disk read/write operations can bottleneck your applications, especially databases. - Network Traffic: Spikes in incoming or outgoing traffic can signal a DDoS attack or a sudden surge in legitimate user activity. - Disk Space: Running out of disk space will cause applications to fail. Monitor available disk space. - Process Counts: An unexpectedly high number of processes can indicate a runaway application or a fork bomb. - Alerting: Prometheus can be configured with alerting rules that trigger notifications when certain conditions are met (e.g., CPU usage over 90% for 5 minutes). This usually involves setting up an Alertmanager. - Application-Specific Metrics: You can instrument your applications to expose custom metrics to Prometheus, giving you visibility into application-level performance (e.g., request latency, error rates). - High Availability: For critical systems, you might consider running Prometheus and Grafana in a highly available setup, perhaps using multiple VPS instances. For reliable VPS hosting, providers like PowerVPS and Immers Cloud offer various plans to suit different needs. - Resource Management: Understanding your server's resource usage helps you choose the right VPS plan. A resource like Server Rental Guide can be helpful when comparing hosting options.