A few years ago, we showed you how to integrate Yoctopuce sensors in a Grafana dashboard used with InfluxDB, which was a very common solution at the time. In the mean time, GrafanaLabs has set its sights on another time-series database, Prometheus, which offer many more possibilities to extract data than InfluxDB. We have therefore added to our modules the possibility to provide their data in a format directly recognized by Prometheus.
Prometheus / Grafana 's target scenario
Before going into details, let's clarify that Prometheus and Grafana are not designed to provide a real time visualization of sensor data, second by second. To do this, we recommend rather Yocto-Visualization, which will be easier to implement and more responsive.
The true aim of Prometheus is to periodically collect hundreds of measures issued from multiple sources, to store them, to query them efficiently, and to potentially trigger alarms. Grafana then allows you to visualize the measure history on a given time range to detect and analyze abnormal situations.
Architecture of a Prometheus system
In the opposite to InfluxDB, Prometheus works by polling: it is the Prometheus server which periodically contacts the sources to collect the measures at the selected frequency, and not the sources which spontaneously post their measures in the data base. This choice implies that you need in any case to install you own Prometheus server on your local network, so that it can access your data sources and your sensors. You can then synchronize your local Prometheus server with a Cloud service, but the data collection must be performed by a local server.
Prometheus data sources are called exporters: the idea is that each important system or service can make its vital data available to Prometheus, enabling the system administrator to collect and monitor them. Each exporter is an HTTP accessible URL, which provides data following the OpenMetrics standard: one measure per line, with conventions for naming and classifying, enabling the system administrator to find his/her way among the hundreds of measures at disposal when configuring the dashboard.
To get the best possible integration with Prometheus, we have built into Yoctopuce devices and into the VirtualHub software the capability to be native OpenMetrics exporters. Up to now, Yoctopuce modules could export their measures in the following formats: JSON, XML, and simple text, via a REST interface described in more the documentation in the chapter titled Using with unsupported languages. This same REST interface now enables you to obtain data in the OpenMetrics format by using the .om file extension. For example, if you load the /api/services.om URL on a YoctoHub-Ethernet, you obtain something akin to this (we modified the presentation to make reading easier, but in reality each measure fits on a single line):
To tell Prometheus to collect these data directly from your YoctoHub-Ethernet, you must add to your prometheus.yml a file section of this type:
- targets: ['192.168.0.100:4444']
And here is the kind of graph that you can get from Yoctopuce sensors in Grafana:
Temperature measurements in Grafana
As our OpenMetrics exporter is embedded straight into the REST interface, you can use it to obtain more detailed information for each sensor. For example, if you assign to a Yocto-Thermocouple the logical name tcProbes amd that you query the URL /byName/tcProbes/api.om URL, you obtain something like:
Thus, all the numerical attributes are made available. You can therefore know the min/max values encountered, the voltage measured at the thermocouple terminal, and so on. Note also that in this case, the exported symbol includes the unit, as recommended by OpenMetrics. When the module detects that an input is not connected (like the temperature2 function above), metrics that cannot be computed are automatically deleted from the export so that Prometheus reports them as missing, rather than keeping the latest measured value.
To obtain these additional data per sensor, simply add to the prometheus.yml file a new section, referencing the sensor either by its serial number (bySerial) or by its logical name (byName):
- targets: ['192.168.0.100:4444']
Here is the corresponding metrics selection interface in Grafana Web UI, for a Yocto-Meteo-V2:
Choice of Yoctopuce metrics for a Yocto-Meteo-V2 ambient sensor
As of today, we have published new firmware for the YoctoHub-Ethernet, the YoctoHub-Wireless-n and a new VirtualHub with support for the OpenMetrics format, which enables you to immediately implement the basic usage. To obtain detailed data by sensor, you will also need to update the firmware of all the sensors. We have already published new firmware for a dozen of devices, and the other modules will follow gradually, as the firmware are validated. You can recognize a firmware with OpenMetrics support by its firmware level, which should be greater than 48000. If you need a particular one urgently, don't hesitate to contact Yoctopuce support!