Actuator Deep Dive
spring-boot-starter-actuator DEPENDENCY ADD karте hi, Spring Boot DOZENS of PRODUCTION-READY MONITORING ENDPOINTS AUTOMATICALLY EXPOSE karta hai — /health (application ZINDA hai?), /info (custom APPLICATION METADATA), /metrics (CPU, MEMORY, HTTP REQUEST COUNTS), /env (ENVIRONMENT VARIABLES, PROPERTIES), /beans (SAARI REGISTERED BEANS), /mappings (SAARI URL MAPPINGS).
SECURITY ke liye, DEFAULT mein SIRF /health aur /info EXPOSED hote hain — BAAKI, EXPLICITLY management.endpoints.web.exposure.include se ENABLE karne padte hain. Production mein, PROPER AUTHENTICATION/AUTHORIZATION ke SAATH SECURE kiya jaata hai, kyunki YE ENDPOINTS SENSITIVE INFORMATION REVEAL kar sakte hain.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
# application.properties:
management.endpoints.web.exposure.include=health,info,metrics,env,beans
management.endpoint.health.show-details=always
# Custom info contributor:
@Component
public class BuildInfoContributor implements InfoContributor {
public void contribute(Info.Builder builder) {
builder.withDetail("build", Map.of("version", "1.2.3", "commit", "a1b2c3d"));
}
}
// GET /actuator/info → { "build": { "version": "1.2.3", "commit": "a1b2c3d" } }- Dozens of built-in endpoints — /health, /metrics, /env, /beans, /mappings, /loggers
- DEFAULT mein SIRF /health aur /info EXPOSED — baaki EXPLICITLY ENABLE karo
- Production mein AUTHENTICATION ke saath SECURE karna ESSENTIAL hai
Actuator DOZENS of BUILT-IN endpoints DETA hai — /health, /info, /metrics, /env (environment variables), /beans (SAARI registered beans), /mappings (SAARI URL mappings), /loggers (RUNTIME mein LOG LEVELS change karna), /threaddump, /heapdump.
InfoContributor INTERFACE IMPLEMENT karके, /actuator/info endpoint mein CUSTOM DATA ADD ki ja sakti hai — jaise BUILD VERSION, GIT COMMIT HASH, DEPLOYMENT TIMESTAMP — DEBUGGING/AUDITING ke liye USEFUL.
@Component
public class BuildInfoContributor implements InfoContributor {
public void contribute(Info.Builder builder) {
builder.withDetail("build", Map.of(
"version", "1.2.3",
"commit", "a1b2c3d"
));
}
}