Git Product home page Git Product logo

study-springboot-observability's Introduction

Study about Spring Boot with Prometheus and Grafana

Kotlin icon Spring icon Spring Boot icon Docker icon Docker icon

⤴️ Table of Contents

❓ About

Studies about Spring Boot with Prometheus and Grafana from the article Springboot App monitoring with Grafana & Prometheus by Vishnu M V.

Added some business metrics to Grafana and learned how to provision dashboards and datasources.

Back to Top

📊 System Diagrams

graph LR
    subgraph Linux
        A[Application]
    end

    subgraph Windows/MacOSX
        B[Application]
    end

    subgraph docker
        P[Prometheus] -- " study-springboot-grafana-prometheus-app-1:8080 " --> A
        P[Prometheus] -- " host.docker.internal:8080 " --> B
        G[Grafana] -- " prometheus:9090 " --> P
    end

Back to Top

👩‍🏫 Learnings

Very easy to enable it with spring boot actuator and there are dashboards ready for use.

Some difficulties getting it to work cross-platform. How docker networking works differently between Windows and Linux. There is no direct way to access the host IP address from within the container, making prometheus difficult to extract information from the application by Prometheus scraper.

More investigation would be needed to make the prometheus scraper work correctly on various OS platforms using only one target. For now, I have added both URLs to be discarded and accept that one of them will fail.

Back to Top

🏃 How to Run

Pre-requisites:

Initialize the Prometheus and Grafana with Docker Compose with the command:

docker compose up
Component Url User Password
Prometheus http://localhost:9090 - -
Grafana http://localhost:3000 admin admin

Run with Maven

mvn spring-boot:run

Run with Docker

Linux/MacOSX:

docker run --rm \
  -p 8080:8080 \
  -w /app \
  -v ./src:/app/src \
  -v ./pom.xml:/app/pom.xml \
  -v data:/root/.m2 \
  --network=study-springboot-grafana-prometheus_monitoring \
  --name=/study-springboot-grafana-prometheus-app-1 \
  --label com.docker.compose.project=study-springboot-grafana-prometheus \
  maven:3.8.8-eclipse-temurin-21-alpine mvn spring-boot:run

Windows (PowerShell):

$srcPath = (Resolve-Path 'src').Path
$pomPath = (Resolve-Path 'pom.xml').Path

docker run --rm `
  -p 8080:8080 `
  -w /app `
  -v ${srcPath}:/app/src `
  -v ${pomPath}:/app/pom.xml `
  -v data:/root/.m2 `
  --network=study-springboot-grafana-prometheus_monitoring `
  --name=/study-springboot-grafana-prometheus-app-1 `
  --label com.docker.compose.project=study-springboot-grafana-prometheus `
  maven:3.8.8-eclipse-temurin-21-alpine mvn spring-boot:run

Back to Top

How to Test

Some endpoints to test the business metrics in Grafana.

Action URI Description
Flip a Coin GET http://localhost:8080/api/flipCoin Returns head or tail value and register a total count metric and another metric telling how many tails or heads

And below the Grafana Dashboards

Dashboard URL Description
Business Metrics http://localhost:3000/d/d5ae9a0e-e1b5-4e87-8a0a-d0720cc17a88/business-metrics Metrics added inside the application
JVM (Micrometer) http://localhost:3000/d/d815b226-48af-4ecd-89de-50782a2d0ada/jvm-micrometer Metrics related to the JVM
Spring Boot 3.x Statistics http://localhost:3000/d/spring_boot_21_2/spring-boot-3-x-statistics Metrics related to Spring Boot

Back to Top

📖 References

Back to Top

study-springboot-observability's People

Contributors

marciovmartins 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.