Inhaltsverzeichnis
< Alle Themen

PulseSensor – Grafana configuration

Grafana

For the purpose to visualize the telemetry data coming from our PulseSensor Project we require to configure Grafana to read and display the real-time data stream.

Adding the Eclipse Kapua™ data source

Eclipse Kapua™ leverages the ElasticSearch Time-Series database to store all telemetry data which it does receive via MQTT and its built-in MQTT Broker (see example here).

The ElasticSearch DB container is part of the overall Eclipse Kapua™ Docker installation, and it listens per default on port 9200. This is one of the parameters which we  need to know when configuring the data source within Grafana.

Another important parameter which we need to know is the index where Eclipse Kapua™ stores its data in. This is comparable to a database name in rational databases.

To find out which index Eclipse Kapua™ uses to store its data, we can query for this information using the ElasticSearch API in a browser:

http://<Server-IP>:9200/_cat/indices?

green open 4782942282088783468-data-metric          ph5hSCGJRHWrbA49j6ByYw 1 0       4 65  23.5kb  23.5kb
green open 4782942282088783468-data-message-2021-44 GPJt5EEkQumDRdLjEuuBdg 1 0 1695558  0 312.7mb 312.7mb
green open 4782942282088783468-data-client          aDLVwMuNS6iHhPFB1rSSLQ 1 0       1  0   4.7kb   4.7kb
green open 4782942282088783468-data-channel         -Ex2jbkIT6Kogs529rKt0g 1 0       1  0   5.1kb   5.1kb

The index we are looking for is ‘4782942282088783468-data-message-2021-44’  and we need to acknowledge that this index changes each week. The suffix ‘2021-44’  represents the current week we are in.

With the index and the IP port our ElasticSearch DB is listening on, we are ready to configure the data source in Grafana. Only additional information we need is the ElasticSearch version our Eclipse Kapua™ is running on. This is currently 7.8.1.

Go to [Configuration] -> [Data source] and select ElasticSearch from the data sources which are being loaded as plug-ins per default from Grafana after  new installation.

Now let’s apply the configuration parameters:

  • Name = “ElasticSearch-Pulsesensor” (or whatever name you like)
  • URL = “http://<Your Server-IP>:9200
  • Index name = “4782942282088783468-data-message-2021-44
  • Time field name = “timestamp”
  • Version = “7.7+”

As for now, we leave all other parameters as default.

Once we [Save & test] our configuration, we receive a positive acknowledgement in case all parameters are correct.

Adjusting Dashboard refresh times

Each Grafana Dashboard can be refreshed which means new data are read from the underlying data source and the plot is updated accordingly. The minimum refresh time per default is 5seconds, which can bring down to 1sec by adding a configuration parameter to the ‘etc/grafana/grafana.ini’ configuration file.

#################################### Dashboards History ##################
[dashboards]
# Number dashboard versions to keep (per dashboard). Default: 20, Minimum: 1
;versions_to_keep = 20

# Minimum dashboard refresh interval. When set, this will restrict users to set the refresh interval of a dashboard lower than given interval. Per default this is 5 seconds.
# The interval string is a possibly signed sequence of decimal numbers, followed by a unit suffix (ms, s, m, h, d), e.g. 30s or 1m.
min_refresh_interval = 1s

# Path to the default home dashboard. If this value is empty, then Grafana uses StaticRootPath + "dashboards/home.json"
;default_home_dashboard_path =

#################################### Users ###############################
Allow anonymous login

We want to allow anonymous users such as our app to login without providing any credentials.

#################################### Anonymous Auth ######################
[auth.anonymous]
# enable anonymous access
enabled = true

# specify organization name that should be used for unauthenticated users
;org_name = Main Org.

# specify role for unauthenticated users
;org_role = Viewer

# mask the Grafana version number for unauthenticated users
;hide_version = false
Allow embedding panels in other applications

We want to allow to embed a panel in our app, so we need grant permission for that in the [security] section of the Grafana configuration

#################################### Security ####################################
[security]
# set to true if you want to allow browsers to render Grafana in a <frame>, <iframe>, <embed> or <object>. default is false.
allow_embedding = true

After this configuration change and a restart of the Grafana container it is now possible to add 1s in the respective Dashboard properties and to save the settings (isn’t possible to save the dashboard settings without prior to add the ‘min_refresh_interval’ property  in the grafana.ini file).

Creating a dashboard for our Pulsesensor data

Grafana is really a great tool for a rapid composition of various different views on data. Dashboards are composed out of one or multiple panels, each panel representing a specific view on a subset of the data to be displayed.

Creating a panel for the Live Measurement raw data

For creating a panel which continuously plots live measurement data from our PulseSensor, we add a panel and configure it this way:

  • Panel-name (e.g. Live Measurement – Raw data)
  • Visualization type: TimeSeries
  • Data source is always ‘Grafana’ for measurement data coming from the Live API.
  • Time range: now-2min to now
  • Channel can be found in the drop-down menu (stream/pulsesensor/mqtt_consumer[n msg/min])
  • Fields (time, LatestSample)
Creating a panel for the Live BeatsPerMinute (BPM) data (speedometer)

For creating a panel which continuously plots live measurement data from our PulseSensor, we add a panel and configure it this way:

  • Panel-name (e.g. Live Measurement – BeatsPerMinute)
  • Visualization type: Gauge
  • Data source is always ‘Grafana’ for measurement data coming from the Live API.
  • Time range: now-1min to now
  • Channel can be found in the drop-down menu (stream/pulsesensor/mqtt_consumer[n msg/min])
  • Fields (time, BeatsPerMinute)
  • Threshold:80
Creating a panel for the Live BeatsPerMinute (BPM) data (discrete)

For creating a panel which continuously plots live measurement data from our PulseSensor, we add a panel and configure it this way:

  • Panel-name (e.g. Live Measurement – BeatsPerMinute)
  • Visualization type: Stat
  • Data source is always ‘Grafana’ for measurement data coming from the Live API.
  • Time range: now-1min to now
  • Channel can be found in the drop-down menu (stream/pulsesensor/mqtt_consumer[n msg/min])
  • Fields (time, BeatsPerMinute)
  • Threshold:80
Creating a panel for the Historical  raw data

For creating a panel which plots historical measurement data from our PulseSensor, we add a panel

  • Panel-name (e.g. Historical Data – Raw Data)
  • Visualization type: Time Series
  • Data source is Elasticsearch-PulseSensor.
  • Time range: now-15min to now
  • Metrics: Average metrics.LatestSample.int
  • Group by: Data Histogram timestamp
Creating a panel for the Historical  BeatsPerMinute (BPM) data

For creating a panel which plots historical BPM value data from our PulseSensor, we add a panel

  • Panel-name (e.g. Historical Data – BeatsPerMinute)
  • Visualization type: Time Series
  • Data source is Elasticsearch-PulseSensor.
  • Time range: now-15min to now
  • Metrics: Average metrics.LatestSample.int
  • Group by: Data Histogram timestamp
PulseSensor Dashboard overview

All four panels which we just created can now be arranged on the dashboard. Ideally we create two rows, one row which hosts the panels for live data, and another row for panels with historical data. A good practice is to set the refresh time to 5 minutes and a time range to plot data of 2 minutes. Unfortunately, Grafana does not support yet (based on our current knowledge) to set time ranges and refresh times on a per panel level.