IoT Time Series Data with InfluxDB
InfluxDB is a Time Series NoSQL database specifically built for use cases centred around IoT/sensor data. This is a brief technical introduction into InfluxDB as well as analytics on InfluxDB using Knowi.
Internet of Things — the umbrella term for network aware devices, wearables, home, cars and other connected devices — appears to be shedding its hype and starting to coming of age. The projections are certainly eye-popping, with an expected 50–200 billion connected devices by 2020, $1.7 trillion in spending, and 173 million wearable devices by 2019.
Given the volume and velocity of sensor data, NoSQL databases are often the preferred option for storing such types of data. This has typically been the domain of data stores like Cassandra, HDFS and Graphite. More recently, Druid and InfluxDB have been coming up the ranks, databases that are specifically catered towards storing time series data.
InfluxDB does not require a schema defined upfront. Queries are enabled using a nice SQL-like syntax with easy extensions for time based queries. Write and Query APIs are exposed through a REST API.
Given its focus on time series databases, data is always stored with a timestamp component, which acts like a primary index.
It uses a Line Protocol format, with measurements (like a SQL table), tags (like an indexed column) and fields (an unindexed column).
<measurement>[,<tag-key>=<tag-value>…] <field-key>=<field-value>[,<field2-key>=<field2-value>…] [unix-nano-timestamp]
stock,symbol=AAPL bid=127.46,ask=127.48 1434067467100293230
Stock is a measurement; Symbol is a tag; bid and ask are fields. The number field is an optional unix timestamp in nanoseconds.
InfluxDB is straightforward to download and setup.
a. Download the package.
b. Start the service.
To import some test data:
curl https://s3-us-west-1.amazonaws.com/noaa.water.database.0.9/NOAA_data.txt > NOAA_data.txt
(Water level data from the National Oceanic and Atmospheric Administration)
Insert: influx -import -path=NOAA_data.txt -precision=s
Queries can be executed against InfluxDB using InfluxQL, a SQL-like syntax to query data stored in InfluxDB. Example:
SELECT * FROM mydb WHERE time > now() — 1d
This returns all tags & fields for the mydb measurement for last day.
Knowi provides native integration into InfluxDB to be able to query, aggregate, visualize, analyze data from InfluxDB, as well as allowing multi-datasource joins with your polyglot persistence architectures (data across various NoSQL, SQL, REST API’s and files), all the way to produce interactive dashboards for non-technical users.
It’s also worth noting that InfluxData provides Chronograf, a visualization tool to interface with InfluxDB. This might be an option to consider for time series charts, if you are planning to store all your data in InfluxDB alone.
To see InfluxQL in action:
- Go to InfluxDB Instant Visualization page at Knowi. It’s configured with a live InfluxDB database and InfluxDB queries.
Note: The query generator section can be used to discover measurements, tags & fields and build basic InfluxQL dynamically.