Getting Started with InfluxDB
What is InfluxDB?
InfluxDB
is an open-source time series database (TSDB) developed by InfluxData. It is written in Go and optimized for fast, high-availability storage and retrieval of time series data in fields such as operations monitoring, application metrics, Internet of Things sensor data, and real-time analytics.
What is a Time Series Database?
A Time Series Database (TSDB) is a database optimized for time-stamped or time series data. Time series data are simply measurements or events that are tracked, monitored, downsampled, and aggregated over time. This could be server metrics, application performance monitoring, network data, sensor data, events, clicks, trades in a market, and many other types of analytics data.
For more information read this article https://iotbyhvm.ooo/what-is-a-time-series-database/
Getting Started with InfluxDB
I use ubuntu 16.04 LTS OS . Follow instructions are given below:
- Download and install InfluxDB –
Read This article How to Install InfluxDB on Ubuntu and follow instructions.
- Now Check status of InfluxDB
systemctl status influxdb.service
- After Activation start Influx
influx
- First create a database
> create database mydb
- To view the list of databases
> show databases
name: databases
---------------
name
_internal
mydb
>
- For using the database
> use mydb
Note :
In influxdb we call tables as measurements and columns as fields.
We don’t need to define measurements(tables) and fields(columns). It will create measurements and add columns automatically when we insert data.
Inserting Data
Format for writing data is
measurementName field1=value1,field2=value2,field3=value3 timestamp
- The timestamp is in nanoseconds. If we don’t provide timestamp it will assign the local current timestamp.
- By default it assumes all the numbers as doubles. For integer value we have to append
i
at the end.> insert measurementName field4=12i
- String values should be in double quotes.
> insert measurementName field5="qwqw"
- For boolean values use t, T, true, True, or TRUE for TRUE, and f, F, false, False, or FALSE for FALSE
> insert measurementName field6=T
- We can use
\
character for escaping comma, space, equal and other special character in field (field) value
For more details refer official documentation
Querying Data
To select all fields from measurement
> select * from measurementName
To select particular fields
> select field1, field2 from measurement
Note :
If your mesurement name or field name contains characters such as .
#
or =
, then use double quotes
> select "field1.name", "field2.name" from "measurement.name"
Where clause
A typical usage of where clause
> select * from measurement where field1 > 12 and field2 = 'sparta' and time > now() - 1d
We can also use or
logic using separaters (
and )
.
Supported comaparaters in influxdb are
=
equal to<>
not equal to!=
not equal to>
greater than<
less than=~
matches against!~
doesn’t match against
You can learn about queries in details from official influxDB Documentation.
Pingback: Using Mq135 Sensor with InfluxDB - IoTbyHVM