Installing and Setting Up Prometheus + Grafana with Linux System Metrics

Installing and Setting Up Prometheus + Grafana with Linux System Metrics

Installing and Setting Up Prometheus with Linux System Metrics

In this comprehensive guide, we'll cover the installation and setup of Prometheus and Grafana, and demonstrate how to collect and export system metrics from a Linux machine to Prometheus.

Part 1: Installing Prometheus

Step 1: System Requirements

Ensure your system meets the minimum requirements for running Prometheus, such as a compatible operating system like Linux, and sufficient disk space.

Step 2: Download and Extract Prometheus

  1. Visit the official Prometheus download page: prometheus.io/download
  2. Download the file to a location of your choice and then extract the compressed file using the following commands:
tar -xvzf prometheus-<version>.tar.gz
cd prometheus-<version>

Step 3: Configuration

Create a prometheus.yml file in the Prometheus directory and configure it. Here's an example incorporating job configurations for Prometheus and Node Exporter:

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'node-exporter'
    static_configs:
      - targets: ['localhost:9100']  # Assuming Node Exporter is running on the same machine

Step 4: Run Prometheus

Execute the following command to start Prometheus:

./prometheus --config.file=prometheus.yml

Access Prometheus' web interface at localhost:9090.

Part 2: Installing Node Exporter

Node Exporter is a Prometheus exporter for system metrics. We'll use it to gather and export Linux system metrics.

Step 1: Download and Install Node Exporter

  1. Visit the official Node Exporter download page: prometheus.io/download/#node_exporter
  2. Download the file to a location of your choice and then extract the compressed file using the following commands:
    tar -xvzf node_exporter-<version>.tar.gz
    cd node_exporter-<version>
    
  3. Run Node Exporter:
    ./node_exporter
    
    Node Exporter will start collecting system metrics.

Part 3: Integrating with Prometheus and Grafana

Step 1: Update Prometheus Configuration

Add the Node Exporter job to the Prometheus configuration (prometheus.yml):

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'node-exporter'
    static_configs:
      - targets: ['localhost:9100']  # Assuming Node Exporter is running on the same machine

Step 2: Query and Visualize Metrics in Grafana

  1. Log in to Grafana.
  2. Navigate to the "+" icon on the left sidebar and choose "Dashboard."
  3. Add a new panel, select Prometheus as the data source, and use queries like node_cpu_seconds_total or node_memory_MemFree_bytes to visualize system metrics.

With this setup, you have successfully integrated Node Exporter, collected Linux system metrics, and visualized them in Grafana through Prometheus. This provides an example of simple solution and setup for monitoring and managing the health of your Linux-based infrastructure. Explore Grafana's features to customize and enhance your monitoring dashboards further.

Did you find this article valuable?

Support Cloud Tuned by becoming a sponsor. Any amount is appreciated!