Visualize your data using Grafana on TagoCore

Visualize your data using Grafana on TagoCore



TagoCore is a free, fast, and open-source IoT platform for edge computing that can be used in association with TagoIO to visualize your data by using several Widgets to create beautiful dashboards that can be deployed to your end-users.

However, you can also use third-parties applications like Grafana to visualize your data through simplified panels, and also to set up alerts using data from your TagoCore application, just like with TagoIO.


By the end of this tutorial, you will have enough knowledge to know the basics of querying data to create dashboards with graphs, charts, and so on.


Requirements to follow this tutorial

There are some basic settings that need to be configured before using Grafana.

  1. Install the latest version of TagoCore on your machine, and connect your devices. Check out the official TagoCore website for more information;


  1. Connect your TagoCore to a Database server. You can check out the available plugins to connect to your database by clicking on the Plugin Store button located on the TagoCore's sidebar.  You can also build your own plugin by following the tutorial Creating a Plugin.


Make sure that you are receiving data into your TagoCore, and that it's being stored in your database.



Installing Grafana

You can choose to run Grafana local or cloud. You can compare the differences between both versions on their Official Website. Refer to the links below to get started:



Make sure you have Grafana running (cloud or local) before advancing on this tutorial.



Connecting your database

In order to visualize data, you will need to connect Grafana to a database server running local or cloud. Refer to this link to check the Supported Databases.

Follow the instructions below to connect Grafana to your database:

  1. Open Grafana;

  2. Search for the "Configuration" icon on the left sidebar;

  3. Go to the tab "Data Sources" and then click on the button "Add data source";

  4. A list of available data sources will be displayed, select the one for you. After selecting a data source, a new screen will appear. Here you need to fill in the connection details for your data source. Refer to the image below:


  5. Fill in the required information to connect your data source, and then click on "Save & test" to test your connection. If all information is correct, the following message will be shown.


Note: If the system is throwing an error, check your data source configuration; it's recommended to run some tests to verify if it's working correctly:

  • Verify the status of your database connection at TagoCore;

  • Try to run some SQL queries inside your database source;

  • Restart your database server, and try again.


You can see a list of your data sources by clicking on the configuration button, and then the Data Sources tab.



Selecting your data to create graphs and tables

In order to show your data in a bar chart or a graph, you will need to use Queries to return the desired information from your database. Queries are how Grafana panels communicate with data sources to create a visualization. Read more about Querying a Data source.

In Grafana you can write a SQL query if you want to, but you can also use the UI provided to skip the coding part, or even use both. Let's see how to get data from a device and show it in a table or a graph using only the Query Builder.

Before we continue, the data I'll be using is being generated from the "Freezer Simulator" plugin, which can be found inside TagoCore > Plugin Store.

Let's get started!

  1. Open Grafana and click on the "Create" button on the left sidebar;

  2. Here you will find a few options that you can explore later, but for now, select "Add a new panel";

  3. A new screen will appear with tons of options to configure. Take a look at the scheme below to understand at a high level what they do:

  4. Now, it's time to select the exact data to display in the graph. However, we need to tell Grafana where this data is located in my database table. So let's take a look at my data source table before querying on Grafana. In my case, I'm using MySQL database, here it is:


As you can see, there's a lot of information here, but in order to plot this on a chart, we need to specify which data to show. In this case, I want to show the internal_temperature value in a time series graph;

  1. To do that, head back to your recently created Panel, and let's use the Query Builder to filter only the internal_temperature value, and plot in a time series chart.

    Note: Instead of using the Query Builder, you can also write your SQL query right away by clicking on the button "Edit SQL". The language supported is the same for your database server. Read more.

  2. First, in the Query Builder, select your Data source, and in the field "From", select the table you want to show the data. 


You will notice that nothing happened in your panel, or maybe some error message appeared, but no data sample. If you want to see the results of your query, you can switch the option "Table view" here:
 


Note: If you still don't see any data yet,  you might have to remove the filter "Macro: $_timeFilter" in the "WHERE" field. This filter is there as default and has no function for us now. Remove it by clicking on it, and selecting "remove".

  1. Now that we selected the right table, let's filter only the "internal_temperature" rows. In the "Select" field, you can choose what column you want to use as a data source for your graph, in our case, the internal temperature values generated by the device are being stored in the column "value". So, click on the "SELECT" field and type "value".



  1. You will notice that in the Table view, all data in the "value" column was selected, however, we only want the values related to the internal temperature. So, in the "WHERE" field, we will tell which data will be shown in your graph. Let's take a look at our data source table inside the database to identify where the temperature is:


The temperature values are only in the rows where the column "variable" contains "internal_temperature". So we can say that the values for temperature are only where variable = 'internal_temperature". Now let's apply this filter to the query builder.

  1. First, remove the default "Macro: $_timeFilter" if you haven't done it by now, and add a new one by clicking on the "+" button in the WHERE field, and selecting "expression". You should have something like this:


Now, let's filter only the internal_temperature by writing
variable = 'internal_temperature'. Like this:


If you switch to "Table view" you will notice that only the temperature variable was filtered.


Note: You can change the name of the "value" column by adding an "alias". All you need to do is click on the "+" button in the SELECT field, choose "Alias" and edit the value for the name you want to; here, I will be using "Temperature".


  1. At this point, we did the hard job of filtering the specific data you want to show, however, we still need to do some data preparation. That's where the tab "Transform" comes in handy, as there you will find a lot of options like concatenate fields, add formulas, change the data type, join tables, and much more.

    In this case, I'll need to change my data type because I got the following error after deactivating the "Table view" option. You can see in the image below, that my column "value" is not a numeric data type, and for that reason, the graph cannot show data. Let's change that in the following step.

  2. To convert the column "value" to a number data type, we need to access the "Transform" tab and select the "Convert field type" option. Now, just fill the fields to convert your data into a numeric type.


    By now you will probably have a graph like this:


  1. Now, just give your panel a Title, save it, and you have your first dashboard receiving real-time data! You can explore even more functionalities by customizing your graph in the options on the right side of your screen.


Hope you had an idea of how to use Grafana to create views to show your data, just like the Widgets on TagoIO, but with a little bit more work to prepare the data.


If you have any questions, feel free to add a comment below!

Thanks!
Phil Gutierre





        Take a look at our updated roadmap here!
          What would you like to see on TagoIO?