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

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

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

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 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
  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4

Trending

  • Emerging Data Architectures: The Future of Data Management
  • Rust and WebAssembly: Unlocking High-Performance Web Apps
  • *You* Can Shape Trend Reports: Join DZone's Software Supply Chain Security Research
  • Segmentation Violation and How Rust Helps Overcome It
  1. DZone
  2. Coding
  3. Frameworks
  4. Metrics 2.X in Spring Boot 2.X

Metrics 2.X in Spring Boot 2.X

Spring Boot offers a metrics endpoint that you can use diagnostically to analyze the metrics gathered by the application. Keeping track of metrics for Spring Boot 2.x.

By 
Vicky Singh user avatar
Vicky Singh
·
Updated Oct. 27, 21 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
6.0K Views

Join the DZone community and get the full member experience.

Join For Free

Spring Boot offers a metrics endpoint that you can use diagnostically to analyze the metrics gathered by the application.

Adding the Dependency Inside POM Is the First Step

A meter is an interface for gathering a bunch of estimations (which we separately call measurements) about your application. spring-measurements loads with an upheld set of Meter natives including Timer, Counter, Gauge, DistributionSummary, and LongTaskTimer. Note that diverse meter types bring about an alternate number of measurements. For instance, while there is a solitary metric that addresses a Gauge, a Timer estimates both the number of coordinated occasions and the absolute season of all occasions planned.

XML
 
<dependency>
  <groupId>org.springframework.metrics</groupId>
  <artifactId>spring-metrics</artifactId>
  <version>${metrics.version}</version> 
</dependency>


Create Registry Configuration

A library makes and deals with your application's arrangement of meters. Exporters utilize the meter library to emphasize the arrangement of meters instrumenting your application, and afterward further repeat over each meter's measurements, for the most part bringing about a period series in the measurements backend for every mix of measurements and measurements. 

Three meter library executions are given out-of-the-case: SpectatorMeterRegistry, PrometheusMeterRegistry, and SimpleMeterRegistry. The libraries are for the most part made unexpectedly by choosing a backend through @EnableAtlasMetrics, @EnablePrometheusMetrics, and so on.

Java
 
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.micrometer.core.aop.TimedAspect;
import io.micrometer.core.instrument.MeterRegistry;

@configuration
public class RegistryConfig {
	@Bean
  	MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
    	return registry -> registry.config().commonTags("region", "someRegionName");
    }
  
  @Bean
  TimedAspect timedAspect(MterRegistry registry) {
    return new TimedAspect(reegistry);
  }
}


Whenever we want to check the metrics of any method we only have to add the @Timed above the method and we can keep track of the method.

Add @Timed to the Method

Java
 
@Timed("mockMetricsSomeData")
public String getSomeData(){
	return "mockData":
}


Call the URL With Metrics

You will get the desired response from the metrics URL and we can keep these records and use them for creating a dashboard for any threshold value.

JSON
 
{
  "names": [
    "jvm.memory.committed",
    "jvm.gc.concurrent.phase.time",
    "jvm.buffer.total.capacity",
    "logback.events",
    "jvm.memory.max",
    "jvm.buffer.memory.used",
    "jvm.classes.loaded",
    "tomcat.threads.config.max",
    "http.server.requests",
    "metrometric.interval.gc.executiontimemillis",
    "jvm.memory.used",
    "jvm.classes.unloaded",
    "tomcat.sessions.active.current",
    "tomcat.global.error",
    "metrometric.interval.gc.count",
    "tomcat.sessions.alive.max",
    "jvm.gc.live.data.size",
    "metrometric.heap.max",
    "tomcat.threads.current",
    "metrometric.heap.used",
    "process.files.open",
    "jvm.gc.pause",
    "tomcat.sessions.active.max",
    "metrometric.heap.committed",
    "tomcat.threads.busy",
    "OemCrn.getCrnPrograms",
    "process.start.time",
    "process.files.max",
    "jvm.gc.memory.promoted",
    "metrometric.total.metrics_in_memory.count",
    "system.load.average.1m",
    "jvm.buffer.count",
    "jvm.gc.max.data.size",
    "tomcat.servlet.request.max",
    "process.cpu.usage"
  ]
}


And if we deeper inside the KEY We will get the more granular response for example:

  1. /metrics/mockMetricsSomeData
JSON
 
{
  "name": "mockMetricsSomeData",
  "description": null,
  "baseUnit": "milliseconds",
  "measurements": [
    {
      "statistic": "COUNT",
      "value": 0
    },
    {
      "statistic": "TOTAL_TIME",
      "value": 0
    },
    {
      "statistic": "MAX",
      "value": 0
    }
  ],
  "availableTags": [
    {
      "tag": "servicename",
      "values": [
        "mockMetrics"
      ]
    },
    {
      "tag": "containerhost",
      "values": [
        "3c94ccb43ab6"
      ]
    }
  ]
}


So we will have all the responses for metrics and we can use these at our convenience. In case of any doubt, feel free to ask in the comment section.

Spring Framework Metric (unit) Spring Boot

Opinions expressed by DZone contributors are their own.

Related

  • 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
  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4

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!