当前位置:网站首页>Preliminary study on temporal database incluxdb 2.2
Preliminary study on temporal database incluxdb 2.2
2022-07-04 07:31:00 【sp42a】
What is a time series database ? There is no popular science here , Please Baidu . Timing data is a scenario of writing more and reading less .
InfluxDB use Go Language writing , Open source , It should be good . But the disadvantage is : The stand-alone version is free and open source , There is a charge for the cluster version .
install
Download the database separately Server And command line tools CLI, Two separate programs . After installation , perform influx start-up Server, Pay attention to exposure 8086 Default port .
influx
This is a temporary start , We changed the daemon to execute ,
nohup ./influx &
Then on Server Configure accordingly , Yes WebUI The interface of , Visit its 8086 Web The service can be , As shown in the figure below .
Set the initial user , All required items .
Successful initialization .
Java Client calls
Our application is Java, So do it :
<dependency>
<groupId>com.influxdb</groupId>
<artifactId>influxdb-client-java</artifactId>
<version>6.1.0</version>
</dependency>
Measurement
Excerpt from netizens :
In a relational database , We are all on the watch table Query data in , According to the understanding of inertial thinking , Will also put influxdb Of measurement Understood as a table , Then when you query, you will naturally bring
_measurement
, However, in the actual query, this is only used as influxdb Query criteria for , In fact, it is an optional condition , Even if not, it can still be queried correctly . But when writing, you must measurement Of .It can also be seen from here ,influxdb Of measurement With a relational database table Not exactly a concept , stay influxdb in measurement It's just bucket As a grouping .influxdb In fact, there is only one data structure , therefore measurement It's the only one ,measurement It will be automatically created when writing data , If the data does not exist ,measurement It will disappear naturally .
Simply compare the two :
Write data
Writing tools can support :influx Command line or API client , For example, we write Java It is officially provided Java-client. Writing mode can support Line protocol Data format or Java Entity Bean, recommend Java Bean intuitive .
asynchronous / Sync
Java Data written by the client can be divided into synchronous writing and asynchronous writing .
WriteApiBlocking writeApi = client.getWriteApiBlocking(); // Blocking , Synchronization
WriteApi makeWriteApi = client.makeWriteApi(); // Non blocking , Asynchronous
Better asynchronous performance , You can write to the database once in either of the following two cases :
- Timer flush operation , Such as once a second
- Write data to 5000 pen , Write once , Control this quantity to
batch_size
( Adjustable )
Before writing data , Data is overstocked buffer In cache .
// write in , Specify a precision of ns nanosecond
writeApi.writeMeasurement(WritePrecision.NS, vo);
Browsing data
Database tools we will think NativeCat And so on. , but influx What about ? Please rest assured that it is officially provided UI Tools , And it's beautifully made , Access the deployment location with a browser , Such as http://localhost:8086, Click on Data Explorer You can browse .
Flux
Flux(flux: n. Traffic ; Changes ; unstable ; Flow out ; vt. Melt ; Treat with flux ; vi. melt ; Flow out ) yes InfluxDB 2.0 A query language introduced , The new version v2 Abandoned v1 Similar SQL grammar , Completely use self-made query methods , be called "Flux". Every Flux Queries need to include the following parts :1. data source ,2 Time range ,3 Data filters .
data source :bucket Identify the name of the database
from(bucket:"example-bucket")
Time range ,stop It's not necessary , The time range can be a specific time (UTC Time ) Or timestamps , It can also be a relative time range , Such as -1h
Show the past 1 Data in hours ( Relative to the current time ), Optional units are s,m( minute ),h,d,mo( month ),y
|> range(start: -1h, stop: -10m)
When querying time series data ,Flux Need a time frame ." unbounded " Queries are very resource intensive , As a protective measure ,Flux The database will not be queried without a specified range .
Data filters , Multiple filters can be used and
or or
Connect , Or start another filter
|> filter(fn: (r) =>)
filter The optional values for are :_measurement ,_field ,_value,_time, Some tag The name of
Generate query data ( Optional )
|> yield()
The output table usually contains :_start, _stop, _field,_value, _measurement,_time,[tag name ]
Field
Every flux Grammar is written in “from” Start , Every other part needs to be marked with " |>
" start .
About Tag Field
Start using Flux when , Find even simple SQL where
The specified condition query cannot be done , Very disappointed ! I asked a lot and didn't know , Later, I read the English documents tag Talent inspiration , There is no designation tag Why .influx in , Distinguish ordinary field and tag field, The former is not indexed , So it can't be searched , The latter can . So when you want to search a field , It must be specified as tag field, Like the one below uavId
Field
/** * The battery 、 voltage */
@Measurement(name = "Power")
public class Power extends InfluxValueObject {
@Column(tag = true)
public String uavId;
@Column
public Integer batteryRemaining;
@Column
public Float voltageBattery;
}
If you build too many indexes , write in 、 Query performance will decline .
Two kinds of function
The first one is : aggregate function; The second kind :selector function. The most important difference between these two types of functions is ,aggregate funciton Is to return a data record through aggregation ;selector funciton Is to return a set of original data . These two kinds of functions can be mixed in some places , Sometimes you can't .
similar SQL Of OR
perhaps IN
Inquire about
- stay filter Use in
or
Connect :|> filter(fn: (r) => r.eq == "1" or r.eq == "2")
- Use
contains
function : stay from Previously defined arrayfields = ["1", "2"]
, And then in filter Use in|> filter(fn: (r) => contains(value: r.eq, set: fields))
The data backup
Reference resources :https://www.sunzhongwei.com/influxdb-20-data-backup-recovery-exportimport?from=bottom
边栏推荐
- [C language] open the door of C
- Zephyr 學習筆記2,Scheduling
- 手写简易版flexible.js以及源码分析
- MYCAT middleware installation and use
- 【森城市】GIS数据漫谈(一)
- Zephyr 学习笔记1,threads
- With excellent strength, wangchain technology, together with IBM and Huawei, has entered the annual contribution list of "super ledger"!
- L1-024 the day after tomorrow (5 points)
- 大学阶段总结
- Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
猜你喜欢
Guoguo took you to write a linked list, and the primary school students said it was good after reading it
BUUCTF(3)
socket inet_ pton() inet_ Ntop() function (a new network address translation function, which converts the expression format and numerical format to each other. The old ones are inet_aton(), INET_ ntoa
[network security] what is emergency response? What indicators should you pay attention to in emergency response?
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
[kubernetes series] kubesphere is installed on kubernetes
Unity 从Inspector界面打开资源管理器选择并记录文件路径
果果带你写链表,小学生看了都说好
Used on windows Bat file startup project
随机推荐
《剑指Offer》第2版——力扣刷题
Handwritten easy version flexible JS and source code analysis
大学阶段总结
[FreeRTOS] FreeRTOS learning notes (7) - handwritten FreeRTOS two-way linked list / source code analysis
MySQL中的文本处理函数整理,收藏速查
Redis - detailed explanation of cache avalanche, cache penetration and cache breakdown
How to buy financial products in 2022?
Computer connects raspberry pie remotely through putty
Amd RX 7000 Series graphics card product line exposure: two generations of core and process mix and match
Vulhub vulnerability recurrence 77_ zabbix
[Mori city] random talk on GIS data (I)
Master-slave replication principle of MySQL database
提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
Zephyr 学习笔记2,Scheduling
Zephyr 學習筆記2,Scheduling
Chain ide -- the infrastructure of the metauniverse
Research on an endogenous data security interaction protocol oriented to dual platform and dual chain architecture
手写简易版flexible.js以及源码分析
Finishing (III) - Exercise 2
MySQL中的文本處理函數整理,收藏速查