forked from dyc87112/SpringBoot-Learning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
148 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.didispace</groupId> | ||
<artifactId>chapter6-3</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
<description>使用时序数据库InfluxDB</description> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.5.1</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.influxdb</groupId> | ||
<artifactId>influxdb-java</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
15 changes: 15 additions & 0 deletions
15
2.x/chapter6-3/src/main/java/com/didispace/chapter63/Chapter63Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.didispace.chapter63; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
|
||
@EnableScheduling | ||
@SpringBootApplication | ||
public class Chapter63Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Chapter63Application.class, args); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
2.x/chapter6-3/src/main/java/com/didispace/chapter63/Monitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.didispace.chapter63; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.influxdb.InfluxDB; | ||
import org.influxdb.dto.Point; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Random; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Created by 程序猿DD on 2021/8/2. | ||
* <p> | ||
* Blog: http://blog.didispace.com/ | ||
* Github: https://github.com/dyc87112/ | ||
*/ | ||
@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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
spring.influx.url=http://localhost:8086 | ||
spring.influx.user=admin | ||
spring.influx.password= | ||
|
22 changes: 22 additions & 0 deletions
22
2.x/chapter6-3/src/test/java/com/didispace/chapter63/ApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.didispace.chapter63; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@Slf4j | ||
@SpringBootTest | ||
public class ApplicationTests { | ||
|
||
@Test | ||
public void findAll() { | ||
|
||
} | ||
|
||
@Test | ||
public void save() { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters