Course – Black Friday 2025 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

Partner – Orkes – NPI EA (cat=Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag=Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Partner – Orkes – NPI EA (cat=Java)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2025 – NPI (cat=Baeldung)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

1. Overview

In the demanding world of software development, ensuring that applications perform optimally and reliably once deployed in production environments is not just preferable — it’s essential. Using Spring Boot, developers can effortlessly set up standalone, high-grade applications. However, to truly enhance performance, availability, and reliability, integrating a sophisticated monitoring tool like Prometheus is key.

This tutorial aims to provide a detailed walkthrough on connecting Prometheus with a Spring Boot application, enriching our monitoring strategy with both fundamental and intricate configurations.

2. What Is Prometheus?

Prometheus is an open source project designed to dive deep into our application data, creating the filtering layers to collect and analyze everything from the simplest to the most complex. It’s not just about numbers and charts, either: It’s about understanding the heartbeat of our application through its advanced query language and time-series data capabilities.

Integrating Prometheus gives us the ability to identify problems before they occur, fine-tune our systems, ensure our application runs at peak performance, and ultimately, means a better experience for our users – convenient, fast, and reliable.

3. Getting Started With Prometheus in Spring Boot

Integrating Prometheus with our Spring Boot application allows us to effectively monitor by exposing application metrics in a format that Prometheus can understand and scrape. This process involves two main steps: adding the necessary dependencies to our project and configuring our application to expose metrics.

3.1. Adding Dependencies

To get started, we add the Spring Boot Actuator and the Micrometer Prometheus registry to the dependencies of our project. The actuator provides a series of built-in endpoints to display performance information about the running application, such as health, metrics, and more. The Micrometer Prometheus registry then formats these metrics into a Prometheus-readable format.

Let’s add the dependencies to our pom.xml file for a Maven project:

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

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

If we’re using Gradle, we include these in our build.gradle file:

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'

3.2. Configuring the Application

After adding the dependencies, the next step is to configure our Spring Boot application to expose the Prometheus metrics endpoint. This is done by updating the application.properties or application.yml file in our project.

For application.properties, we add:

management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always

This configuration ensures the Actuator’s /actuator/prometheus endpoint is exposed, providing a wealth of application metrics in a format that Prometheus can scrape.

It’s important to note that exposing all Actuator endpoints (management.endpoints.web.exposure.include=*) can provide useful insights during development but may expose sensitive operational data. For production environments, it’s best practice for us to carefully select which endpoints to expose based on our monitoring and operational needs.

By following these steps, our Spring Boot application will now expose valuable metrics that Prometheus can collect and store. This foundational setup is crucial for the next stages of our monitoring strategy, including scraping these metrics with Prometheus and visualizing them using tools like Grafana.

4. Setting up Prometheus to Scrape Metrics

With our application now configured to expose metrics, the next step involves setting up Prometheus to collect these metrics. This part of the process requires us to download and configure Prometheus — detailing a step-by-step guide based on the operating system — and to adjust the prometheus.yml file to target our Spring Boot application.

4.1. Installation

Installing Prometheus is straightforward. Let’s review the steps for the two most common operating systems and Docker:

For Windows:

  1. Download the latest Prometheus version from the official Prometheus website, selecting the Windows version.
  2. Extract the downloaded .zip file to our desired location, which will serve as the Prometheus home directory.
  3. Run Prometheus by opening a command prompt, navigating to the Prometheus directory, and executing prometheus.exe. This action starts the Prometheus server.

For Linux/Mac:

  1. Download the latest version for Linux or Mac from the Prometheus downloads page.
  2. Extract the tarball using the command tar xvfz prometheus-*.tar.gz.
  3. Navigate into the extracted directory, making it the Prometheus home directory.
  4. Start Prometheus by executing ./prometheus in the terminal, which launches the Prometheus server.

Using Docker:

Opting for Docker to deploy Prometheus facilitates the setup process, offering a consistent and simplified installation method regardless of the operating system. Here’s how we can achieve this:

  1. Pull the Prometheus Image: Initially, we pull the official Prometheus image from Docker Hub to ensure we have the latest version:
    docker pull prom/prometheus
  2. Run the Prometheus Container: Following the image pull, we can launch a Prometheus container. This command forwards the Prometheus default port (9090) to the same port on our host, enabling access to the Prometheus web UI via http://localhost:9090:
    docker run --name prometheus -d -p 9090:9090 prom/prometheus

    For deployments requiring a custom configuration, a custom prometheus.yml file located on our host can be mounted into the container:

    docker run --name prometheus -d -p 9090:9090 -v /our/path/to/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

    We replace /our/path/to/prometheus.yml with the actual path to our configuration file.

  3. Access Prometheus Web UI: With Prometheus actively running in a Docker container, the UI will become accessible through http://localhost:9090. This interface is instrumental for executing queries, gazing at gathered metrics, and verifying the status of scrape goals.

4.2. Configuring Prometheus to Scrape Metrics

Once installed, we need to configure Prometheus to scrape metrics from our Spring Boot application. This calls for editing the prometheus.yml record located within the Prometheus home listing.

We add our Spring Boot application as a target under the scrape_configs section:

scrape_configs:
  - job_name: 'spring-boot-application'
    metrics_path: '/actuator/prometheus'
    scrape_interval: 15s # This can be adjusted based on our needs
    static_configs:
      - targets: ['localhost:8080']

Here, localhost:8080 should be replaced with the appropriate host and port where our Spring Boot application is running. The scrape_interval specifies how often Prometheus should scrape metrics from our application.

4.3. Visualizing Metrics With Grafana

While Prometheus excels at collecting and storing metrics, Grafana is our tool of choice for visualizing these metrics through insightful dashboards.

Integrating Grafana with Prometheus:

  1. Install Grafana by visiting the official Grafana download page.
  2. Launch Grafana and access its web interface by going to http://localhost:3000 on a web browser.
  3. Add Prometheus as a data source by navigating to Configuration > Data Sources > Add data source in Grafana’s UI. We select Prometheus as the type and specify the URL where Prometheus is running, usually http://localhost:9090.
  4. Save & Test to confirm Grafana can successfully connect to Prometheus.

Creating Dashboards in Grafana:

  1. Create a brand new dashboard by clicking on the icon at the left sidebar and deciding on the Dashboard.
  2. Add a brand new panel to the dashboard. Here, we pick the metric to show, decide on the visualization kind (Graph, Gauge, Table, and so on.), and customize the panel’s appearance.
  3. Select our Prometheus records source and utilize the Prometheus Query Language (PromQL) to pick the metrics we wish to visualize. For example, to reveal the charge of HTTP requests, we would use a query like price(http_requests_total[5m]).
  4. Save our panel and dashboard. We can create as many panels as possible to visualize exceptional metrics from our Spring Boot utility.

Following these steps enables us to set up Prometheus to scrape metrics from our Spring Boot application and leverage Grafana to visualize them. This setup provides us with crucial insights into our application’s health and overall performance.

5. Advanced Configurations and Best Practices

This section addresses advanced configurations that can enhance our Spring Boot application’s observability and security. We’ll explore setting up alerting rules in Prometheus and creating custom metrics in Spring Boot using Micrometer.

Following these best practices ensures that our application remains robust, secure, and highly available.

5.1. Custom Metrics in Spring Boot

Spring Boot’s integration with Micrometer provides a seamless approach to adding custom metrics to our application, enabling us to monitor application-specific behaviors and operations. Here’s how we can create and register custom metrics:

@Component
public class CustomMetricsService {

    private final Counter customMetricCounter;

    public CustomMetricsService(MeterRegistry meterRegistry) {
        customMetricCounter = Counter.builder("custom_metric_name")
          .description("Description of custom metric")
          .tags("environment", "development")
          .register(meterRegistry);
    }

    public void incrementCustomMetric() {
        customMetricCounter.increment();
    }
}

In this example, we define a custom counter metric named custom_metric_name. This counter can be incremented to track a specific event within our application, such as user registrations or login attempts.

By injecting the MeterRegistry, we register our custom metric, making it available for scraping by Prometheus.

5.2. Best Practices for Monitoring and Alerting

Let’s review a few best practices for this endeavor:

  • Set up Alerting Rules in Prometheus: Define alerting rules based on application-specific metrics and thresholds. This proactive approach helps in identifying and addressing issues before they impact users.
  • Monitor Business-Critical Transactions: Beyond system health, track metrics that represent critical business functionality, such as order completions or payment transactions.
  • Secure Access to Metrics: Ensure that metrics endpoints are protected to prevent unauthorized access. Utilize Spring Security to configure access controls as needed.
  • Regularly Review Metrics and Alerts: Periodically review configured metrics and alerts to ensure they remain relevant to operational and business needs. Adjust thresholds and metrics as the application evolves.

By implementing these advanced configurations and adhering to best practices, we can achieve a robust monitoring and alerting setup that not only safeguards our application but also provides deep insights into its performance and usage patterns.

6. Conclusion

Utilizing Prometheus and Grafana to monitor our Spring Boot applications provides a robust approach to understanding application behavior and preempting potential problems. This article has guided us through putting in place an effective monitoring solution, improving our packages’ observability.

By integrating that equipment into our improvement and deployment workflows, we extensively bolster the reliability and performance of our packages. This not only ensures they meet user and business requirements but also fosters a culture of continuous improvement.

Adopting Prometheus and Grafana for tracking is more than a strategy for maintaining utility health. It’s a step toward proactive management and optimization of our packages, setting the stage for sustained success and growth.

Course – Black Friday 2025 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

Partner – Orkes – NPI EA (cat = Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag = Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2025 – NPI (All)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

eBook Jackson – NPI EA – 3 (cat = Jackson)