How to use Grafana with Prometheus

Grafana is an open-source interactive data visualization tool. It allows for data to be interpreted through visuals like charts and graphs. Depending on the requirements, this data can be shown in a unified visual or split into many. This can be done by creating queries and setting alerts on the inputted data into the tool.

Note: Learn more about Grafana.

Implementation

The input data for Grafana can be sourced from multiple tools. In our example, we will work with Prometheus, a popular integration tool for Grafana. We must first set up our Prometheus services to proceed with this guide.

Setting up Grafana

After setting up your Prometheus services, log in to your Grafana account on the official website. Head to the installation page to learn how to download Grafana for your specific OS; we will follow the Linux guide.

// to be run individually
sudo apt-get install -y apt-transport-https
sudo apt-get install -y software-properties-common wget
sudo wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key
echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install grafana
sudo systemctl start grafana-server
sudo systemctl status grafana-server // to check if server running
sudo systemctl enable grafana-server
Terminal commands for Linux systems

Now we go to our browser and enter "localhost:3000" into the address bar. This will navigate us to our Grafana services page. The login credentials are "admin" and "admin" for the username and password. After that, we will arrive at the screen shown below.

Grafana homepage
Grafana homepage

Add a data source

It's now time to add our data source to our Grafana service. For this, we will click on the "Data Sources" prompt. Alternatively, we click the three bars on the top right to open the menu. Then we can click "Connections" followed by "Data Sources" to add our data source.

Then, we click "Add a new data source" and select our preferred one. This will be Prometheus for now.

Data source options and more
Data source options and more

Afterward, we will be asked to enter our information regarding our Prometheus setup. Mainly, we need to add our "Prometheus server URL." We can modify other details as well, but it is not necessary.

Data source setup details
Data source setup details

Then we will click "save and test" to proceed.

Successful prompt
Successful prompt

Creating a dashboard

Let us now create a dashboard to visualize our data. For this, we will click on the "Dashboard" prompt. Alternatively, we click the three bars on the top right to open the menu. Then we can click "Dashboards" to jump to the dashboard list and click "new."

Then, we click "Add visualization" and select our data source i.e., Prometheus.

Start dashboard
Start dashboard

Now, we can start by setting up queries in LokiQL or using the UI given. An example query is shown below.

Query to show dns lookup time metrics for educative.io
Query to show dns lookup time metrics for educative.io

Each query will generate a graph or table, and we can experiment and create multiple queries with their respective visuals.

Graphical representation of the dns query
Graphical representation of the dns query

Multiple dashboards

As we have shown, it is possible to convert our metrics into a visual representation. Moreover, we can create multiple dashboards and make them available as a central dashboard.

Central dashboard
Central dashboard

Conclusion

In conclusion, Grafana provides a convenient service to visualize our data. It can help to visualize complex datasets, which can help us to keep a look out at our websites. Moreover, within Grafana, there are many tools to create better visuals with the ability to filter datasets and set up alerts depending on our needs.

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved