Skip to main content

Comprehensive Guide: Setting Up Grafana, Prometheus, and Node Exporter on Ubuntu

Introduction: Overview of Grafana, Prometheus, and Node Exporter

Tool Description

Grafana: Grafana is an open-source platform for monitoring and observability that allows you to create, explore, and share dashboards and data visualizations.

Prometheus: Prometheus is an open-source monitoring and alerting toolkit designed for reliability and scalability, known for its dimensional data model and powerful query language (PromQL).

Node Exporter: Node Exporter is a Prometheus exporter for system metrics, exposing various system-level metrics about CPU, memory, disk usage, and more, which Prometheus can then scrape and store.

Benefits of using these tools together

  • Unified Monitoring Platform: Integrating Grafana with Prometheus and Node Exporter provides a comprehensive solution for monitoring and observability across various systems and services.
  • Rich Visualization Capabilities: Grafana's powerful visualization features allow you to create detailed, interactive dashboards that display data collected by Prometheus and Node Exporter, providing insights at a glance.
  • Flexible Data Queries: Prometheus's PromQL query language enables flexible querying of metrics collected by Node Exporter, allowing you to extract specific data points and trends for analysis and troubleshooting.
  • Real-time Alerting: Prometheus can be configured to monitor metrics from Node Exporter and trigger alerts based on predefined thresholds, ensuring timely notification of potential issues or anomalies.
  • Scalability and Performance: Node Exporter's lightweight design makes it suitable for monitoring large-scale deployments without significant overhead, while Prometheus's efficient storage and querying capabilities support scalable data collection and analysis.
  • Open-source Community Support: All three tools are open-source projects with active communities, ensuring continuous development, bug fixes, and support for new features and integrations.
  • Ecosystem Integration: Grafana supports integration with a wide range of data sources and plugins, enhancing its capability to visualize data from Prometheus and other monitoring tools, providing a unified view of the entire infrastructure.
  • Historical Analysis: Grafana's ability to visualize historical data stored in Prometheus allows for trend analysis and performance optimization over time, aiding in capacity planning and resource management.

Prerequisites

Necessary permissions and access

Firewall Rules (UFW): Open port 3000 for Grafana: sudo ufw allow 3000.

Hosts File Configuration: Modify /etc/hosts to include:
127.0.0.1:3000 172.16.x.xxx
Replace 172.16.x.xxx with your IP address.

Installing Grafana on Ubuntu

Downloading Grafana for Ubuntu: Download Grafana OSS edition if not using Docker.

Setting up Grafana:

  • In Docker:
  • $ sudo docker run -d -p 3000:3000 --name=grafana grafana/grafana-oss
  • Starting and enabling Grafana service:
  • $ sudo systemctl start grafana-server
    $ sudo systemctl status grafana-server

Installing Prometheus on Ubuntu

Downloading Prometheus for Ubuntu: Download tar.gz from Prometheus download page.

Installing Prometheus:

  • Unzip it using:
  • $ tar xzf prometheus-2.xx.x.linux-amd64.tar.gz
  • Move it to /etc/prometheus:
  • $ mv prometheus-2.xx.x.linux-amd64 /etc/prometheus
  • Create a systemd service file:
  • $ vi /etc/systemd/system/prometheus.service
  • Enter the following content:
  • [Unit]
    Description=Prometheus
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    ExecStart=/etc/prometheus/prometheus --config.file=/etc/prometheus/prometheus.yml
    Restart=always
    
    [Install]
    WantedBy=multi-user.target
  • Reload systemd, start, enable, and check status:
  • $ systemctl daemon-reload
    $ systemctl start prometheus
    $ systemctl enable prometheus
    $ systemctl status prometheus

Installing Node Exporter on Ubuntu

Downloading Node Exporter for Ubuntu: Download from Node Exporter download page.

Installing Node Exporter:

  • Unzip it using:
  • $ tar xzf node_exporter-1.8.1.linux-amd64
  • Move it to /etc/node_exporter:
  • $ mv node_exporter-1.8.1.linux-amd64 /etc/node_exporter
  • Create a systemd service file:
  • $ vi /etc/systemd/system/node_exporter.service
  • Enter the following content:
  • [Unit]
    Description=Node Exporter
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    ExecStart=/etc/node_exporter/node_exporter
    Restart=always
    
    [Install]
    WantedBy=multi-user.target
  • Reload systemd, start, enable, and check status:
  • $ systemctl daemon-reload
    $ systemctl start node_exporter
    $ systemctl enable node_exporter
    $ systemctl status node_exporter

Configuring Node Exporter as a service

Remove existing prometheus.yml file:

$ rm -rf /etc/prometheus/prometheus.yml

Create a new file and enter the following:

$ vi /etc/prometheus/prometheus.yml
global:
  scrape_interval: 15s

scrape_configs:
  - job_name: node
    static_configs:
      - targets: ['172.16.1.141:9100'] # Replace with your own IP

Reload systemd, start Prometheus, and check status:

$ systemctl daemon-reload
$ systemctl restart prometheus
$ systemctl status prometheus

Accessing Grafana and Creating a New Connection

Access Grafana: Open your browser and go to http://:3000 (e.g., http://172.16.1.141:3000).

Create a New Connection:

  • Navigate to Configuration -> Data Sources.
  • Click on Add data source.
  • Select Prometheus from the list.
  • Enter the URL as http://:9090 (replace with your IP if different).
  • Click Save & Test to verify the connection.
  • Create or Import a Dashboard:
    • Go to Dashboards -> Manage.
    • Click New Dashboard to create one, or
    • Click Import to import an existing dashboard.
    • For example, you can import dashboard ID 1860 for system monitoring.
    • If importing, remove any unnecessary links and save the dashboard.

Written by: A.M.Rinas

Contact: mohomadrinas00@gmail.com

Comments

Popular posts from this blog

MySQL 8.0 Binary Installation: A Step-by-Step Guide

MySQL 8.0 Installation: A Comprehensive Guide Aim : Install MySQL 8.0 using the binary distribution on a Linux system. MySQL 8.0 Installation Steps Step 1: Prepare System and User Create a MySQL group: groupadd mysql Create a MySQL user with restricted shell access: useradd -r -g mysql -s /bin/false mysql Step 2: Download and Extract MySQL Navigate to the installation directory(Not compulsory): cd /usr/local Extract the MySQL tarball: tar xvf /path/to/mysql-VERSION-OS.tar.xz Create a symbolic link: ln -s full-path-to-mysql-VERSION-OS mysql Navigate to the MySQL directory: cd mysql Create a directory for MySQL files: mkdir mysql-files Set ownership and permissio...

Install Tomcat on Linux using binary distribution

Install Tomcat on Linux Aim: In this tutorial, we will install Tomcat 9.0.21 on Linux. Step 1: Installing JDK Tomcat 9 requires Java 8 or later versions. Check Java installation: $ java -version If Java is not installed, run the following commands to install Java: $ sudo apt-get update $ sudo apt-get install default-jdk -y After installation, verify Java installation: $ java -version Step 2: Creating a Tomcat user and group Create a group and user for Tomcat: $ sudo groupadd tomcat $ sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat Step 3: Download and Install Tomcat 9 Change directory to /opt and download Tomcat 9 to that directory: $ cd /opt $ sudo wget https:/...

Grafana Installation on Ubuntu using Docker

Grafana Installation on Ubuntu using Docker Aim : Install Grafana OSS (open-source version) on Ubuntu using Docker. Grafana Installation Steps Step 1: Pull and Run the Grafana Container Pull and start the Grafana container: sudo docker run -d -p 3000:3000 --name=grafana grafana/grafana-oss -d : Detaches the container and runs it in the background. -p 3000:3000 : Maps port 3000 on your host machine to port 3000 inside the container, enabling access to Grafana's web interface. --name=grafana : Specifies the name of the container as grafana . Step 2: Access Grafana Once the container is running, access Grafana by opening a web browser and navigating to: http://localhost:3000 If Grafana is running on a remote serv...