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

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • DGS GraphQL and Spring Boot
  • Mastering Scalability in Spring Boot
  • A Practical Guide to Creating a Spring Modulith Project
  • Setting Up Local Kafka Container for Spring Boot Application

Trending

  • Automating Data Pipelines: Generating PySpark and SQL Jobs With LLMs in Cloudera
  • Unlocking the Potential of Apache Iceberg: A Comprehensive Analysis
  • 5 Subtle Indicators Your Development Environment Is Under Siege
  • A Developer's Guide to Mastering Agentic AI: From Theory to Practice
  1. DZone
  2. Software Design and Architecture
  3. Performance
  4. Monitor Spring Boot Web Application Performance Using Micrometer and InfluxDB

Monitor Spring Boot Web Application Performance Using Micrometer and InfluxDB

By leveraging Spring Boot Actuator, Micrometer with InfluxDB, and Grafana, you can gain crucial insights into your application’s performance.

By 
Suyash Joshi user avatar
Suyash Joshi
·
Dec. 24, 24 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
4.4K Views

Join the DZone community and get the full member experience.

Join For Free

As a Java developer, there's nothing more frustrating than dealing with sluggish application performance in production. Diagnosing issues within complex microservice architectures can quickly become a time-consuming and daunting task. Fortunately, the Spring Boot framework offers a powerful observability stack that streamlines real-time monitoring and performance analysis. By leveraging tools like Spring Boot Actuator, Micrometer with InfluxDB, and Grafana, you can gather meaningful insights easily and quickly.

In this article, we'll walk through setting up this stack using a simple "Card-Playing" app/game as our use case. For your reference, the complete working example is available on GitHub.

Card game app screenshot

Setting Up the Project

First, initialize your Spring Boot project and add the necessary dependencies. In this example, we’ll use Maven and configure the dependencies in the pom.xml file. The key dependencies for this setup are Spring Boot Actuator and Micrometer with InfluxDB registry.

XML
 
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-influx</artifactId>
    <version>1.13.1</version>
</dependency>


Spring Boot Actuator

Spring Boot Actuator offers production-ready features that help monitor and manage your application. By default, it exposes endpoints like /actuator/health and /actuator/info. You can enable additional endpoints securely by configuring the application.properties file, as shown below:

Properties files
 
# SpringBoot Actuator Endpoints configuration
management.endpoints.web.exposure.include=health,info,metrics


Micrometer With InfluxDB

Micrometer is a lightweight library that integrates seamlessly with Spring Boot to enable application instrumentation. Once you’ve added the micrometer-registry-influx dependency to your pom.xml, you need to configure it in the application.properties file. This configuration will expose the relevant metrics to InfluxDB for monitoring. You’ll need to provide your InfluxDB token, URL, organization, and bucket information, which can be found in your InfluxDB portal.

Properties files
 
# InfluxDB Micrometer Registry Configuration for v2
management.metrics.tags.application=PickACard
management.metrics.export.influx.api-version=v2
management.metrics.export.influx.batch-size=10000
management.metrics.export.influx.compressed=true
management.metrics.export.influx.connect-timeout=1s
management.metrics.export.influx.enabled=true
management.metrics.export.influx.num-threads=2
management.metrics.export.influx.read-timeout=10s
management.metrics.export.influx.step=1m
management.metrics.export.influx.bucket=YOUR_INFLUXDB_BUCKET
management.metrics.export.influx.org=YOUR_INFLUXDB_ORG
management.metrics.export.influx.token=YOUR_INFLUXDB_TOKEN
management.metrics.export.influx.uri=YOUR_INFLUXDB_URI


Application Architecture

The application logic revolves around three main classes: CardController.java, DeckOfCardService.java, and InfluxDBConfig.java.

  • CardController.java: This serves as the entry point for the application, handling HTTP requests from users. When a user makes a request to the /card endpoint, the controller invokes the DeckOfCardService.
  • DeckOfCardService.java: This class interacts with the external Deck of Cards API to fetch a random card and return it as an SVG image.
  • InfluxDBConfig.java: This class configures InfluxDB metrics, ensuring that the application’s performance data is logged and accessible for analysis and monitoring.

Meanwhile, the InfluxDBConfig.java class handles the configuration of the Micrometer integration with InfluxDB, based on the settings in the application.properties file. As the application processes requests, Micrometer collects various performance metrics — such as response times and request counts — and sends them to the InfluxDB Bucket for storage. These metrics are then visualized in Grafana, allowing developers to monitor the application’s performance in real time.

Key Micrometer Concepts

  • Metrics: Data points that describe the behavior of your application, such as HTTP request counts, response times, and memory usage
  • Meters: Instruments that record metrics
    • Timers: Measure the duration of events (e.g., request handling time)
    • Counters: Measure an increasing value (e.g., number of HTTP requests)
    • Gauges: Represent a single value that can increase or decrease (e.g., memory usage)
  • Tags: Labels (key-value pairs) that provide context to a metric (e.g., HTTP status codes)
  • Registry: A place where metrics are stored, such as the InfluxMeterRegistry for InfluxDB

In our example application, we have a simple card game that uses a third-party HTTP API to fetch random cards. While I’m using a free API for this example, monitoring API calls becomes even more critical when working with a paid service. With Spring Boot Actuator and Micrometer integrated with InfluxDB, we can monitor custom metrics, like tracking how long each request takes, the result of the request, and how much memory the application uses. Here’s an example of the code:

Java
 
@Controller
public class CardController {
    @GetMapping("/card")
    @ResponseBody
    public Mono<String> getRandomCard() {
        return deckOfCardService.getRandomCardSvg();
    }
}


Logging and Monitoring With InfluxDB and Grafana

Once your Spring Boot application is running, it will send metrics to the InfluxDB bucket you’ve configured. You can view these metrics directly in the InfluxDB Dashboard or connect InfluxDB with a popular visualization tool like Grafana to create a custom dashboard for all your relevant metrics. This allows you to track important data, such as how many times the endpoint was called, when it was called, and the result of each request, giving you valuable insights into your application's performance.

The Bottom Line

By leveraging Spring Boot Actuator, Micrometer with InfluxDB, and Grafana, you can gain crucial insights into your application’s performance. This proactive approach helps identify and resolve issues early while ensuring a seamless user experience, particularly in complex environments like Kubernetes clusters. Tracking key performance metrics and health indicators empowers you to embrace a DevOps mindset, enabling you to deploy with confidence.

Feel free to explore the sample app on GitHub (linked earlier), and remember: you can start using InfluxDB Cloud for free. If you have any questions or feedback, don't hesitate to comment below or tag me on social media.

InfluxDB application Monitor (synchronization) Spring Boot Performance

Published at DZone with permission of Suyash Joshi. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • DGS GraphQL and Spring Boot
  • Mastering Scalability in Spring Boot
  • A Practical Guide to Creating a Spring Modulith Project
  • Setting Up Local Kafka Container for Spring Boot Application

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!