Reader small image

You're reading from  Learn Grafana 10.x - Second Edition

Product typeBook
Published inDec 2023
PublisherPackt
ISBN-139781803231082
Edition2nd Edition
Right arrow
Author (1)
Eric Salituro
Eric Salituro
author image
Eric Salituro

Eric Salituro is currently a Software Engineering Manger with the Enterprise Data and Analytics Platform team at Zendesk. He has an IT career spanning over 30 years, over 20 of which were in the motion picture industry working as a pipeline technical director and software developer for innovative and creative studios like DreamWorks, Digital Domain, and Pixar. Before moving to Zendesk, he worked at Pixar helping to manage and maintain their production render farm as a Senior Software Developer. Among his accomplishments there was the development of a Python API toolkit for Grafana aimed at streamlining the creation of rendering metrics dashboards
Read more about Eric Salituro

Right arrow

Surveying Additional Grafana Visualizations

In the last chapter, we looked at several venerable panel visualizations. From the table to the stat and gauge visualizations, each is a key component in your visualization toolkit—the panel visualizations that you will combine on the canvas of the dashboard to highlight your data and tell its story.

In this chapter, we will be looking at a few of the newer visualizations, mostly concerned with the display of data in more qualitative ways, from the use of spatial mapping with the geomap visualization to categorical data in the bar chart and heatmap visualizations.

We’ll also be working with a new dataset from our friends at the United States Geological Survey (USGS), a real-time catalog of earthquakes around the globe.

We’ll first drop the data on a map, locating each earthquake in its spatial location with the geomap visualization. Next, we’ll look at how to display earthquake category data with the bar...

Technical requirements

Before we create our visualization panels, we’ll need to set up InfluxDB and Grafana servers, install a Python Docker container to run our script, and then ingest data into an InfluxDB bucket. These steps should recall those we used when we introduced this data ingestion pipeline back in Chapter 5, Extracting and Visualizing Data with InfluxDB and Grafana.

Information

Tutorial code, dashboards, and other helpful files for this chapter can be found in this book’s Github repository at https://github.com/PacktPublishing/Learn-Grafana-10/tree/main/Chapter08.

Let’s start!

Launching server Docker containers

We’ll go through the same steps as in the previous chapters:

  1. If you haven’t done so already, shut down any services you might have left running from the other chapters by executing the following:
    % docker-compose down
  2. Run the Docker Compose script that will download the Grafana and InfluxDB containers and then launch them. The docker-compose.yml file is available in the Chapter08 directory of the GitHub repository for this book:
    % docker-compose up -d --pull missing
    [+] Running 3/3
      Network chapter08_default         Created            0.1s
      Container chapter08-influxdb-1  Started            0.5s
      Container chapter08-grafana-1   Started            ...

Setting up the InfluxDB database

Here, we’ll log in to our InfluxDB server, set it up with an initial account and bucket, and generate an API key so we can connect to it from our Python script and the Grafana data source.

Initializing the InfluxDB server

Log in to the InfluxDB UI at http://localhost:8086. If you haven’t already set up the instance, you’ll see a prompt to perform the initialization:

  1. Set the username to whatever you like.
  2. Add a password (8 characters minimum).
  3. Choose an organization name: LearnGrafana.
  4. Create a bucket: Chapter08.

Generating an API token

You’ll need to generate a new token in order to access the InfluxDB server from our script:

  1. Click on Load Data | API Tokens.
  2. Click the gear icon on the right side of the user you created previously and select Clone.
  3. Click on Copy to clipboard to copy the API token string.
  4. Save the API token in a safe place as you won’t be able to...

Configuring the InfluxDB data source

Now that we have our InfluxDB server ready to accept data, let’s get Grafana ready to communicate with it:

  1. Open your browser to the Grafana app and select Connections | Add new connection from the main menu.
  2. Search for the InfluxDB data source and select it.
  3. Click on Add a new data source. Fill out the following form fields:
    • Name: InfluxDB
    • Query Language: InfluxQL
    • HTTP | URL: http://influxdb:8086
    • Custom HTTP Headers | Header: Authorization
    • Custom HTTP Headers | Value: Token <API Token>
    • Database: Chapter08

Note

Make sure there is a space between Token and <API Token>.

Your data source configuration should look like this:

Figure 8.1 – InfluxDB data source

Figure 8.1 – InfluxDB data source

Click on Save and Test to confirm you can successfully connect to the InfluxDB server.

Building the Python Docker container

Use the requirements.txt file in the Chapter08 repository to create a Docker container with...

Exploring spatial data with the Geomap visualization

You should be all set up at this point to start downloading our data and then storing it in our InfluxDB bucket.

Ingesting a new earthquake dataset

The USGS maintains a comprehensive earthquake catalog and it is freely available via a simple REST interface at https://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php. The USGS provides continually updated catalogs of earthquakes, which are filtered by size over a variety of time periods ranging from one hour to one month.

To load the earthquake data, we only need to create a new Python script that is similar in structure to weather.py from Chapters 5, 6, and 7. We’ll call this new script earthquake.py, and you can find it in the Chapter08/app folder of the repository. Let’s take a quick peek at the changes we made from weather.py to earthquake.py.

Updating process_cli()

The first big change occurs in process_cli(). First, we change the parser description...

Displaying category data with a bar chart visualization

We will now move on to talk about the bar chart visualization. This visualization is designed to display a simple bar chart reflecting the relationship between a set of categories and their associated values.

Basically, it works much like you would expect a Microsoft Excel spreadsheet graph to work by taking a series of text value pairs and graphing their relative sizes.

An example from the Grafana documentation using the TestData data source should make things clear. Here, we select the CSV file scenario and the browser_marketshare.csv file option. By setting the visualization to Bar chart, you should see a graph of various web browsers and their relative market share depicted as a bar chart.

Figure 8.7 – Browser market share bar chart

Figure 8.7 – Browser market share bar chart

Switching to Table view shows the dataset is nothing more than a series of browser/market share category/value pairs. Can we do something similar with...

Displaying histogram data with the bar chart visualization

It turns out the answer to the first question is yes. Again, we can leverage transformations to shape our data in a way that makes it compatible with the bar chart. At this point, we’re going to break away from the pattern we’ve followed in this chapter in order to demonstrate a better workflow practice than simply creating the bare minimum to illustrate a concept.

The goal is to set up a visualization pipeline, both the Query and the Transform, to maximize our flexibility as we perform analysis. This way, if we want to produce multiple panels with different slices of data or different metrics, we don’t have to create entirely new panels each time. Follow these steps:

  1. Create a new bar chart visualization panel.
  2. Add the following query (raw editor): SELECT "magnitude", "cdi", "mmi", "sig", "depth" FROM "event" WHERE $timeFilter GROUP...

Visualizing histogram data over time with the heatmap

Armed with the tools to produce histograms and corresponding bar chart visualizations for our earthquake data, we now turn to an additional dimension: time. What if you could see how histogram data changes over time? Enter the heatmap, a visualization capable of mapping histogram bins with the x axis representing time, the y axis representing the bin, and the bin count by color.

In order to leverage the heatmap, we only need to make a small change to our existing panel, so let’s make a copy first. To duplicate a panel, click on the title of the panel on the dashboard and select More... | Duplicate. Now, open the new panel for editing.

Disable the Histogram and Convert field type transformation functions. They are not relevant for this visualization.

When you switch the panel over to use the Heatmap visualization, you may either see something that looks like a bunch of colored rectangles or you may get an error. The...

Summary

I hope this was an interesting (and informative) exploration into some of the science behind one of the more destructive forces on Earth. In this chapter, we learned about several new visualizations including geomap, bar chart, histogram, and heatmap. We have also become familiar with the transformation functions and how they can help shape data to facilitate analysis. We even learned a little about the power-law distribution (https://en.wikipedia.org/wiki/Power_law) and how it governs many of the common processes in nature.

In our next chapter, we bring together much of what we’ve learned in the past few chapters. We’ll apply these skills toward a concrete result: assembling panels into engaging and informative dashboards.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learn Grafana 10.x - Second Edition
Published in: Dec 2023Publisher: PacktISBN-13: 9781803231082
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

Author (1)

author image
Eric Salituro

Eric Salituro is currently a Software Engineering Manger with the Enterprise Data and Analytics Platform team at Zendesk. He has an IT career spanning over 30 years, over 20 of which were in the motion picture industry working as a pipeline technical director and software developer for innovative and creative studios like DreamWorks, Digital Domain, and Pixar. Before moving to Zendesk, he worked at Pixar helping to manage and maintain their production render farm as a Senior Software Developer. Among his accomplishments there was the development of a Python API toolkit for Grafana aimed at streamlining the creation of rendering metrics dashboards
Read more about Eric Salituro