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
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Metrics 2.X in Spring Boot 2.X
  • Spring Boot Metrics with Dynamic Tag Values
  • Spring Boot Monitoring via Prometheus -Grafana
  • [CSF] Using Metrics In Spring Boot Services With Prometheus, Graphana, Instana, and Google cAdvisor

Trending

  • Creating a Web Project: Caching for Performance Optimization
  • Implementing API Design First in .NET for Efficient Development, Testing, and CI/CD
  • Modern Test Automation With AI (LLM) and Playwright MCP
  • Understanding the Shift: Why Companies Are Migrating From MongoDB to Aerospike Database?
  1. DZone
  2. Coding
  3. Frameworks
  4. How to Publish Spring Boot Actuator Metrics to Dynatrace

How to Publish Spring Boot Actuator Metrics to Dynatrace

The metrics generated by the Spring Boot Actuator module of Spring Boot can be easily published to a Dynatrace cloud instance.

By 
Diego Pettisani user avatar
Diego Pettisani
·
Updated Jan. 02, 20 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
24.8K Views

Join the DZone community and get the full member experience.

Join For Free

open, blank book

Learn more about publishing Spring boot actuator metrics!

The metrics generated by the Spring Boot Actuator module of Spring Boot can be easily published to a Dynatrace cloud instance. This article will give you a step-by-step guide for obtaining that.

Prerequisites:

  • JDK 8+
  • Maven 3.x
  • A Dynatrace cloud instance, you can create it for a 15-days free trial very quickly (try it). 
  • A Dynatrace OneAgent installed on your environment, you can install it on Linux and Windows.

If you do not have the OneAgent installed, please:

  • Download the installer from the Deploy Dynatrace web page of your Dynatrace instance (you need administrator rights).
  • Asks a proper administrator to install OneAgent on your PC.
  • Asks a proper administrator to give you access to an environment having the OneAgent already installed and where you can run the PoC that we are going to develop.

Generate a Dynatrace API token

Spring Boot Actuator uses Micrometer  and the metrics will be published thanks to the Micrometer integration with Dynatrace. 

If you give a look at the source code it is possible to verify that Micrometer uses the Custom Device and Timeseries API exposed by Dynatrace. But, before using any Dynatrace API, you have to generate an API token.

Please note that for generating an API token you need administrator rights on your Dynatrace instance or otherwise you have to ask a proper administrator to generate that token for you.

Login to your Dynatrace instance and open the Settings menu  in the bottom left panel:

Open the Integration -> Dynatrace API page and clicks the Generate token button.

Generate Token button

Type a name for identifying the token (for example spring_boot_poc) and clicks the Generate button visible scrolling down the page and your new brand new token will be created.

API Token list

You can read the API token value by clicking the arrow under Edit.

Copy the token value and keep it in a safe place.

Create a Spring Boot app

A simple "Hello World!" Spring Boot app will be enough for publishing some custom metrics to Dynatrace. 

It is possible to copy and paste the file contents described below or (more quickly) to clone this GitHub repository.

The pom.xml file will be:

XML
 




x
86


 
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"
3
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4
    <modelVersion>4.0.0</modelVersion>
5
    <parent>
6
        <groupId>org.springframework.boot</groupId>
7
        <artifactId>spring-boot-starter-parent</artifactId>
8
        <version>2.2.3.BUILD-SNAPSHOT</version>
9
        <relativePath/> <!-- lookup parent from repository -->
10
    </parent>
11
    <groupId>com.example</groupId>
12
    <artifactId>demo</artifactId>
13
    <version>0.0.1-SNAPSHOT</version>
14
    <name>demo</name>
15
    <description>Demo project for Spring Boot</description>
16

          
17
    <properties>
18
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19
        <java.version>1.8</java.version>
20
        <maven.compiler.source>1.8</maven.compiler.source>
21
        <maven.compiler.target>1.8</maven.compiler.target>
22
    </properties>
23

          
24
    <dependencies>
25

          
26
        <dependency>
27
            <groupId>org.springframework.boot</groupId>
28
            <artifactId>spring-boot-starter-web</artifactId>
29
        </dependency>
30

          
31
        <!-- Enable Spring Boot Actuator -->
32
        <dependency>
33
            <groupId>org.springframework.boot</groupId>
34
            <artifactId>spring-boot-starter-actuator</artifactId>
35
        </dependency>
36

          
37
        <!-- Add this dependency for publishing Actuator metrics to Dynatrace -->
38
        <dependency>
39
            <groupId>io.micrometer</groupId>
40
            <artifactId>micrometer-registry-dynatrace</artifactId>
41
        </dependency>
42

          
43
    </dependencies>
44

          
45
    <build>
46
        <plugins>
47
            <plugin>
48
                <groupId>org.springframework.boot</groupId>
49
                <artifactId>spring-boot-maven-plugin</artifactId>
50
            </plugin>
51
        </plugins>
52
    </build>
53

          
54
    <repositories>
55
        <repository>
56
            <id>spring-milestones</id>
57
            <name>Spring Milestones</name>
58
            <url>https://repo.spring.io/milestone</url>
59
        </repository>
60
        <repository>
61
            <id>spring-snapshots</id>
62
            <name>Spring Snapshots</name>
63
            <url>https://repo.spring.io/snapshot</url>
64
            <snapshots>
65
                <enabled>true</enabled>
66
            </snapshots>
67
        </repository>
68
    </repositories>
69
    <pluginRepositories>
70
        <pluginRepository>
71
            <id>spring-milestones</id>
72
            <name>Spring Milestones</name>
73
            <url>https://repo.spring.io/milestone</url>
74
        </pluginRepository>
75
        <pluginRepository>
76
            <id>spring-snapshots</id>
77
            <name>Spring Snapshots</name>
78
            <url>https://repo.spring.io/snapshot</url>
79
            <snapshots>
80
                <enabled>true</enabled>
81
            </snapshots>
82
        </pluginRepository>
83
    </pluginRepositories>
84

          
85
</project>
86

          



Please note that:

  • The Spring Boot version used is 2.2.3 (SNAPSHOT) because it fixes this bug and so it is possible to set the  management.metrics.export.dynatrace.group  property (see  application.properties  file configuration later). Currently, the final Spring Boot 2.2.3 version has not yet been released.
  • The pom contains the  spring-boot-starter-actuator  dependency for enabling Spring Boot Actuator.
  • The pom contains the  micrometer-registry-dynatrace  dependency needed for publishing the custom metrics to Dynatrace.

Create a simple Spring Boot controller in HelloWorldController.java:

Java
 




xxxxxxxxxx
1
14


 
1
package com.example.demo;
2

          
3
import org.springframework.web.bind.annotation.RequestMapping;
4
import org.springframework.web.bind.annotation.RestController;
5

          
6
@RestController
7
public class HelloWorldController {
8
        
9
    @RequestMapping("/")
10
    public String index() {
11
        return "Hello World!";
12
    }
13

          
14
}



Create a Spring Boot initialization class like the following App.java:

Java
 




xxxxxxxxxx
1
11


 
1
package com.example.demo;
2

          
3
import org.springframework.boot.SpringApplication;
4
import org.springframework.boot.autoconfigure.SpringBootApplication;
5

          
6
@SpringBootApplication
7
public class App {
8
    public static void main(String[] args) {
9
        SpringApplication.run(App.class, args);
10
    }
11
}



Enable the Spring Boot Actuator health and metrics endpoints in the application.properties file:

Properties files
 




xxxxxxxxxx
1


 
1
# Expose the health and metrics endpoints
2
management.endpoints.web.exposure.include=health, metrics



Build and start the Spring Boot app in one shot with the following command:

Shell
 




xxxxxxxxxx
1


 
1
mvn spring-boot:run



You can check that the application is running properly by putting http://localhost:8080 in your web browser.

Hello World!

You can verify that the Spring Boot Actuator module is running by putting http://localhost:8080/actuator/health in your web browser.

And, finally, checks that the Spring Boot Actuator metrics are collected by putting http://localhost:8080/actuator/metrics in your web browser.

You can check the value of a single metric by adding to the previous URL the metric name. For example http://localhost:8080/actuator/metrics/logback.events. 

Please note that, if the Dynatrace OneAgent was installed correctly, you should already see the HelloWorldController Spring Boot app in your Dynatrace instance by clicking Transactions and services in the left panel.

Spring Boot app detected in Transactions and services menu

Publish the Custom Metrics to Dynatrace

For enabling the publication of the custom metrics to Dynatrace modify the  application.properties  file as below:

Properties files
 


xxxxxxxxxx
1
25
 
1
# Expose the health and metrics endpoints
2
management.endpoints.web.exposure.include=health, metrics
3

          
4
# The Dynatrace instance URL
5
management.metrics.export.dynatrace.uri=https://xxxxxxxx.live.dynatrace.com
6

          
7
# The Dynatrace API token generated
8
management.metrics.export.dynatrace.api-token=0F0YILrjS2WokxAnlujiR
9

          
10
# The Device ID passed to Dynatrace API (could be an hostname or a pod name)
11
management.metrics.export.dynatrace.device-id=myhostname
12

          
13
# The Process Group passed to Dynatrace API (could be the application name)
14
# Be aware that this property works properly only from Spring Boot 2.2.3.RELEASE
15
management.metrics.export.dynatrace.group=spring_boot_poc
16

          
17
# The interval at which metrics are sent to Dynatrace (default 1 minute)
18
management.metrics.export.dynatrace.step=1m
19

          
20
#################################################
21
### IMPORTANT: Set to true for publishing the ###
22
###            custom metrics to Dynatrace.   ###
23
#################################################
24
management.metrics.export.dynatrace.enabled=true
25

          


Please note that:

  • Your Dynatrace instance URL has to be set in the management.metrics.export.dynatrace.uri property.
  • Your Dynatrace API token has to be set in the management.metrics.export.dynatrace.api-token property.
  • Do not forget to set the management.metrics.export.dynatrace.enabled property to  true.

Rebuild and restart the Spring Boot app with the command:

Shell
 


xxxxxxxxxx
1
 
1
mvn spring-boot:run


If your configuration is correct, you should see the following message in the Spring Boot console log:

Dynatrace enabled message

Wait for 1-2 minutes and enter in your Dynatrace instance. Open the Technologies page on the left menu and clicks the java quadrant for showing the process group set in the  management.metrics.export.dynatrace.group  property previously. Please note that if you are using a Spring Boot version lower than 2.2.3 you could see a random alphanumeric string prefixed with UNKNOWN CUSTOM_DEVICE_GROUP (this is a Spring Boot issue fixed here).

Technologies

Clicks the arrow under Details and then the Group details button.

In the bottom of the web page, you can see the device set in the management.metrics.export.dynatrace.device-id property previously.

Finally, clicks on the device name and you will see the graphs of your metrics!

Spring Boot Actuator metrics published on Dynatrace

Conclusions

This is a guide for publishing the Spring Boot Actuator metrics (collected by using Micrometer) to Dynatrace.

In our example the metrics published are very simple, checks the Spring Boot Actuator documentation for a full list of the supported metrics (caches, connection pools, and other useful metrics can be enabled automatically).

You can create (and publish) custom metrics by injecting a MeterRegistry instance as explained here. Use the Micrometer API for registering new metrics.

And last but not least, try to create custom charts on Dynatrace for a nice visualization of your metrics (check the documentation).

Enjoy your ad-hoc metrics to Dynatrace!

Spring Framework Spring Boot Metric (unit)

Opinions expressed by DZone contributors are their own.

Related

  • Metrics 2.X in Spring Boot 2.X
  • Spring Boot Metrics with Dynamic Tag Values
  • Spring Boot Monitoring via Prometheus -Grafana
  • [CSF] Using Metrics In Spring Boot Services With Prometheus, Graphana, Instana, and Google cAdvisor

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!