Spring Boot and Micrometer with InfluxDB Part 2: Adding InfluxDB
Part 2 of Spring Boot and Micrometer with InfluxDB where I'll show how to add InfluxDB and add a docker instance.
Join the DZone community and get the full member experience.
Join For FreeSince we added our base application it is time for us to spin up an InfluxDB instance.
We shall follow a previous tutorial and add a docker instance.
docker run –rm -p 8086:8086 –name influxdb-local influxdb
Time to add the micrometer InfluxDB dependency on our pom
x
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
</parent>
<groupId>com.gkatzioura</groupId>
<artifactId>DevJobsApi</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<defaultGoal>spring-boot:run</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-influx</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
</project>
It's also time to add the configuration through the application.yaml
xxxxxxxxxx
management
metrics
export
influx
enabledtrue
db devjobsapi
uri http //127.0.0.18086
endpoints
web
expose"*"
Let’s spin up our application and do some requests.
xxxxxxxxxx
curl localhost:8080/jobs/github/1
After some time we can check the database and the data contained.
xxxxxxxxxx
docker exec -it influxdb-local influx
> SHOW DATABASES;
name: databases
name
----
_internal
devjobsapi
> use devjobsapi
Using database devjobsapi
> SHOW MEASUREMENTS
name: measurements
name
----
http_server_requests
jvm_buffer_count
jvm_buffer_memory_used
jvm_buffer_total_capacity
jvm_classes_loaded
jvm_classes_unloaded
jvm_gc_live_data_size
jvm_gc_max_data_size
jvm_gc_memory_allocated
jvm_gc_memory_promoted
jvm_gc_pause
jvm_memory_committed
jvm_memory_max
jvm_memory_used
jvm_threads_daemon
jvm_threads_live
jvm_threads_peak
jvm_threads_states
logback_events
process_cpu_usage
process_files_max
process_files_open
process_start_time
process_uptime
system_cpu_count
system_cpu_usage
system_load_average_1m
That’s pretty awesome. Let’s check the endpoints accessed.
xxxxxxxxxx
> SELECT*FROM http_server_requests;
name: http_server_requests
time count exception mean method metric_type outcome status sum upper uri
---- ----- --------- ---- ------ ----------- ------- ------ --- ----- ---
1582586157093000000 1 None 252.309331 GET histogram SUCCESS 200 252.309331 252.309331 /actuator
1582586157096000000 0 None 0 GET histogram SUCCESS 200 0 2866.531375 /jobs/github/{page}
Pretty great! The next step would be to visualise those metrics.
Published at DZone with permission of Emmanouil Gkatziouras, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments