Since 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
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 | <dependencies>... <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> |
Time to add the configuration through the application.yaml
01 02 03 04 05 06 07 08 09 10 | management: metrics: export: influx: enabled: true db: devjobsapi uri: http://127.0.0.1:8086 endpoints: web: expose: "*" |
Letβs spin up our application and do some requests.
After some time we can check the database and the data contained.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | docker exec -it influxdb-local influx> SHOW DATABASES;name: databasesname----_internaldevjobsapi> use devjobsapiUsing database devjobsapi> SHOW MEASUREMENTSname: measurementsname----http_server_requestsjvm_buffer_countjvm_buffer_memory_usedjvm_buffer_total_capacityjvm_classes_loadedjvm_classes_unloadedjvm_gc_live_data_sizejvm_gc_max_data_sizejvm_gc_memory_allocatedjvm_gc_memory_promotedjvm_gc_pausejvm_memory_committedjvm_memory_maxjvm_memory_usedjvm_threads_daemonjvm_threads_livejvm_threads_peakjvm_threads_stateslogback_eventsprocess_cpu_usageprocess_files_maxprocess_files_openprocess_start_timeprocess_uptimesystem_cpu_countsystem_cpu_usagesystem_load_average_1m |
Thatβs pretty awesome. Letβs check the endpoints accessed.
1 2 3 4 5 6 | > SELECT*FROM http_server_requests;name: http_server_requeststime count exception mean method metric_type outcome status sum upper uri---- ----- --------- ---- ------ ----------- ------- ------ --- ----- ---1582586157093000000 1 None 252.309331 GET histogram SUCCESS 200 252.309331 252.309331 /actuator1582586157096000000 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 on Java Code Geeks with permission by Emmanouil Gkatziouras, partner at our JCG program. See the original article here: Spring Boot and Micrometer with InlfuxDB Part 2: Adding InfluxDB Opinions expressed by Java Code Geeks contributors are their own. |
Thank you!
We will contact you soon.
Emmanouil GkatziourasFebruary 27th, 2020Last Updated: February 25th, 2020

This site uses Akismet to reduce spam. Learn how your comment data is processed.
Thanks for the very helpful article.
Just for anyone else running into this: when I copy+pasted the above docker-run command apparently non-ascii unicode characters where copied, causing docker to fail with a rather unspecific error message. Here is the command in ascii characters: