Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Building IoT Visualizations using Grafana

You're reading from  Building IoT Visualizations using Grafana

Product type Book
Published in Jul 2022
Publisher Packt
ISBN-13 9781803236124
Pages 360 pages
Edition 1st Edition
Languages
Author (1):
Rodrigo Juan Hernández Rodrigo Juan Hernández
Profile icon Rodrigo Juan Hernández

Table of Contents (21) Chapters

Preface Part 1: Meeting Grafana
Chapter 1: Getting Started with Grafana Chapter 2: Exploring Grafana Part 2: Collecting Data from IoT Devices
Chapter 3: Connecting IoT Devices Chapter 4: Data Sources for Grafana Chapter 5: Using Time Series Databases Part 3: Connecting Data Sources and Building Dashboards
Chapter 6: Getting Data and Building Dashboards Chapter 7: Managing Plugins Chapter 8: Organizing and Managing Dashboards Part 4: Performing Analytics and Notifications
Chapter 9: Performing Analytics in Grafana Chapter 10: Alerting and Notifications in Grafana Part 5: Integrating Grafana with Other Platforms
Chapter 11: Using Grafana with Prometheus Chapter 12: Using Grafana with OpenSearch Chapter 13: Showing Data from LibreNMS in Grafana Chapter 14: Integrations for Grafana Cloud Other Books You May Enjoy

Chapter 9: Performing Analytics in Grafana

In this chapter, you will learn how to transform data and perform calculations on it. You will use some built-in Grafana functionalities, InfluxQL capabilities, and the Plotly plugin.

First, you will learn how to use numerical manipulations on an InfluxDB data source. Then, you’ll learn about transformations in Grafana.

These calculations include statistical, derivative, integral, and mathematic functions.

You will also learn how to embed Plotly dashboards in Grafana panels.

The topics that are covered in this chapter are the following:

  • InfluxDB calculations
  • Transformations in Grafana
  • Building advanced plots with Plotly

After finishing this chapter, you will be able to perform all kinds of calculations on data and build complex visualizations.

Technical requirements

To apply the techniques shown in this chapter, you will need the following:

  • A running instance of Grafana
  • An InfluxDB data source with historical data
  • The Plotly plugin installed in Grafana

Let’s start by looking at InfluxDB calculations.

InfluxDB calculations

In InfluxDB, you can perform calculations on the data. In this section, you will learn how to apply them from the graphical query section of Grafana.

First, let’s identify the section on the panel edition screen. Figure 9.1 shows the query editor, which you already know about from previous chapters:

Figure 9.1 – Query editor

Recall from Chapter 5, Using Time Series Databases, that InfluxDB has two query languages: InfluxQL and Flux. In that chapter, you learned that versions 1.x of InfluxDB use InfluxQL, whereas versions 2.x of InfluxDB use Flux.

However, you can also use InfluxQL in versions 2.x. Please refer to Chapter 5, Using Time Series Databases, for more information.

In the end, Grafana fully supports InfluxQL, so we will work with that. So, let’s start by looking at functions in InfluxQL.

InfluxQL functions

InfluxDB offers you a wide range of calculations. It’s important to note that...

Transformations in Grafana

You can use transformations in Grafana to process the data from a query before Grafana shows it. With transformations, you can join queries, rename fields, perform mathematical operations, and so on.

To access the transformation feature, go to the Transform tab in the panel editor, as you can see in Figure 9.3:

Figure 9.3 – Transform tab

Take into account that, sometimes, the resulting data isn’t shown in the panel because of some incompatibility with the type of panel. In these cases, you can switch the panel to Table view at the top of the screen. In this mode, you will be able to see the results as a table and analyze whether they are what you are looking for.

If you apply more than one transformation, the order of them is important. Each transformation passes the result to the next, forming a pipeline. So, changing the order can modify the final result.

Finally, to apply transformations, you need a working...

Building advanced plots with Plotly

According to the GitHub description, Plotly is a standalone JavaScript data visualization library. This library is also available in Python and R.

With Plotly, you can build a wide range of basic and advanced visualizations, such as 3D graphs, SVGs, and statistical charts.

There are two plugins for running Plotly scripts at the time of writing this book. However, one of them seems to have some issues. In this book, we will work with the Plotly panel, whose source code is available in the following GitHub repository:

https://github.com/ae3e/ae3e-plotly-panel

You can find the plugin page on the Grafana Labs site, at the following link: https://grafana.com/grafana/plugins/ae3e-plotly-panel/.

To install this plugin, you can follow the same procedure described in Chapter 7, Managing Plugins.

In particular, you can install this plugin with the CLI tool, using the following command:

$sudo grafana-cli plugins install ae3e-plotly-panel...

Summary

In this chapter, you have seen how to perform basic analytics using the InfluxQL language, just before the data is displayed on the dashboard.

Also, you have learned how to use Grafana transformations to perform calculations, group data, modify data structure, and more. All these transformations allow you to arrange the data before displaying it on the dashboard.

Finally, you have seen how to use the Plotly library utilizing a plugin. This library brings you great versatility, allowing you to build things from simple plots to advanced visualizations.

In the next chapter, you will learn how to set alerts and notifications, something that is very important on any IoT platform.

Invitation to join us on Discord

Read this book alongside other Grafana users and the author Rodrigo Juan Hernández.

Ask questions, provide solutions to other readers, chat with the author via Ask Me Anything sessions and much more.

SCAN the QR code or visit the link to join the community.

https://packt.link/iotgrafana

lock icon The rest of the chapter is locked
You have been reading a chapter from
Building IoT Visualizations using Grafana
Published in: Jul 2022 Publisher: Packt ISBN-13: 9781803236124
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.
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}