<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() {
// 가상 report 데이터
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 database 에 저장
influxDB.write("test", "autogen", point);
log.info("총 건수:" + count);
}
}
$ influx
> show databases
> create database "test"
2022-12-27 01:52:47.732 INFO 94110 --- [ main] c.d.demo.InfluxDBApplication : Started InfluxDBApplication in 2.326 seconds (JVM running for 3.027)
2022-12-27 01:52:47.764 INFO 94110 --- [ scheduling-1] com.blake.demo.Monitor : 총 건수:25
2022-12-27 01:52:52.736 INFO 94110 --- [ scheduling-1] com.blake.demo.Monitor : 총 건수:30
2022-12-27 01:52:57.737 INFO 94110 --- [ scheduling-1] com.blake.demo.Monitor : 총 건수:38
2022-12-27 01:53:02.739 INFO 94110 --- [ scheduling-1] com.blake.demo.Monitor : 총 건수:51
2022-12-27 01:53:07.739 INFO 94110 --- [ scheduling-1] com.blake.demo.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