Legacy post. This article was written between 2016 and 2018. Software versions, commands and services mentioned here may be outdated. Check the official documentation before running anything.

The goal of this tutorial is to install an InfluxDB container with Docker and work with it.

Prerequisites

Run InfluxDB on Docker

docker run -d -p 8083:8083 -p 8086:8086 \
      --name=influxdb \
      -v /usr/lib/influxdb:/var/lib/influxdb \
      influxdb

see more here

Create Database

CREATE DATABASE IF NOT EXISTS sensor

Connect to InfluxDB

influx
use sensor

Create retention policy

CREATE RETENTION POLICY one_years_only ON sensor DURATION 52w REPLICATION 1 DEFAULT

Create continuous query

CREATE CONTINUOUS QUERY cq_dht22_1h ON sensor BEGIN SELECT MEAN(temperature) AS  mean_temperature, MEAN(humidity) AS mean_humidity INTO sensor."one_years_only"."cq_dht22_1h" FROM dht22 GROUP BY time(1h), gatewayId END
CREATE CONTINUOUS QUERY cq_dht22_1d ON sensor BEGIN SELECT MEAN(temperature) AS  mean_temperature, MEAN(humidity) AS mean_humidity, MIN(temperature) as min_temperature , MAX(temperature) as max_temperature, MIN(humidity) as min_humidity, MAX(humidity) as max_humidity INTO sensor."one_years_only"."cq_dht22_1d" FROM dht22 GROUP BY time(1d), gatewayId END

Useful commands

SHOW RETENTION POLICIES ON sensor
DROP RETENTION POLICY one_years_only ON sensor
SHOW CONTINUOUS QUERIES
SELECT * FROM sensor."autogen".downsampled_dht22
DROP CONTINUOUS QUERY cq_1h ON sensor
DROP DATABASE IF EXISTS sensor