Skip to main content

Tutorial: Visualize Data in Spotflow Grafana

This tutorial will show you how to send your data from the Device and visualize in the integrated instance of Grafana.

Requirements

  • If you are not registered to the Spotflow IoT Platform yet, Sign Up.
  • You need to have an existing Stream. A Stream called default-stream in Stream Group default-stream-group is created automatically after you register. Create a new one if you want to use a different Stream.
  • You need to have an existing Provisioning Token

1. Configure Route to Spotflow Grafana

tip

Your Start Workspace has the Stream default-stream in the Stream Group default-stream-group already configured to route incoming data to the integrated instance of Grafana. You need to follow these steps below only if you want to use a different Stream or Workspace.

  1. Click on Data Flows in the left sidebar.

  2. Click on the Add Route button next to the stream that should be routed to the Grafana.

  3. Choose Grafana as the existing egress sink to to use. Click Next.

  4. Review the default configuration and optionally customize it. Configure the path where the we should store the Delta table. Click Create Egress Route to finish.

  5. The route to Grafana has been created! You should see an arrow going from your stream to the Egress Sink.

2. Send Data to Platform

Follow Tutorial: Send Data to Platform to send data to the Platform.

warning

Do not forget to send data to the Stream you configured in step 2!

If you successfully followed the previous steps, your Device is sending data to the Platform and the data is forwarded to the Spotflow Grafana.

Message Format

Messages routed to Grafana Egress Sink must be in the following format:

  • The Message must be a JSON document encoded in UTF-8. The document root must be an object or an array of objects. Otherwise, the message is skipped.
  • The field timestamp is required in each top-level object. The field must contain an ISO 8601 timestamp string. Otherwise, the object is skipped.
  • A field name can contain only the characters 0-9, a-z, A-Z, _, and :. It also can't start with a number. If the field name doesn't conform to this format, it's skipped.
  • A field value can be an object, a number, or a boolean. Objects are parsed recursively. Numbers are directly translated into data points; booleans are converted to 0 or 1 before that. Fields with other value types are skipped.

Example:

{
"timestamp": "2023-04-03T15:16:03+01:00",
"temperatureCelsius": 21.6,
"revolutionsPerMinute": 7200
}

One message can also contain multiple data points and nested objects:

[
{
"timestamp": "2023-04-03T15:16:03+01:00",
"machine": {
"temperatureCelsius": 21.6,
"revolutionsPerMinute": 7200
},
"weather": {
"temperatureCelsius": 18.5,
"humidityPercent": 65.8
}
},
{
"timestamp": "2023-04-03T15:17:03+01:00",
"machine": {
"temperatureCelsius": 21.9,
"revolutionsPerMinute": 7201,
},
"weather": {
"temperatureCelsius": 18.5,
"humidityPercent": 65.8
}
},
]

3. Visualize Data in Spotflow Grafana

  1. Open the link Grafana in the left sidebar.

  2. The Home page of the integrated instance of Grafana will open in a new browser tab. It answers some common questions about how you can use it. Click the menu icon.

  3. Open the link Explore in the menu.

  4. In the query editor, open the data-source picker.

  5. Select the data source that starts with device_metric. The other one contains the usage data of your Workspace.

  6. Click Select table.

  7. The Platform creates a new table from each metric it receives in any Message. It also changes the name of the metric into the snake case. Select humidity_percent.

  8. Because we want to know when the Device took the measurement, select the "time" Column.

  9. Click the + button to add another column.

  10. Choose the second column. Select value.

  11. Grafana shows only the last 50 records by default. To change this, click Order and erase the Limit.

  12. Expand the options of the big Run query button in the top-right corner. Select 5s to automatically refresh the query every 5 seconds.

  13. Scroll down to the query results. If the Device is still sending Messages, you'll see them appearing as rows in the Table and points in the Graph in real time.

note

If your program finished sending Messages, you can rerun it to see the data appearing in Grafana. You don't need to approve the Device this time because it's already registered.

What's next

  • Feel free to explore the received data and create custom dashboards, as described in the official Grafana documentation.
  • To learn more about the integrated instance of Grafana and the format it accepts, see the User Guide.
  • To develop custom streaming applications, look at Egress Sinks.