DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • How Spring Boot Starters Integrate With Your Project
  • A Practical Guide to Creating a Spring Modulith Project
  • Structured Logging in Spring Boot 3.4 for Improved Logs

Trending

  • Build a Voice Assistant With Gemini Live API
  • Stop Writing Database Migration Scripts: Declarative Schema Sync for Java
  • Should Developers Switch From SQLite to DuckDB?
  • Adding Graph Retrieval to a RAG Pipeline With Python

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Frameworks
  4. Spring Boot and Micrometer with InfluxDB Part 2: Adding InfluxDB

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.

By 
Emmanouil Gkatziouras
DZone Core CORE ·
Nov. 24, 20 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
15.6K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

XML
 




x


 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<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">
3
    <modelVersion>4.0.0</modelVersion>
4
 
5
    <parent>
6
        <groupId>org.springframework.boot</groupId>
7
        <artifactId>spring-boot-starter-parent</artifactId>
8
        <version>2.2.4.RELEASE</version>
9
    </parent>
10
 
11
    <groupId>com.gkatzioura</groupId>
12
    <artifactId>DevJobsApi</artifactId>
13
    <version>1.0-SNAPSHOT</version>
14
 
15
    <build>
16
        <defaultGoal>spring-boot:run</defaultGoal>
17
        <plugins>
18
            <plugin>
19
                <groupId>org.apache.maven.plugins</groupId>
20
                <artifactId>maven-compiler-plugin</artifactId>
21
                <configuration>
22
                    <source>8</source>
23
                    <target>8</target>
24
                </configuration>
25
            </plugin>
26
            <plugin>
27
                <groupId>org.springframework.boot</groupId>
28
                <artifactId>spring-boot-maven-plugin</artifactId>
29
            </plugin>
30
        </plugins>
31
    </build>
32
 
33
    <dependencies>
34
        <dependency>
35
            <groupId>org.springframework.boot</groupId>
36
            <artifactId>spring-boot-starter-webflux</artifactId>
37
        </dependency>
38
        <dependency>
39
            <groupId>org.projectlombok</groupId>
40
            <artifactId>lombok</artifactId>
41
            <version>1.18.12</version>
42
            <scope>provided</scope>
43
        </dependency>
44
      <dependency>
45
            <groupId>org.springframework.boot</groupId>
46
            <artifactId>spring-boot-starter-actuator</artifactId>
47
        </dependency>
48
        <dependency>
49
            <groupId>io.micrometer</groupId>
50
            <artifactId>micrometer-core</artifactId>
51
            <version>1.3.2</version>
52
        </dependency>
53
        <dependency>
54
            <groupId>io.micrometer</groupId>
55
            <artifactId>micrometer-registry-influx</artifactId>
56
            <version>1.3.2</version>
57
        </dependency>
43
        </dependency>
58
   </dependencies>
59
</project>



It's also time to add the configuration through the application.yaml

YAML
 




xxxxxxxxxx
1
10


 
1
management:
2
  metrics:
3
    export:
4
      influx:
5
        enabled: true
6
        db: devjobsapi
7
        uri: http://127.0.0.1:8086
8
  endpoints:
9
    web:
10
      expose: "*"


Let’s spin up our application and do some requests.

Shell
xxxxxxxxxx
1
 
1
curl localhost:8080/jobs/github/1


After some time we can check the database and the data contained.

Shell
 




xxxxxxxxxx
1
40


 
1
docker exec -it influxdb-local influx
2
> SHOW DATABASES;
3
name: databases
4
name
5
----
6
_internal
7
devjobsapi
8
> use devjobsapi
9
Using database devjobsapi
10
> SHOW MEASUREMENTS
11
name: measurements
12
name
13
----
14
http_server_requests
15
jvm_buffer_count
16
jvm_buffer_memory_used
17
jvm_buffer_total_capacity
18
jvm_classes_loaded
19
jvm_classes_unloaded
20
jvm_gc_live_data_size
21
jvm_gc_max_data_size
22
jvm_gc_memory_allocated
23
jvm_gc_memory_promoted
24
jvm_gc_pause
25
jvm_memory_committed
26
jvm_memory_max
27
jvm_memory_used
28
jvm_threads_daemon
29
jvm_threads_live
30
jvm_threads_peak
31
jvm_threads_states
32
logback_events
33
process_cpu_usage
34
process_files_max
35
process_files_open
36
process_start_time
37
process_uptime
38
system_cpu_count
39
system_cpu_usage
40
system_load_average_1m


That’s pretty awesome. Let’s check the endpoints accessed.

Shell
 




xxxxxxxxxx
1


 
1
> SELECT*FROM http_server_requests;
2
name: http_server_requests
3
time                count exception mean        method metric_type outcome status sum         upper       uri
4
----                ----- --------- ----        ------ ----------- ------- ------ ---         -----       ---
5
1582586157093000000 1     None      252.309331  GET    histogram   SUCCESS 200    252.309331  252.309331  /actuator
6
1582586157096000000 0     None      0           GET    histogram   SUCCESS 200    0           2866.531375 /jobs/github/{page}
7
 
          


Pretty great! The next step would be to visualise those metrics.

Spring Framework InfluxDB Spring Boot

Published at DZone with permission of Emmanouil Gkatziouras. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • How Spring Boot Starters Integrate With Your Project
  • A Practical Guide to Creating a Spring Modulith Project
  • Structured Logging in Spring Boot 3.4 for Improved Logs

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook