Teach you one trick to use time series database in Spring Boot
In addition to the most commonly used relational databases and caches, we have previously introduced examples of how to configure and use MongoDB and LDAP storage in Spring Boot. Next, we continue to introduce another special database: the use of time series database InfluxDB in Spring Boot.
InfluxDB Introduction
What is a time series database? The full name is time series database. Time series database is mainly used to process data with time tags (changing in the order of time, that is, time serialization). Data with time tags is also called time series data.
Time series data is mainly collected and generated by various types of real-time monitoring, inspection and analysis equipment in the power industry, chemical industry, etc. The typical characteristics of these industrial data are: fast generation frequency (one for each monitoring point) Multiple pieces of data can be generated within seconds), it is heavily dependent on the collection time (each piece of data is required to correspond to a unique time), and there are many measuring points and a large amount of information (conventional real-time monitoring systems have thousands of monitoring points. Data is generated every second, and tens of gigabytes of data are generated every day). Although relational databases can also store data based on time series, due to the disadvantages of the storage structure, these data cannot efficiently achieve high-frequency storage and query statistics. Therefore, a new method was born specifically for time series storage and optimization. database to meet higher efficiency requirements.
InfluxDB is currently a popular open source time series database (official website address: https://www.influxdata.com/). Our more common usage scenarios are some high-frequency data records and statistics related to time. Need, for example: monitoring data storage and query.
Before proceeding with the following hands-on sessions, let’s first understand a few important terms in InfluxDB:
database: database
measurement: similar to a table (table) in a relational database
points: similar to a row (a row of data) in a relational database
Among them, a Point consists of three parts:
time: timestamp
- ##fields: recorded value
- tags: Index attributes
<dependency> <groupId>org.influxdb</groupId> <artifactId>influxdb-java</artifactId> </dependency>
spring.influx.url=http://localhost:8086 spring.influx.user=admin spring.influx.password=
@Service @AllArgsConstructor @Slf4j public class Monitor { private InfluxDB influxDB; @Scheduled(fixedRate = 5000) public void writeQPS() { // 模拟要上报的统计数据 int count = (int) (Math.random() * 100); Point point = Point.measurement("ApiQPS") // ApiQPS表 .tag("url", "/hello") // url字段 .addField("count", count) // 统计数据 .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS) // 时间 .build(); // 往test库写数据 influxDB.write("test", "autogen", point); log.info("上报统计数据:" + count); } }
$ influx
> show databases
> create database "test"
2021-08-03 01:52:47.732 INFO 94110 --- [ main] c.d.chapter63.Chapter63Application : Started Chapter63Application in 2.326 seconds (JVM running for 3.027) 2021-08-03 01:52:47.764 INFO 94110 --- [ scheduling-1] com.didispace.chapter63.Monitor : 上报统计数据:25 2021-08-03 01:52:52.736 INFO 94110 --- [ scheduling-1] com.didispace.chapter63.Monitor : 上报统计数据:30 2021-08-03 01:52:57.737 INFO 94110 --- [ scheduling-1] com.didispace.chapter63.Monitor : 上报统计数据:38 2021-08-03 01:53:02.739 INFO 94110 --- [ scheduling-1] com.didispace.chapter63.Monitor : 上报统计数据:51 2021-08-03 01:53:07.739 INFO 94110 --- [ scheduling-1] com.didispace.chapter63.Monitor : 上报统计数据:31
> select * from ApiQPS order by time desc; name: ApiQPS time count url ---- ----- --- 1627926787730000000 31 /hello 1627926782730000000 51 /hello 1627926777729000000 38 /hello 1627926772727000000 30 /hello 1627926767728000000 25 /hello
The above is the detailed content of Teach you one trick to use time series database in Spring Boot. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Guide to Square Root in Java. Here we discuss how Square Root works in Java with example and its code implementation respectively.

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.
