Visualizing Data with Grafana :- Configuration and Setup

Visualizing Data with Grafana :- Configuration and Setup

ยท

6 min read

Grafana is an open-source platform for monitoring, visualization and analysis providing powerful and flexible visualizations with support for various data sources including Prometheus. This blog will guide you through installing Grafana, connecting it to Prometheus and creating your first dashboard to visualize your metrics.

Step-by-Step Guide on Installing Grafana

Step 1 :- Download and Install Grafana

Grafana is available for multiple operating systems. The installation process is straightforward and we will cover the steps for Linux, macOS and Windows.

Installing on Linux

  1. Add the Grafana APT repository :-

     sudo apt-get install -y software-properties-common
     sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
    
  2. Add the Grafana GPG key :-

     wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
    
  3. Install Grafana :-

     sudo apt-get update
     sudo apt-get install grafana
    
  4. Start and enable the Grafana service :-

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

Installing on macOS

  1. Install Grafana using Homebrew :-

     brew update
     brew install grafana
    
  2. Start Grafana :-

     brew services start grafana
    

Installing on Windows

  1. Download the Grafana installer from the official Grafana website.

  2. Run the installer and follow the on-screen instructions.

  3. Start Grafana by running grafana-server from the command prompt.

Step 2 :- Access Grafana Web UI

After installation Grafana's web UI is accessible at localhost:3000. Open this URL in your web browser.

Step 3 :- Log In to Grafana

The default login credentials are :-

  • Username: admin

  • Password: admin

You will be prompted to change the default password upon first login.

How to Connect Grafana to Prometheus as a Data Source

  1. Navigate to Configuration :-

    • Click on the gear icon in the left sidebar to open the Configuration menu.

    • Select Data Sources.

  2. Add New Data Source :-

    • Click on the Add data source button.

    • Select Prometheus from the list of available data sources.

  3. Configure the Data Source :-

    • In the URL field, enter the address of your Prometheus server (e.g. localhost:3000).

    • Set the Access mode to Server if Grafana and Prometheus are on the same server or Browser if accessing remotely.

    • Click Save & Test to verify the connection.

If the connection is successful you will see a green message indicating that the data source is working.

Overview of Grafana's Interface and Key Features

Grafana's interface is user-friendly and packed with features that make it easy to visualize and analyze data. Here are the key components :-

Grafana UI Components

  1. Home Dashboard :-

    • The initial screen you see after logging in.

    • Provides quick access to creating dashboards, managing data sources and other configuration options.

  2. Side Menu :-

    • Located on the left side this menu provides access to Dashboards, Explore, Alerts and Configuration options.
  3. Dashboards :-

    • The main area where you create and view visualizations.

    • Can be customized with different panels, rows and plugins.

  4. Explore :-

    • An interactive query console to perform ad-hoc queries and visualize data.
  5. Alerts :-

    • Configure alerts to notify you when certain conditions are met based on your data.

Key Features of Grafana

  1. Customizable Dashboards :-

    • Create and organize dashboards with multiple panels.

    • Panels can be resized and arranged as needed.

  2. Rich Visualization Options :-

    • Supports various types of visualizations, including graphs, heatmaps, tables and more.

    • Extensive customization options for each panel.

  3. Templating and Variables :-

    • Create dynamic dashboards with variables to change queries and visualizations on the fly.
  4. Plugins :-

    • Extend Grafana's functionality with a wide range of plugins for data sources, panels and apps.
  5. Alerting :-

    • Set up alerts to monitor critical metrics and receive notifications through email, Slack or other channels.

Creating Your First Dashboard and Panel

Let's create a simple dashboard to visualize metrics from Prometheus.

Step 1 :- Create a New Dashboard

  1. Navigate to Dashboards :-

    • Click on the Dashboards icon in the side menu.

    • Select New Dashboard.

  2. Add a New Panel :-

    • Click on Add new panel.

Step 2 :- Configure the Panel

  1. Select Data Source :-

    • In the Query section select Prometheus as the data source.
  2. Enter PromQL Query :-

    • In the query editor enter a PromQL query to retrieve data. For eg., to visualize CPU usage from Node Exporter use :-

        node_cpu_seconds_total
      
  3. Configure Visualization :-

    • Select the type of visualization you want (e.g., Graph, Gauge, Table).

    • Customize the visualization settings such as the title, legend and axes.

Step 3 :- Save the Dashboard

  1. Save the Panel :-

    • Click on Apply to save the panel configuration.
  2. Save the Dashboard :-

    • Click on the Save dashboard icon at the top of the screen.

    • Enter a name for the dashboard and click Save.

Example :- Visualizing CPU Usage

Let's create a more specific example of visualizing CPU usage from Node Exporter.

  1. Add a New Panel :-

    • In the new dashboard click on Add new panel.
  2. Configure the Panel :-

    • Select Prometheus as the data source.

    • Enter the following PromQL query to calculate the CPU usage rate :-

        rate(node_cpu_seconds_total{mode!="idle"}[5m])
      
    • This query calculates the rate of CPU usage excluding the idle time over the last 5 minutes.

  3. Customize the Visualization :-

    • Set the visualization type to Graph.

    • Configure the graph settings, such as the title (CPU Usage), legend and axes.

  4. Apply and Save :-

    • Click on Apply to save the panel.

    • Save the dashboard with a meaningful name such as System Metrics.

Step 4 :- Adding More Panels

To make your dashboard more comprehensive you can add additional panels to visualize other metrics such as memory usage, disk I/O and network traffic.

Memory Usage

  1. Add a New Panel.

  2. Configure the Panel :-

    • Select Prometheus as the data source.

    • Enter the following PromQL query to visualize total memory usage :-

        node_memory_MemTotal_bytes
      
    • Customize the visualization settings.

  3. Apply and Save :-

    • Click on Apply to save the panel.

    • Save the dashboard.

Disk I/O

  1. Add a New Panel.

  2. Configure the Panel :-

    • Select Prometheus as the data source.

    • Enter the following PromQL query to visualize disk read bytes :-

        rate(node_disk_read_bytes_total[5m])
      
    • Customize the visualization settings.

  3. Apply and Save :-

    • Click on Apply to save the panel.

    • Save the dashboard.

Network Traffic

  1. Add a New Panel.

  2. Configure the Panel :-

    • Select Prometheus as the data source.

    • Enter the following PromQL query to visualize network receive bytes :-

        rate(node_network_receive_bytes_total[5m])
      
    • Customize the visualization settings.

  3. Apply and Save :-

    • Click on Apply to save the panel.

    • Save the dashboard.

Conclusion

Grafana is a powerful tool for visualizing and analyzing metrics from various data sources including Prometheus. In this blog we covered the installation and configuration of Grafana, connecting it to Prometheus, exploring Grafana's interface and key features and creating your first dashboard and panels.

By following this guide you now have the foundational knowledge to set up and use Grafana for monitoring and visualization. Stay tuned for more insights and practical tips to enhance your monitoring setup.

Let's connect and grow on Linkedin :Click Here

Let's connect and grow on Twitter :Click Here

Happy Monitoring!!!

Happy Reading!!!

Sudha Yadav

ย