Setting Up Grafana with Prometheus on Ubuntu: A Comprehensive Guide

Setting Up Grafana with Prometheus on Ubuntu: A Comprehensive Guide

Introduction: To ensure the reliability and effectiveness of your systems and applications, it is crucial to monitor them consistently. By using Grafana and Prometheus in combination, you can access comprehensive monitoring and visualization features. This informative post will guide you through the process of installing Grafana with Prometheus on Ubuntu, enabling you to gain valuable insights into your infrastructure, maintain its seamless operation into your infrastructure and keep it running smoothly.

Grafana is a platform that enables users to create, share, and visualize interactive dashboards and graphs. It can support various data sources, with Prometheus being a widely used one. Some of the notable features of Grafana include:

  • Rich Visualization: Grafana provides a simple dashboard interface to create and personalize visualizations, including graphs, tables, and gauges.

  • Alerting and Annotations: Grafana enables users to create alert rules and add annotations to graphs for events and incidents.

  • Dashboard Sharing: Dashboards are a collaborative tool for monitoring and troubleshooting, easily shared with team members.

  • Plugins and Extensibility: Grafana enables integration with various data sources through plugins, including databases, cloud services, and IoT devices.

  • Community and Ecosystem: Grafana boasts a vibrant community that creates and shares a plethora of pre-made dashboards and plugins.

Prometheus is a monitoring and alerting toolkit that has been developed as an open-source project. It was initially created at SoundCloud and serves as a tool for collecting and storing time-series data. This type of data presents information that changes over time and is represented as a sequence of timestamped values. Prometheus is particularly effective at gathering metrics from diverse sources, including servers, containers, databases, and applications. It boasts several impressive features that set it apart from other monitoring tools.

  • Scalable Data Collection: Prometheus is capable of monitoring complex environments by collecting data from various sources.

  • Multi-dimensional Data Model: The data collected by Prometheus is stored with labels, which allows for metrics to be flexibly queried and filtered.

  • Powerful Query Language: Prometheus Query Language (PromQL) enables users to create sophisticated queries for data analysis and alerting.

  • Alerting: Prometheus has an integrated alert system for setting rules and receiving notifications when requirements are met.

  • Service Discovery: It supports service discovery mechanisms to automatically discover and monitor new targets as they come online.

Prerequisites:

  1. Make sure you have the following prerequisites in place before installing and configuring:

  2. You should have an Ubuntu-based server with a non-root user account that has sudo privileges.

  3. Make sure your server has internet access to download the required packages.

  4. Basic Knowledge: Familiarity with the Linux command line will be helpful.

Step 1: Update and Upgrade Your System

Before installing any software, it's essential to keep your system up-to-date. Open a terminal and run the following commands:

sudo apt update 
sudo apt-get update

This will update the package list and upgrade your system packages to the latest versions.

Step 2: Install Grafana

Grafana is a popular open-source platform for monitoring and observability. To install Grafana, execute the following commands:

  • Download deb package for Grafana

      Wget https://dl.grafana.com/enterprise/release/grafana-enterprise_10.1.2_amd64.deb
    
  • Install the package

      sudo dpkg -i grafana-enterprise_10.1.2_amd64.deb
    
  • Start and enable Grafana on the server

      sudo systemctl start grafana-server
      sudo systemctl enable grafana-server
    

Step 3: Access the Grafana Web Interface

To access Grafana's web interface, open a web browser and navigate to http://your-server-ip:3000. You will be prompted to log in with your default credentials:

Username: admin
Password: admin

Upon logging in, you should change the default password for security reasons.

Step 4: Install Prometheus

Prometheus is an open-source monitoring and alerting toolkit. To install Prometheus, follow these steps:

  1. Download Prometheus:

     Wget https://github.com/prometheus/prometheus/releases/download/v2.47.0/prometheus-2.47.0.linux-amd64.tar.gz
    

  2. Extract the downloaded archive

     tar xvfz prometheus-2.47.0.linux-amd64.tar.gz
    

  3. Move the Prometheus binary to the /usr/local/bin directory to make it accessible system-wide:

     cd prometheus-2.47.0.linux-amd64
     sudo cp prometheus /usr/local/bin/
    
  4. Create a Prometheus configuration file:

      nano prometheus.yml  or vi prometheus.yml
    
  5. Add the following minimal configuration:

     global:
       scrape_interval: 15s
    
     scrape_configs:
       - job_name: 'prometheus'
         static_configs:
           - targets: ['localhost:9090']
    

    Step 5: Configure Prometheus as a Data Source

    To visualize data from Prometheus in Grafana, you need to configure Prometheus as a data source:

    In the Grafana web interface, click on the "Settings" gear icon in the left sidebar.

    Under the "connections" click on the "data source" button.

    Choose "Prometheus" from the list of available data source types.

    In the "HTTP" section, set the URL to http://localhost:9090, assuming Prometheus is running on the same server as Grafana.

Click "Save & Test" to verify the connection to Prometheus.

Step 6: Create Dashboards and Visualizations

With Prometheus configured as a data source, you can now create dashboards and visualizations to monitor your systems and applications. Grafana provides a user-friendly interface for building custom dashboards and adding panels to visualize your data.

  • Click on the new them import

We use Grafana default dashboard for Prometheus

Add “3662” in import via the Grafana.com section and load it

  • Add Prometheus to the data source

Conclusion:

By configuring Grafana along with Prometheus on Ubuntu, you can proficiently oversee and present your infrastructure. This potent amalgamation offers a solid base to monitor your systems and applications. You can personalize your Grafana dashboards to cater to your specific requirements. Monitoring is of utmost importance to ensure the well-being and efficiency of your systems. With Grafana and Prometheus, you possess the necessary tools to do precisely that. Simply follow the instructions delineated in this guide to begin your journey.