Code Monkey home page Code Monkey logo

spring-boot-default-metrics-example's Introduction

This repository demonstrates the most important default Spring Boot metrics which are enabled through the Spring Boot Actuator module:

  • Spring MVC metrics
  • Outbound request metrics for RestTemplate and WebClient
  • JVM metrics

For a full explanation see the accompanying Spring Boot default metrics article at tomgregory.com or YouTube video.

Prerequisites

To run this project you'll need:

  • JDK 11+
  • Docker

Running

Build and run the project using Docker compose with the following command:

./gradlew assemble docker dockerComposeUp

This will startup:

  • Spring Boot application at localhost:8080 exposing several APIs
    • API 1 is a simple GET API which adds a small random latency
    • API 2 is a simple GET API which adds a larger random latency
    • API 3 is a GET API that makes a request to another application using RestTemplate (see below)
    • Prometheus metrics for the Prometheus service to scrape (see below)
  • nginx application at localhost:8081 to act as the 2nd application to be called using RestTemplate. It always returns a 200 response.
  • Prometheus service at localhost:9090 which is preconfigured to scrape from the Spring Boot application

Generating metric data

To avoid having to hit the APIs by hand in order to demonstrate the Prometheus metrics, a Gatling script is included which will hit all the different APIs multiple times over 30 seconds. See BasicSimulation.scala for details of how this is done.

Just run:

./gradlew gatlingRun

Some sample Prometheus queries

Try out these simple queries on Prometheus:

Inbound request per second rate

rate(http_server_requests_seconds_count[1m])

Inbound request average duration

rate( http_server_requests_seconds_sum[1m]) / rate(http_server_requests_seconds_count[1m])

Inbound request 95th percentile

http_server_requests_seconds{quantile="0.95"}

Outbound request average duration

rate(http_client_requests_seconds_sum[1m]) / rate(http_client_requests_seconds_count[1m])

JVM used heap memory

sum(jvm_memory_used_bytes{area="heap"})

See more examples in the Spring Boot default metrics article at tomgregory.com

Stopping

To stop all the applications in this project, just run:

./gradlew dockerComposeDown

spring-boot-default-metrics-example's People

Contributors

tkgregory avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.