Actuator

Spring Boot Actuator is a built-in module that provides production-ready features to monitor and manage applications. It exposes various endpoints that provide insights into application health, metrics, environment, and other operational data. It simplifies monitoring by exposing endpoints that integrate seamlessly with tools like Prometheus and Grafana.

Features

One standout feature in recent versions is the SBOM (Software Bill of Materials) endpoint, which enhances security and compliance by exposing the list of software components in your application. This is particularly useful for teams working in regulated environments where tracking dependencies is critical.

Another key enhancement is the integration with Micrometer, a metrics collection facade that simplifies connecting your application to monitoring systems like Prometheus, Graphite, or Datadog. This integration has made it easier for me to set up comprehensive monitoring with minimal configuration.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
EndpointDescription
/actuator/healthShows app and component health (e.g., database status).
/actuator/infoDisplays custom app details, like version or build info.
/actuator/metricsLists metrics; drill down with /metrics/{name} (e.g., jvm.memory.used).
/actuator/mappingsLists all URL mappings, ideal for debugging endpoint setups.
/actuator/beansShows all Spring beans in the app context.
/actuator/envDisplays environment properties and configs.
/actuator/prometheusExposes metrics for Prometheus scraping.

Creating a Custom Endpoint

To expose custom data, like app version:

import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.stereotype.Component;

@Endpoint(id = "appInfo")
@Component
public class AppInfoEndpoint {
    @ReadOperation
    public String getVersion() {
        return "1.0.0";
    }
}

Access it at /actuator/appInfo. I’ve used this to expose environment-specific configs, simplifying debugging.

Prometheus

Prometheus is an open-source monitoring and alerting tookit designed for reliability and scalability. It collects and stores time-series data by pulling metrics from configured targets at specified intervals. It provides a query language (PromQL) for analysis. When paired with Spring Boot Actuator, Prometheus can scrape application metrics effortlessly.

Prometheus, an open-source monitoring system, scrapes metrics from HTTP endpoints (Prometheus Documentation). Its reliability, scalability, and Grafana integration make it a top choice. Benefits include:

Q - does prometheus only work with http endpoint

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
scrape_configs:
  - job_name: 'spring'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['localhost:8080']

https://www.linkedin.com/pulse/spring-boot-actuator-application-insights-bruno-santos-6m8bf/ https://uptrace.dev/blog/spring-boot-microservices-monitoring https://uptrace.dev/opentelemetry/collector/prometheus https://uptrace.dev/opentelemetry/collector/prometheus https://uptrace.dev/blog/spring-boot-microservices-monitoring https://batuhanorhon.medium.com/spring-boot-actuator-and-prometheus-with-an-example-application-90c88f7cc923