Install InfluxDB on MacOS

1
2
brew update
brew install influxdb

To run influxDB at startup, run this command

1
ln -sfv /usr/local/opt/influxdb/*.plist ~/Library/LaunchAgents

Now, to start InfluxDB, run this command(Accept the request of incoming connections in the window that appears)

1
influxd -config /usr/local/etc/influxdb.conf

Check if InfluxDB works

InfluxDB exposes an API with which one can easily check its good working condition. Here’s what you will receive in return for this curl command

1
2
3
4
5
6
curl -sl -I localhost:8086/ping
HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: 95b307f8-5d6b-11e7-8002-000000000000
X-Influxdb-Version: v1.3.0
Date: Fri, 30 Jun 2017 08:10:31 GMT

Terminology, difference with SQL database

Like all non-relational database, InfluxDB for its own vocabulary your need to know before starting

  • Measurement is equivalent to SQL table

  • Tags is similar to a indexed column in a SQL database

  • Fields is similar to the column not indexed in a SQL database

  • Points is equivalent to line(row) in a SQL database

Database Management Methods

There are 6 methods to manage database

  • CREATE DATABASE

  • DROP DATABASE

  • DROP SETS

  • DELETE

  • DROP MEASUREMENT

  • DROP SHARD

Create a Database

1
CREATE DATABASE <database_name> [WITH [DURATION <duration>] [REPLICATION <n>] [SHARD DURATION <shard_duration>] [NAME <retention-policy-name>]]

Basic Setting

  • database_name: name of the database

  • duration: you can set the period of data retention(conversation) but it makes more sense to implement a retention policy.

Delete a database (drop database)

1
DROP DATABASE <database_name>

Establish a retention policy

InfluxDB incorporates a system of automatic deletion of data. It is the policy of Retention. Spent some time, data is automatically deleted from the base. This mechanism is very convenient because it for a good grasp of size of the base and we don’t have to worry about the maintenance operation. Free to each set the lifetime of any particular measure. If you want to follow the temperature of its microprocessor, one less may be sufficient, instead the retention policy must be more flexible if we want to compare the temperature in a House form one year to the other. It will also think about the system upstream, you don’t have to store a measurement of atmosphere temperature every 10 seconds! A measurement per minutes, 15 minutes, that’s enough. Instead in an industrial process, we certainly want to go for the second… or a lot less.

We therefore for 3 methods

  • Create: to create a rule of conservation of data

  • Alter: to change a rule

  • Drop: to remove a rule

Create a retention policy

1
CREATE RETENTION POLICY <name_politic_retention> ON <name_database> DURATION: <duration> REPLICATION: <n> [SHARD DURATION <duration duration_shard>] [DEFAULT]

Parameters

  • name_politic_retention: a short name without spaces of preference

  • name_database: the database on which applies the retention policy

  • duration: duration of data retention. It’s a literal expression which must respect the convention InfluxDB

  • duration_shard: the duration of storage of the data in the buffer zone

  • n: number of replication(required), put 1 if no cluster installed

1
CREATE RETENTION POLICY 'one_day_only' WE 'NOAA_water_database' DURATION 1 d REPLICATION 1

This policy keeps the records during a day(one_day_only) based NOAA_water_database. The data are stored in space shard 1 day. Replication 1 indicates that a copy of each item is copied in the cluster.

Modify retention policy(alter retention policy)

This method allows to change an existing retention policy

1
ALTER ...

Destroyed a retention policy(drop retention policy)

1
DROP RETENTION ...

Discover the InfluxDB Shell

Now we know some methods, we will provide to run some test