CodeGym /Courses /Docker SELF /Visualizing Metrics in Grafana

Visualizing Metrics in Grafana

Docker SELF
Level 21 , Lesson 4
Available

5.1 What is Grafana

Grafana is a powerful tool for visualizing metrics, widely used for creating customizable dashboards and analyzing data in real-time. In this lecture, we’ll look at how to set up Grafana to work with Prometheus and how to create dashboards for visualizing Docker container metrics.

5.2 Installing Grafana on Windows

To install Grafana on Windows, follow these steps:

1. Download the installer

Go to the official Grafana website and download the installer for Windows: https://grafana.com/grafana/download.

Terminal

    # The installer file is usually named grafana-installer-x.x.x.exe
    

2. Install Grafana

Run the installer and follow the instructions. You can choose to install it as a Windows service for automatic startup.

3. Start Grafana

After the installation is complete, you can start Grafana as a service or using the desktop shortcut. Open your browser and go to http://localhost:3000.

5.3 Installing Grafana on macOS

To install Grafana on macOS, follow these steps:

1. Installing Homebrew

If Homebrew is not installed yet, run the following command:

Terminal

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
    

2. Installing Grafana

Terminal

brew update
brew install grafana
    

3. Starting Grafana

Run Grafana as a service:

Terminal

brew services start grafana
    

Open your browser and go to http://localhost:3000.

5.4 Installing Grafana on Linux

To install Grafana on Linux, follow these steps:

1. Adding the Grafana Repository

Add the official Grafana repository:

Terminal

sudo apt-get install -y software-properties-common
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
sudo apt-get update
    

2. Installing Grafana

Terminal

sudo apt-get install grafana
    

3. Starting Grafana

Start and enable Grafana auto-start:

Terminal

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

Go to the browser and visit http://localhost:3000.

5.5 Setting Up Grafana

1. Accessing the Grafana Web Interface

Open your web browser and go to http://localhost:3000. Log in using the default credentials: (admin/admin).

2. Adding a Prometheus Data Source

  1. Navigate to "Configuration" → "Data Sources".
  2. Click "Add data source".
  3. Select "Prometheus".
  4. Enter the URL of your Prometheus server (e.g., http://localhost:9090).
  5. Click "Save & Test" to check the connection.

5.6 Creating Dashboards in Grafana

1. Creating a New Dashboard

  1. Go to "Create" → "Dashboard".
  2. Click "Add new panel".

2. Adding a Panel

  1. In the "Query" section, select the data source Prometheus.
  2. Enter a PromQL query to get the metrics. For example, to use CPU:
  3. PromQL
    
    rate(container_cpu_usage_seconds_total[1m])
    
  4. Select the type of graph (e.g., "Graph").
  5. Customize the panel (e.g., title, legend, axes, etc.).
  6. Click "Apply" to save the panel.

3. Creating Additional Panels

Repeat the steps to create additional panels for other metrics, such as memory, network, and disk. Example queries:

Memory Usage:

PromQL

container_memory_usage_bytes

Network Traffic:

PromQL

rate(container_network_receive_bytes_total[1m])

Disk Operations:

PromQL

rate(container_fs_reads_total[1m])

5.7 Examples of Creating Panels

Example 1: CPU Panel

Query:

PromQL

rate(container_cpu_usage_seconds_total[1m])

Graph Type: Graph

Panel Settings: Set the title to "CPU Usage" and configure the axes.

Example 2: Memory Panel

Query:

PromQL

container_memory_usage_bytes

Graph Type: Graph

Panel Settings: Set the title to "Memory Usage" and configure the axes.

Example 3: Network Traffic Panel

Query:

PromQL

rate(container_network_receive_bytes_total[1m])

Graph Type: Graph

Panel Settings: Set the title to "Network Traffic" and configure the axes.

5.8 Setting Up Dashboards

1. Setting Time Ranges

At the top of your dashboard, select the time range for displaying metrics (e.g., last 5 minutes, last hour, etc.).

2. Saving the Dashboard

  1. Click on the "Save dashboard" button in the top menu.
  2. Specify the name of the dashboard and, if needed, provide a description.
  3. Click "Save".

3. Organizing Panels

You can drag and drop panels, resize them, and organize them on the dashboard however you like. This will help you create a more user-friendly and informative dashboard.

Example of a Full Dashboard

Creating a dashboard that includes panels for CPU, memory, network traffic, and disk operations will give you a complete view of the state of your Docker containers.

  1. Create a new dashboard and add panels for all key metrics.
  2. Configure each graph with the appropriate PromQL queries and display settings.
  3. Organize panels on the dashboard so that important metrics are easily accessible.
3
Task
Docker SELF, level 21, lesson 4
Locked
Installing Grafana
Installing Grafana
3
Task
Docker SELF, level 21, lesson 4
Locked
Starting Grafana
Starting Grafana
3
Task
Docker SELF, level 21, lesson 4
Locked
Adding a data source
Adding a data source
3
Task
Docker SELF, level 21, lesson 4
Locked
Creating a CPU Panel
Creating a CPU Panel
1
Опрос
Monitoring and Logging,  21 уровень,  4 лекция
недоступен
Monitoring and Logging
Monitoring and Logging
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION