calaos / calaos_base

Calaos server
https://calaos.fr
GNU General Public License v3.0
160 stars 37 forks source link

Dev/naguirre/influxdb #145

Closed naguirre closed 4 years ago

naguirre commented 4 years ago

This PR add support for influxdb data logging into calaos_server.

What's needed

One instance of Influxdb up and running at IP:PORT

Configure Calaos_server

Configuration is located in local_config.xml

calaos_config set influxdb_host 127.0.0.1
calaos_config set influxdb_port 8086
calaos_config set influxdb_database calaos
calaos_config set influxdb_enabled true
calaos_config set influxdb_log_timeout 300

Configure IO

Enabling IO logging is done in configuration per IO, by adding logged=true in io.xml file

Example of configuration :

<calaos:input enabled="true" gui_type="temp"  id="io_3" io_type="input" logged="true" name="T°" visible="true"  ...../>

Behaviour

At calaos_server startup, the database influxdb_database is created if it doesn't exists. Each time an IO with logged=true configuration changed, value is send to influxdb host. At startup and after a timeout of influxdb_log_timeoutseconds expires, all data marked as logged_true are send to influxdb host.

Schema used for influxdb logging is the following :

IOName,room=ROOM value=XX TIMESTAMP

Once data are insterted in influxdb database, they can be retrieve by using requests :

curl -G 'http://127.0.0.1:8086/query' --data-urlencode "db=calaos" --data-urlencode "q=SELECT \"value\" FROM \"T°\" WHERE \"room\"='livingroom'"