| 1 |
.. SPDX-License-Identifier: BSD-2-Clause |
| 2 |
.. |
| 3 |
.. Copyright (C) 2024 Intel Corporation |
| 4 |
.. Author Walfred Tedeschi <[email protected]> |
| 5 |
.. |
| 6 |
.. Testbench documentation MQTT Integration file. |
| 7 |
.. |
| 8 |
|
| 9 |
.. _MQTT: |
| 10 |
|
| 11 |
MQTT and Grafana Integration |
| 12 |
============================ |
| 13 |
|
| 14 |
Motivation |
| 15 |
---------- |
| 16 |
|
| 17 |
With the introduction of MQTT logging the visualization if the statistics is fostered by usage of |
| 18 |
Grafana. The full chain from MQTT log to Grafana is provided with this extension. This extension |
| 19 |
provides a visualization of data in grafical format, which is desired for some use cases, e.g. long |
| 20 |
term analysis, several instances of the Linux RealTime Communication Testbench running, and |
| 21 |
showcases. The combination MQTT/Grafana is chosen as it is the most recognized and used application |
| 22 |
for data visualization, but requires additional services for the visualization. Those services are |
| 23 |
Telegraf and InfluxDB. Telegraf performs the transfer of the MQTT data into InfluxDB |
| 24 |
insertions. InfluxDB itself is the data provider for Grafana. The configuration for those services |
| 25 |
are provided allowing the direct start with data visualization with Grafana. A docker-composer file |
| 26 |
that allows that can be generated via a bash script provided. |
| 27 |
|
| 28 |
|
| 29 |
Enabling the build |
| 30 |
------------------ |
| 31 |
|
| 32 |
MQTT support is integrated in the build system as an option to enable it add the flag: |
| 33 |
|
| 34 |
.. code:: bash |
| 35 |
|
| 36 |
cmake -DCMAKE_BUILD_TYPE=Release -DWITH_MQTT=True.. |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
Configuration parameters |
| 41 |
------------------------- |
| 42 |
|
| 43 |
The parameters which affect the MQTT integration are presented in the table below: |
| 44 |
|
| 45 |
.. list-table:: Features & configure options |
| 46 |
:widths: 50 100 |
| 47 |
:header-rows: 1 |
| 48 |
|
| 49 |
* - Option |
| 50 |
- Description |
| 51 |
|
| 52 |
* - StatsCollectionIntervalNS |
| 53 |
- Interval in which a summary of the data is generated, typically 1s, i.e. 1000000000Ns |
| 54 |
|
| 55 |
* - LogMqtt |
| 56 |
- Enable and disable MQTT logging |
| 57 |
|
| 58 |
* - LogMqttThreadPriority |
| 59 |
- Thread priority for the logging thread, usually low < 7 |
| 60 |
|
| 61 |
* - LogMqttThreadCpu |
| 62 |
- Thread CPU affinity |
| 63 |
|
| 64 |
* - LogMqttBrokerIP |
| 65 |
- IP address where MQTT broker is running |
| 66 |
|
| 67 |
* - LogMqttBrokerPort |
| 68 |
- Port used by the MQTT Broker, default value is |
| 69 |
|
| 70 |
* - LogMqttKeepAliveSecs |
| 71 |
- Keep alive time for the connection, default value 60s |
| 72 |
|
| 73 |
* - LogMqttMeasurementName |
| 74 |
- Used to distinguish measurements coming from different machines. |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
Docker Composer |
| 79 |
--------------- |
| 80 |
|
| 81 |
The first step is to create the docker-composer.yml file. As there is an uncertanty about the licensing on those docker-composer files and not much to be copyrighted on those, |
| 82 |
an indirect approach to deliver the file was taken. In the docker/mqtt-composer directory the file "create_docker_composer.sh" is provided. by running that file, i.e.: |
| 83 |
|
| 84 |
.. code:: bash |
| 85 |
|
| 86 |
cd docker/mqtt-composer |
| 87 |
./create_docker_compose.sh |
| 88 |
./set_permissions.sh |
| 89 |
|
| 90 |
Creating the services |
| 91 |
^^^^^^^^^^^^^^^^^^^^^ |
| 92 |
|
| 93 |
The docker-composer.sh makes the integration into Grafana simple. |
| 94 |
A simplistic way to have the Grafana running is it can be used, is to instantiate the docker-compose in the machine where reference is running, by doing that all parameters concerning the MQTT broker are default. |
| 95 |
To instantiate the docker-composer you need docker and docker-compose installed. |
| 96 |
Start the services by issuing the commands below from the rtc-testbench directory. |
| 97 |
|
| 98 |
.. code:: bash |
| 99 |
|
| 100 |
cd docker/mqtt-composer |
| 101 |
docker-compose --compatibility up -d |
| 102 |
|
| 103 |
At this point all services needed to have the data available in Grafana is done. |
| 104 |
The most important part is now how to access the data. |
| 105 |
The verification of data availability can be done in two steps: first at InfluxDB and second via Grafana. |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
Influx Access |
| 110 |
^^^^^^^^^^^^^^ |
| 111 |
|
| 112 |
Used database for the provided configuration is "testbench" and is defined in the telegraf.conf file. |
| 113 |
The measurement name is the "LogMqttMeasurementName" provided in the configuration. |
| 114 |
The Timestamp provided is the time taken in the application side when the last frame in the recording period "StatsCollectionIntervalNS" |
| 115 |
is received, and the traffic class name is one of the columns of the measurment. |
| 116 |
This way one can investigate the data base by providing the following code when running influx: |
| 117 |
|
| 118 |
.. code:: bash |
| 119 |
|
| 120 |
use testbench |
| 121 |
SELECT * from ${LogMqttMeasurementName} |
| 122 |
|
| 123 |
where ${LogMqttMeasurementName} is a placeholder for the real name used. |
| 124 |
|
| 125 |
|
| 126 |
Grafana Access |
| 127 |
^^^^^^^^^^^^^^ |
| 128 |
|
| 129 |
Grafana can be accessed by the IP of the machine that the docker-copose was started and port defined on |
| 130 |
the docker-compose.yml file. |
| 131 |
In Grafana a new data source for InfluxDB can be created and querries added to create dashboards. |
| 132 |
|
| 133 |
Grafana Password |
| 134 |
^^^^^^^^^^^^^^^^ |
| 135 |
|
| 136 |
Grafana password has to be reset for the first usage. |
| 137 |
In some cases Grafana might also consider the password as expired refusing to allow the admin to login, e.g. extreme clock changes. |
| 138 |
To do so execute the "change_grafana_password.sh" script, with the containers running, providing the new password as parameter as below: |
| 139 |
|
| 140 |
.. code:: bash |
| 141 |
|
| 142 |
cd docker/mqtt-composer |
| 143 |
./change_grafana_password.sh $NEW_PASSWORD |
| 144 |
|
| 145 |
Grafana Example |
| 146 |
^^^^^^^^^^^^^^^^ |
| 147 |
|
| 148 |
The example provided for Grafana has the time display of the 3 Profinet real-time traffic classes, TSN-High, TSN-Low and RTC. |
| 149 |
Dials are provided to show the current maximum visualized within the visible time range. |
| 150 |
Colored bars are provided for representing the number of errors and outliers found. |
| 151 |
|
| 152 |
.. image:: images/grafana_example.png |
| 153 |
:width: 600 |
| 154 |
:alt: Grafana sample with a cicle time of 250us. |