Skip to main content

๐Ÿš€ Spring Boot Actuator Explained: Health ๐Ÿฉบ, Metrics ๐Ÿ“Š & Info โ„น️ Endpoints with Examples!

๐ŸŒŸ Exploring Spring Boot Actuator Endpoints: health, metrics & info ๐Ÿš€

Spring Boot Actuator exposes many useful endpoints for monitoring your app. Among the most popular are health, metrics, and info. Let's break them down with simple examples and understand why each is like the superhero of your app's backstage! ๐Ÿฆธ‍♂️๐Ÿฆธ‍♀️


1️⃣ Health Endpoint ๐Ÿฉบ

The /actuator/health endpoint tells you whether your app is UP and running fine or if something is DOWN and broken. Think of it as your app's doctor giving you a quick check-up.

{

  "status": "UP",

  "components": {

    "db": {

      "status": "UP",

      "details": {

        "database": "PostgreSQL",

        "result": 1

      }

    },

    "diskSpace": {

      "status": "UP",

      "details": {

        "total": 499963174912,

        "free": 389963174912,

        "threshold": 10485760

      }

    }

  }

}

Joke time: Why don’t programmers like nature? It has too many bugs! ๐Ÿž๐Ÿ˜†


2️⃣ Metrics Endpoint ๐Ÿ“Š

The /actuator/metrics endpoint is like your app’s fitness tracker. It records tons of numbers about your app’s performance — CPU usage, memory, HTTP requests, garbage collection stats, and more.

Example output for JVM memory metrics:

{

  "name": "jvm.memory.used",

  "measurements": [

    { "statistic": "COUNT", "value": 120 },

    { "statistic": "TOTAL", "value": 12345678 },

    { "statistic": "MAX", "value": 9876543 }

  ],

  "availableTags": [

    { "tag": "area", "values": ["heap", "nonheap"] },

    { "tag": "id", "values": ["PS Eden Space", "Code Cache"] }

  ]

}

Fun fact: Java developers love metrics so much, they measure their coffee intake too ☕๐Ÿ“ˆ!


3️⃣ Info Endpoint โ„น️

The /actuator/info endpoint provides static or dynamic information about your application — version number, description, build time, or any custom info you want to expose.

Here’s a simple example configured via application.properties or application.yml:

{

  "app": {

    "name": "MyAwesomeApp",

    "version": "1.2.3",

    "description": "The coolest Spring Boot app in town!"

  }

}

Quick tip: Use info.app.version from your CI/CD pipeline to track deployments!

Joke break: Why did the Java developer go broke? Because he used up all his cache! ๐Ÿ’ธ๐Ÿ˜‚


๐Ÿ› ️ Creating Your Own Custom Health Endpoint

Spring Boot Actuator lets you create custom health checks to monitor anything important for your app — like an external API, cache, or custom service.

How to do it? Simply implement the HealthIndicator interface and override health() method.

import org.springframework.boot.actuate.health.Health;

import org.springframework.boot.actuate.health.HealthIndicator;

import org.springframework.stereotype.Component;

@Component

public class ExternalApiHealthIndicator implements HealthIndicator {

    @Override

    public Health health() {

        boolean apiIsUp = checkExternalApi();

        if (apiIsUp) {

            return Health.up().withDetail("External API", "Available").build();

        } else {

            return Health.down().withDetail("External API", "Not reachable").build();

        }

    }

    private boolean checkExternalApi() {

        // Replace with real API ping check

        return true; // assuming API is up

    }

}

When you call /actuator/health, your custom health status will appear like this:

{

  "status": "UP",

  "components": {

    "externalApiHealthIndicator": {

      "status": "UP",

      "details": {

        "External API": "Available"

      }

    },

    ...

  }

}

Joke break: Why did the health check fail? Because it forgot to ping the coffee machine ☕๐Ÿ’ฅ!


๐ŸŽฏ Wrapping Up

To sum up:

  • Health = The app's heartbeat ๐Ÿซ€
  • Metrics = The app's workout stats ๐Ÿ‹️‍♂️
  • Info = The app's ID card ๐Ÿ†”
They work together to help you keep your app running smoothly and make your life as a developer or operator easier!

Start using these actuator endpoints today and feel like a superhero in your own production world! ๐Ÿฆธ‍♂️๐Ÿฆธ‍♀️

Comments

Popular posts from this blog

๐Ÿ” Is final Really Final in Java? The Truth May Surprise You ๐Ÿ˜ฒ

๐Ÿ’ฌ “When I was exploring what to do and what not to do in Java, one small keyword caught my eye — final . I thought it meant: locked, sealed, frozen — like my fridge when I forget to defrost it.”   But guess what? Java has its own meaning of final… and it’s not always what you expect! ๐Ÿ˜… Let’s break it down together — with code, questions, confusion, jokes, and everything in between. ๐ŸŽฏ The Confusing Case: You Said It's Final... Then It Changed?! ๐Ÿซ  final List<String> names = new ArrayList <>(); names.add( "Anand" ); names.add( "Rahul" ); System.out.println(names); // [Anand, Rahul] ๐Ÿคฏ Hold on... that’s final , right?! So how on earth is it still changing ? Time to dive deeper... ๐Ÿง  Why Is It Designed Like This? Here’s the key secret: In Java, final applies to the reference , not the object it points to . Let’s decode this like a spy mission ๐Ÿ•ต️‍♂️: Imagine This: final List<String> names = new ArrayList <>(); Be...

๐ŸŽข Java Loops: Fun, Fear, and ForEach() Fails

๐ŸŒ€ Oops, I Looped It Again! — The Ultimate Java Loop Guide You Won't Forget “I remember this question from one of my early interviews — I was just 2 years into Java and the interviewer asked, ‘Which loop do you prefer and why?’” At first, I thought, “Duh! for-each is cleaner.” But then he grilled me with cases where it fails. ๐Ÿ˜ต That led me to explore all loop types, their powers, and their pitfalls. Let’s deep-dive into every major Java loop with examples &  real-world guidance so you'll never forget again. ๐Ÿ” Loop Type #1: Classic For Loop — “The Old Reliable” ✅ When to Use: You need an index You want to iterate in reverse You want full control over loop mechanics ✅ Good Example: List<String> names = List.of("A", "B", "C"); for (int i = 0; i < names.size(); i++) { System.out.println(i + ": " + names.get(i)); } ๐Ÿ”ฅ Reverse + Removal Example: List<String> item...

๐Ÿงต Virtual Threads in Java — The Ultimate Guide with Diagrams, Code & Interview Qs!

๐Ÿš€ “How are Virtual Threads different from Thread Pools?” ๐Ÿ˜ต “Are they OS threads or JVM threads?” ๐Ÿ™ƒ “Should I still use CompletableFuture?” ๐Ÿคฏ “How do I even use them in real-time microservices?” ๐Ÿง  What are Virtual Threads? Virtual Threads (introduced in Java 21 as stable ๐ŸŽ‰) are lightweight threads managed by the JVM instead of the OS kernel. ๐Ÿ‘‰ They look like normal threads, but don’t hog OS resources like traditional threads. ๐Ÿง  What is the OS Kernel? ๐Ÿ›️ OS Kernel = The Brain of the Operating System It’s the core part of your OS (Windows, Linux, Mac) that: Manages memory ๐Ÿง  Schedules threads ๐Ÿ•’ Talks to hardware ๐Ÿ’ป Handles I/O operations ๐Ÿ“จ When you create a traditional thread in Java, the JVM asks the OS Kernel to create a real OS-level thread. ๐Ÿ–ผ️ Imagine This... ┌───────────────────────────┐ │ Your Java Application │ └────────────┬──────────────┘ │ ...