Open main menu

DAVE Developer's Wiki β

Changes

m
==Introduction==
When dealing with IoT fleets, one of the major concerns is to monitor the devices' health status. The "health status" is a generic expression that may include tons of parameters, ranging from the system-on-chip's temperature to the number of processes running in Linux's user space.
This Technical Note (TN for short) illustrates how to combine some well-known, open-source software to implement a monitoring system for such devices. It is based on:
* [https://grafana.com/ Grafana]: ''visualization and analytics software''.
* [https://www.influxdata.com/ InfluxDB 2.0]: ''a time series database''.
* [https://nicolargo.github.io/glances/ Glances]: ''a cross-platform system monitoring tool written in Python''.
 
In essence, the example described implements the following scheme.
 
[[File:MISC-TN-029-BD.png|center|thumb|600px]]
 
 
The IoT device used for this TN is an [[MISC-TN-004:_Running_Debian_(armbian)_on_SBCSPG|SBCSPG IIoT gateway]] running Debian [[MISC-TN-026:_Automated_test_equipment_(ATE)_monitoring_with_SBCSPG_gateway,_ThingsBoard_IoT,_and_Fledge|Bullseye]] GNU/Linux distribution. An instance of Glances runs on SBCSPG for collecting data (CPU load, memory usage, network traffic, etc.). These data are pushed into an InfluxDB database. Grafana retrieves these data from the database and shows them in a beautiful dashboard.
 
For the sake of simplicity, Grafana and InfluxDB were installed on the same host running Ubuntu 20.04, but they can indeed run on different machines.
 
==Installing InfluxDB 2.0 and Grafana==
Please follow the instructions available [https://medium.com/@nanditasahu031/integration-of-influxdb2-with-grafana-28b4aebb3368 here], but refer to [https://repos.influxdata.com/ these page] for the InfluxDB GPG key to use.
 
For convenience, a ready-to-use dashboard was installed, which is available [https://grafana.com/grafana/dashboards/2387-glances-for-flux/ here].
 
For accessing the bucket from Grafana, use the API token provided by InfluxDB. It can be copied from the page shown in the following picture.
 
 
[[File:Sbcspg-glances-grafana-2.png|center|thumb|600px|Getting the API token from Grafana]]
 
 
==Installing Glances on the IoT device==
For convenience, a Python 3 virtual environment was created on the device first. Then, all the necessary packages were installed as illustrated in the following dump.
 
<pre class="board-terminal">
armbian@sbcspg:~/devel/glances$ python3 -m venv ~/devel/glances/venv/
armbian@sbcspg:~/devel/glances$ source env/bin/activate
-bash: env/bin/activate: No such file or directory
armbian@sbcspg:~/devel/glances$ source venv/bin/activate
(venv) armbian@sbcspg:~/devel/glances$ pip install glances bottle influxdb
Installing collected packages: typing-extensions, reactivex, influxdb-client, ciso8601
Successfully installed ciso8601-2.3.0 influxdb-client-1.37.0 reactivex-4.0.4 typing-extensions-4.8.0
</pre>
 
The next steps consists of creating a configuration file suitable for our setup.
<pre class="board-terminal">
(venv) armbian@sbcspg:~/.config/glances$ cp -v ~/devel/glances/venv/share/doc/glances/glances.conf .
'/home/armbian/devel/glances/venv/share/doc/glances/glances.conf' -> './glances.conf'
</pre>
 
In particular, make sure the the <code>influxdb2</code> section is edited properly for matching your setup:
<pre class="board-terminal">
...
[influxdb2]
# Configuration for the --export influxdb2 option
# https://influxdb.com/
host=192.168.0.21
port=8086
protocol=http
org=nicolargo
bucket=glances
token=ZWZfgKt6O_GS38xzRZIAEFwXfeCh1pyYIDfBXFaeGig9eJvzdi1pFKseXVq8n-rkJ1MD-7mPS>
# Set the interval between two exports (in seconds)
# If the interval is set to 0, the Glances refresh time is used (default behavo>
#interval=0
# Prefix will be added for all measurement name
# Ex: prefix=foo
# => foo.cpu
# => foo.mem
# You can also use dynamic values
#prefix=foo
# Following tags will be added for all measurements
# You can also use dynamic values.
# Note: hostname is always added as a tag
#tags=foo:bar,spam:eggs,domain:`domainname`
...
</pre>
 
Once the configuration file is in place, Glances can be started in quiet mode as follows:
<pre class="board-terminal">
(venv) armbian@sbcspg:~/.config/glances$ glances -q --export influxdb2
</pre>
 
If everything works as expected, collected data are displayed live in the Grafana's dashboard:
[[File:Sbcspg-glances-grafana-1.png|center|thumb|600px|Grafana dashboard showing collected data]]
4,650
edits