Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle and usage of influxdb

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Today, I will talk to you about the principle and usage of influxdb, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

What is influxdb?

Influxdb is an open source database developed by the go language for storing and analyzing time series data. The features are as follows:

Built-in HTTP interface, easy to use

The data can be marked and checked so that the query can be very flexible.

Query statement like SQL

Installation and management is simple, and reading and writing data is efficient.

It can be queried in real time, and the data can be found immediately after it is indexed when it is written.

Support for data storage policy (RP) and data archiving (CQ)

For more descriptions, see the influxdb official description.

Influxdb installation

We can download the binary installation directly from the official or install it based on the docker image. To install based on the docker image, execute the following command

Docker run-d-name influxdb-p 8860 purl 8086\

-v $PWD/influxdb.conf:/usr/local/influxdb/influxdb.conf:ro\

-v $PWD:/data/influxdb\

Influxdb-config / usr/local/influxdb/influxdb.conf

Parameter description:

-d: run the container in the background and print out the container id

-- name influxdb specifies the name of the container

-p 8081Plus 8082 specifies port mapping, mapping port 8860 of the host to port 8086 of the container

-v $PWD/influxdb.conf:/usr/local/influxdb/influxdb.conf:ro mounts the influxdb.conf under the current directory to the container's / usr/local/influxdb/influxdb.conf directory. Because the path permission of the default mount is read-write, you can limit the permission to read-only through ro to prevent the configuration file from being modified in the container.

-v $PWD:/data/influxdb mounts the current directory to the container's / data/infludb directory. In this way, we can specify the data file of infludb and write it to the / data/infludb directory, so that the data can be removed from the disk.

Related concepts of influxdb

Before using infludb, let's take a look at some of its concepts, such as database, Retention Policy, measurement, Continuous Query, point, field, tag, and so on. First of all, get to know it as a whole:

1 、 database

Database is a database, which can be compared to mysql, mongo and other databases.

Create database "test"-create a database

Show databases-show all databases

Use test-choose the database to use

2 、 Retention Policy

Retention policy, namely storage policy, or RP for short, is used to control the storage time of the database. InfluxDB compares the local timestamp of the server with the timestamp of your data, and deletes data that is older than the duration in RP. There can be multiple RP in a single database, but the RP for each data is unique. The related operations of RP are as follows:

View the rp of the database test

SHOW RETENTION POLICIES ON "test"

Create a new rp for the test database

CREATE RETENTION POLICY "rp_name" ON "db_name" DURATION 3w REPLICATION 1 DEFAULT

Rp_name:RP Policy name

Db_name: specific database name

3w: set the data to be saved for 3 weeks, and the data from 3 weeks ago will be deleted. Infludb has various time parameters, such as h (hours), d (days), w (weeks).

REPLICATION 1: the number of copies, just fill in 1 here.

DEFAULT is set as the default policy.

Modify the rp of the database

Modify rp using the following command:

CREATE RETENTION POLICY "rp_name" ON "db_name" DURATION 3D DEFAULT

Delete rp of the database

DROP RETENTION POLICY "rp_name" ON "db_name"

3 、 measurement

Measurement, which can be compared to tables in traditional databases. The traditional database supports additions, deletions, changes and queries. Infludb only supports additions and queries. Deletion can be achieved with RP.

Data insertion

Influxdb supports http and rpc to insert data. Of course, it also supports inserting data on the command line, as follows:

Use test-using the test database

Insert weather,altitude=1000,area= North temperature=11,humidity=-4

Where:

Weather: table name, that is, the name of measurement

Altitude=1000,area= north is tag, and tag can be understood as an indexed column in mysql.

Temperature=11,humidity=-4 is field,. Field can be understood as a column in mysql without an index.

For each inserted data, influxdb automatically adds a column named time, which is used to record the time of the current data.

Query of data

Influxdb supports where, group, order, limit and other words. As follows:

Select * from weather order by time desc limit 5

4. Continuous query (Continuous Queries)

The data in the influxdb will be deleted when the time specified in the save policy is exceeded. What if we don't want to delete it, but are worried about too much capacity? The data can be archived with larger granularity, that is, at the expense of reduced accuracy. For example, the original data per second is archived as minute data, and the original minute data is archived as hourly or daily data, so that more data can be stored when the capacity is fixed. In influxdb, this operation is called continuous query (Continuous Queries).

View the Continuous Queries of the database

SHOW CONTINUOUS QUERIES

Create Continuous Queries

1CREATE CONTINUOUS QUERY cq_3d ON testDb BEGIN SELECT mean (age) as age INTO test_3days FROM test GROUP BY time (3D), * END

Where: cq_3d: the name of the continuous query

TestDb: the specific database name.

Mean (age) as age: calculates the average of age, and changes the field name to age

Test: measurement name, that is, which table in the base database is archived

Test_3days: measurement name, the name of the table stored after the data is archived.

3D: the frequency of archiving, that is, once every 3 days.

*: perform group by operations on all tag. Of course, we can also group by operations based on a specific tag. It is important to note that for which tags operations are performed, there will be tags in the archived table test _ 3days.

Delete Continuous Queries

The delete operation command is as follows:

DROP CONTINUOUS QUERY ON

After reading the above, do you have any further understanding of the principle and usage of influxdb? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report