Reader small image

You're reading from  Hands-On Infrastructure Monitoring with Prometheus

Product typeBook
Published inMay 2019
PublisherPackt
ISBN-139781789612349
Edition1st Edition
Right arrow
Authors (2):
Joel Bastos
Joel Bastos
author image
Joel Bastos

Joel Bastos is an open source supporter and contributor, with a background in infrastructure security and automation. He is always striving for the standardization of processes, code maintainability, and code reusability. He has defined, led, and implemented critical, highly available, and fault-tolerant enterprise and web-scale infrastructures in several organizations, with Prometheus as the cornerstone. He has worked at two unicorn companies in Portugal and at one of the largest transaction-oriented gaming companies in the world. Previously, he has supported several governmental entities with projects such as the Public Key Infrastructure for the Portuguese citizen card. You can find his blogs at kintoandar and on Twitter with the handle @kintoandar.
Read more about Joel Bastos

Pedro Araújo
Pedro Araújo
author image
Pedro Araújo

Pedro Arajo is a site reliability and automation engineer and has defined and implemented several standards for monitoring at scale. His contributions have been fundamental in connecting development teams to infrastructure. He is highly knowledgeable about infrastructure, but his passion is in the automation and management of large-scale, highly-transactional systems. Pedro has contributed to several open source projects, such as Riemann, OpenTSDB, Sensu, Prometheus, and Thanos. You can find him on Twitter with the handle @phcrva.
Read more about Pedro Araújo

View More author details
Right arrow

Discovering and Creating Grafana Dashboards

The Prometheus expression browser is great for performing exploratory queries, but sometimes we require prebuilt visualizations to assist us when we want to quickly debug issues. In this chapter, we'll dive into Grafana, the tool recommended by the Prometheus project for building dashboards. The Grafana community keeps growing and thriving, in part by hosting a multitude of ready-to-use dashboards, making it easy to reuse them and contribute to the community and thus improve the ecosystem. In this chapter, we will learn how to find and use dashboards from the community, as well as how to write our own and give something back to the community. Finally, we'll also provide a cursory look at consoles, the dashboarding solution built into Prometheus for advanced use cases.

In brief, the following topics will be covered in this chapter...

Test environment for this chapter

To provide a hands-on approach, we'll be creating a new test environment for this chapter. The setup we'll be using resembles the following diagram:

Figure 10.1: Test environment network

Deployment

To generate this chapter's virtual machine (VM) based test environment, go to the correct repository path, relative to the code repository root:

cd ./chapter10/

Ensure that no other test environments are running and spin up this chapter's environment, as follows:

vagrant global-status
vagrant up

You can validate the successful deployment of the test environment using the following code:

vagrant status

This will give the following output:

Current machine states:

prometheus ...

How to use Grafana with Prometheus

Grafana is the most recognized open source project for dashboarding. It has the concept of data sources, which are nothing more than integrations with data backends. At the time of writing, the following are the available data sources:

  • Prometheus
  • Graphite
  • InfluxDB
  • Elasticsearch
  • Google Stackdriver
  • AWS CloudWatch
  • Azure Monitor
  • Loki (logging visualization)
  • MySQL
  • PostgreSQL
  • Microsoft SQL Server
  • OpenTSDB
  • TestData (useful for generating fake data for testing)

Several efforts have been made to improve the integration of Prometheus into Grafana—for example, PromQL autocompletion. Currently, Grafana is the go-to dashboarding solution for anyone interested in visualizing Prometheus data. The previous sentence isn't completely true, because we know that for exploratory queries, there's nothing like the Prometheus expression browser. Recently...

Building your own dashboards

Inside the provided VM test environment, you had the opportunity to try out the bundled dashboard. Now, it's time to learn how to build your own, but for that, you will need to grasp some concepts. In this section, we'll walk you through the process of creating a dashboard.

Dashboard fundamentals

A dashboard is composed of several components. We'll go over the most important concepts in the following sections, including panels, the visualizations they support, how to template variables, and changing the time range of the displayed data.

Panels

...

Discovering ready-made dashboards

Since Grafana is widely used and has a huge community behind it, it's logical that a huge number of dashboards are being created by that community. The folks at Grafana provide a service where registered users are able to publish their dashboards onto a gallery, and anyone can download and install them on their own Grafana instances. In the following sections, we'll be providing an overview of both actions, not only using community-made dashboards, but also how to publish your own.

Grafana dashboards gallery

Both community-driven and official dashboards are available at https://grafana.com/dashboards and, as expected, there are a lot to choose from. Since we're interested in...

Default Prometheus visualizations

Historically, Prometheus maintained its own tool to create dashboards, called PromDash. Over time, since Grafana improved its native support for Prometheus as a data source, the community began gravitating toward using Grafana as its primary visualization solution—so much so that PromDash was deprecated by the people who maintained Prometheus in favor of Grafana.

You can find the source code for PromDash at https://github.com/prometheus-junkyard/promdash.

Even though Grafana is the recommended visualization solution for most people, Prometheus also ships with an internal dashboarding feature called console templates. These console templates are written in raw HTML/CSS/JavaScript and leverage the power of the Go templating language to generate dashboards (called consoles) that are served by the Prometheus server itself. This makes them blazingly...

Summary

In this chapter, we explored the standard visualization tool for Prometheus: Grafana. We've learned how to provision not only data sources, but dashboards as well. After learning about the building blocks of a dashboard, we created a simple dashboard from scratch, learning all that it entails step by step. We also learned how to take advantage of the thriving community-built dashboard gallery. Giving back to the community is always important, so we've gone through the process of exporting and publishing dashboards. Finally, we were introduced to the Prometheus default visualizations—the consoles—which, even though they have a steep learning curve, are extremely powerful.

In the next chapter, we'll be exploring the Alertmanager, how to best take advantage of its functionalities, and how to integrate it with Prometheus.

...

Questions

  1. How can you provision a data source automatically in Grafana?
  2. What are the steps to import a dashboard from the Grafana gallery?
  3. How do Grafana dashboard variables work?
  4. What's the building block of a dashboard?
  5. When you update a dashboard that's published to grafana.com, does it change its ID?
  6. In Prometheus terms, what is a console?
  7. Why would you use Prometheus console templates?

Further reading

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hands-On Infrastructure Monitoring with Prometheus
Published in: May 2019Publisher: PacktISBN-13: 9781789612349
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Joel Bastos

Joel Bastos is an open source supporter and contributor, with a background in infrastructure security and automation. He is always striving for the standardization of processes, code maintainability, and code reusability. He has defined, led, and implemented critical, highly available, and fault-tolerant enterprise and web-scale infrastructures in several organizations, with Prometheus as the cornerstone. He has worked at two unicorn companies in Portugal and at one of the largest transaction-oriented gaming companies in the world. Previously, he has supported several governmental entities with projects such as the Public Key Infrastructure for the Portuguese citizen card. You can find his blogs at kintoandar and on Twitter with the handle @kintoandar.
Read more about Joel Bastos

author image
Pedro Araújo

Pedro Arajo is a site reliability and automation engineer and has defined and implemented several standards for monitoring at scale. His contributions have been fundamental in connecting development teams to infrastructure. He is highly knowledgeable about infrastructure, but his passion is in the automation and management of large-scale, highly-transactional systems. Pedro has contributed to several open source projects, such as Riemann, OpenTSDB, Sensu, Prometheus, and Thanos. You can find him on Twitter with the handle @phcrva.
Read more about Pedro Araújo