Monitoring Spring Boot application with New Relic One

nbodev
3 min readMar 28, 2022

--

1- Introduction

2- Versions

3- New Relic One

4- Code

5- Metrics example

6- Interesting links

7- Conclusion

Introduction

This article explains how metrics can be pushed from a Spring Boot application to New Relic One platform. One of my client wanted to use New Relic One, since I was not familiar with it, I did this small work in order to see how to push my application metrics there.

Versions

  • Java 11
  • Spring Boot 2.6.6

New Relic One

Go to https://newrelic.com/platform and sign in. The storage of my data will happen in the US (I don’t know if choosing Europe will have any impact).

You will need an insert key (license key) so your metrics can be pushed to New Relic One platform, this key will be used as a value of this argument -Dnewrelic.apiKey in our example later on.

Once you are logged to the New Relic One website, no need to configure anything, type the https://newrelic.com address in your browser so you can access your license key.

Copy the license key (take the INGEST — LICENSE) from below:

Read more about license keys: https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/

Code

Find the code here, maven is needed for the compilation:

Clone the project then run:

cd springboot-newrelic
mvn clean install

Then run:

java -Dnewrelic.enabled=true -Dnewrelic.apiKey=<your api key here> -Dnewrelic.serviceName=MySpringBootApp -jar ./target/newrelic-0.0.1-SNAPSHOT.jar

Make sure you already have the required api key.

Metrics example

The NewRelicRegistry configuration is done in the class NewrelicMicrometerConfig class, this is where we define the registry that will collect our metrics and push them to the New Relic One platform.

We defined three types of metrics:

  • demo.counter that keeps increasing, defined in DemoMicrometer .
  • demo.gauge that increases / decreases and stays in the [0,500[ interval, defined in DemoMicrometer .
  • greetings that is related to the REST endpoint defined in the DemoController class.

Those metrics are defined with micrometer.

Note that I left the logging level to TRACE in the file logback-spring.xml, this will show all the interactions between the application and New Relic One:

<logger name="com.newrelic.telemetry" level="TRACE" />
The MySpringBootApp visible under Services — OpenTelemetry
Default visible metrics for MySpringBootApp
MySpringBootApp metrics exploration
Dashboards

Interesting links

Conclusion

Note that I did not use any agent here, some of the documentation related to New Relic One will describe how to setup the agent.

Also I used the following dependency in my pom.xml in order to bridge New Relic and Micrometer:

<dependency>
<groupId>com.newrelic.telemetry</groupId>
<artifactId>micrometer-registry-new-relic</artifactId>
<version>0.7.0</version>
</dependency>

You might find documentation / tutorials using other dependencies in order to push the metrics to New Relic One. I could try that in a near future.

Enjoy !

--

--

No responses yet