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

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

Trending

  • How to Build Local LLM RAG Apps With Ollama, DeepSeek-R1, and SingleStore
  • How To Develop a Truly Performant Mobile Application in 2025: A Case for Android
  • Fixing Common Oracle Database Problems
  • Integrating Security as Code: A Necessity for DevSecOps
  1. DZone
  2. Coding
  3. Frameworks
  4. Monitoring Using Spring Boot 2.0, Prometheus, and Grafana (Part 2 — Exposing Metrics)

Monitoring Using Spring Boot 2.0, Prometheus, and Grafana (Part 2 — Exposing Metrics)

Follow this tutorial in order to learn how to expose metrics using Prometheus. This tutorial also includes pictures to aid in the tutorial.

By 
Satish Sharma user avatar
Satish Sharma
·
Updated May. 21, 18 · Tutorial
Likes (16)
Comment
Save
Tweet
Share
154.1K Views

Join the DZone community and get the full member experience.

Join For Free

In part two, we will be enabling the metrics endpoints.

In the previous article, we created a REST API for CRUD operations on our entity. In this part, we will be working on the same application to add settings and configurations, which will enable us to expose endpoints for metrics.

As from Spring Boot 2.0, Micrometer is the default metrics export engine. Micrometer is an application metrics facade that supports numerous monitoring systems. Atlas, Datadog, Prometheus, etc. to name a few (as we will be using Prometheus in this tutorial, we will be focusing on Prometheus only).

When you add Spring Boot Actuator and micrometer as your dependencies, it auto-configures a composite MeterRegistry and adds a registry for each of the supported implementations that it finds on the classpath. Having a dependency on micrometer-registry-{system} in your runtime classpath is enough for Spring Boot to configure the registry.

  • pom.xml : In pom.xml, add the dependency for micrometer-core and micrometer-prometheus-registry by adding following snippet.xml
<!-- Spring boot actuator to expose metrics endpoint -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Micormeter core dependecy  -->
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-core</artifactId>
</dependency>
<!-- Micrometer Prometheus registry  -->
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
  • application.properties: unable the actuator and Prometheus endpoints to be exposed by adding below properties.proper
#Metrics related configurations
management.endpoint.metrics.enabled=true
management.endpoints.web.exposure.include=*
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true


That is all you need to do to enable the metrics. Start the application with these changes and if you browse URL http://localhost:9000/actuator you should see the actuator endpoints.

prometheus metric endpoint

Notice spring-boot 2 and actuator has enabled an endpoint http://localhost:9000/actuator/prometheus for us. If you browse this URL, you will be able to see the metrics exported from the person-application. The data is the actual metrics collected from the application and exported as JSON.

Prometheus metrics

If you see something like above screenshot, then you have successfully exposed the metrics.

You can get the source code at this GitHub repository.

In next part, we will be setting up Prometheus and importing the metrics there.

Spring Framework Spring Boot Metric (unit) Grafana

Opinions expressed by DZone contributors are their own.

Related

  • Spring Boot Monitoring via Prometheus -Grafana
  • Metrics 2.X in Spring Boot 2.X
  • Spring Boot Metrics with Dynamic Tag Values
  • [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!