Skip to content

volphy/metrics-example

 
 

Repository files navigation

Metrics Example with Spring Boot

This code base is an example of using CodaHale Metrics (fka Yammer Metrics) [http://metrics.codahale.com] and Spring Boot [http://projects.spring.io/spring-boot/].

Pre-requisite: API key from openweathermap.org is required (free registration)

Running the Example

  1. Clone or fork the repository locally
  2. Run gradlew bootRun -DAPP_ID='your-api-key' on *nix/Mac or gradlew.bat bootRun -DAPP_ID='your-api-key' on Windows
  3. Open browser to http://localhost:8080/test/api
  4. Check generated metrics atr http://localhost:8080/metrics

About the Example

This uses Spring Boot to bootstrap the Web Application using embedded Jetty. This happens in the com.sample.metrics.Application class. This class also contains the @EnableMetrics annotation used to enable the Metrics plugin for Spring. We also expose the MetricRegistry using a variety of other plugins and configure it using a JMX reporter. Using this plugin we can now simply add @Timed to any public Spring bean method and automatically create a timer that wraps the method. The RestProvider and TestController provide examples of this. The RestProvider is used with an InstrumentedHttpClient to automatically instrument the Apache HTTP Client used to fetch API responses. The TestController is a simple Spring MVC endpoint to test everything.

About

Example using Spring Boot and Metrics library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%