InfluxDB first experience
What is time series data? The simplest definition is the data in the data format that contains the timestamp field. For example, the price of the stock market, the temperature in the environment, the CPU usage of the host, and so on. But what data does not contain timestamp? Almost all data can be tagged with a timestamp field. One of the more important attributes of time series data is how to query it. At the time of the query, we always bring a time range to filter the data for the time series. At the same time, the result of the query will always include the timestamp field.
|nouns in influxDB||Concepts in traditional databases|
|measurement||Tables in the database|
|points||One row of data in the table|
A Point consists of a time, a field, and a tag.
Point is equivalent to a row of data in a traditional database, as shown in the following table:
|Point Properties||Concepts in Traditional Databases|
|time||each data record time, is the main index in the database (will be automatically generated)|
|fields||various record values (properties without indexes) are also recorded values: temperature, humidity|
|tags||Various indexed properties: region, altitude|
influxdb docker container running
Docker run -p 8086:8086 -d --name influxdb -v /data/docker_volumes/influxdb:/var/lib/influxdb influxdb
For the docker operation, please refer to my previous article: https://blog.zhouzhipeng.com/tag/docker
Shell command official documentation reference: https://docs.influxdata.com/influxdb/v1.5/tools/shell/
docker exec -it influxdb influx Execute the influx command in the container running above, enter the influxdb interactive command line as follows:
[zhipeng.zhou@instance-1 ~]$ docker exec -it influxdb influx Connected to http://localhost:8086 version 1.5.1 InfluxDB shell version: 1.5.1 > >
Similar to mysql, we first create a test library using
create database test, then use
show databases to view the list of existing databases:
> create database test > show databases Name: databases Name ---- _internal Mydb Test
In InfluxDB, there is no concept of table. Instead, MEASUREMENTS, the function of MEASUREMENTS is consistent with the table in the traditional database, so we can also refer to MEASUREMENTS as a table in InfluxDB.
- n. measured value, size (multiple of measurement)
1) Display all tables
> SHOW MEASUREMENTS ERR: database name required Warning: It is possible this error is due to not setting a database. Please set a database with the command "use <database>".
An error occurred, the prompt must first
use , the same as mysql:
> use test Using database test > SHOW MEASUREMENTS >
The target does not have any tables, then we try to create one.
2) Create a table (
Since there is no explicit statement for creating a new table in InfluxDB, the new table can only be created by means of insert data. As follows:
Insert cpu_usage,ip=192.168.0.1 value=30 15226580942111
** Note that there is no into! after the insert here!!
Where cpu_usage is the name of the table, ip is the tag index, value=xx is the record value key-value pair, the record value can have more than one, and finally the specified time, the data just inserted under the query:
> select * from cpu_usage Name: cpu_usage Time ip value ---- -- ----- 15226580942111 192.168.0.1 30
3) Delete table (
drop measurement cpu_usage)
1) Add data
A row of data represents a
Point (see the basic concept above), and the
insert syntax is summarized:
Description: We can not include a timestamp when writing. When there is no timestamp, InfluxDB will automatically add the local current time as its timestamp.
2) Query operation
The query statement is the same as SQL and will not be described here.
3) Modify and delete data
InfluxDB is a time series database and does not provide a way to modify and delete data.
But deletion can be achieved through InfluxDB’s Retention Policies. Explain separately in subsequent tutorials.
to sum up
The above is just a preliminary experience, more about the other features of influxdb, will be introduced in the following articles.