Spring Boot Actuator는 Spring Boot 애플리케이션에 대한 모니터링, 관리 및 운영을 용이하게 만들어주는 라이브러리입니다.
애플리케이션의 상태, 메트릭, 애플리케이션 정보 등을 쉽게 확인할 수 있도록 다양한 기능을 제공합니다.
애플리케이션 상태 모니터링
애플리케이션 메트릭 수집
환경 정보 제공
애플리케이션의 로그 및 추적 기능
애플리케이션의 관리 기능 제공
Spring Boot Actuator는 기본적으로 다양한 HTTP 엔드포인트를 제공하여 애플리케이션의 상태를 확인하고 관리할 수 있게 해줍니다.
이 엔드포인트들은 http://localhost:8080/actuator/
경로에서 접근할 수 있습니다.
예시 응답:
{
"status": "UP",
"components": {
"db": {
"status": "UP"
}
}
}
예시 응답:
{
"jvm.memory.used": 1048576,
"jvm.threads.live": 45
}
예시 응답:
{
"propertySources": [
{
"name": "applicationConfig: [classpath:/application.yml]",
"properties": {
"spring.datasource.url": "jdbc:mysql://localhost:3306/mydb"
}
}
]
}
예시 응답:
{
"app": {
"name": "MyApp",
"version": "1.0.0"
}
}
예시 응답:
{
"levels": ["TRACE", "DEBUG", "INFO", "WARN", "ERROR"]
}
management.endpoints.web.exposure.include=shutdown
을 설정해야 합니다.Spring Boot에서 Actuator를 사용하려면, spring-boot-starter-actuator
의존성을 pom.xml
에 추가해야 합니다.
Maven 의존성:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Gradle 의존성:
implementation 'org.springframework.boot:spring-boot-starter-actuator'
기본적으로 Actuator는 모든 엔드포인트를 활성화하지 않습니다. 활성화하고 싶은 엔드포인트를 application.properties
또는 application.yml
파일에서 설정할 수 있습니다.
application.properties 예시:
management.endpoints.web.exposure.include=health,metrics,info
health
, metrics
, info
와 같은 엔드포인트를 활성화할 수 있습니다.application.yml 예시:
management:
endpoints:
web:
exposure:
include: health, metrics, info
Spring Boot Actuator는 기본 엔드포인트 외에도 사용자 정의 엔드포인트를 만들 수 있는 기능을 제공합니다.
@Component
public class CustomEndpoint extends AbstractEndpoint<String> {
public CustomEndpoint() {
super("custom");
}
@Override
public String invoke() {
return "Custom Endpoint Response";
}
}
위와 같이 사용자 정의 엔드포인트를 추가하고, /actuator/custom
에서 이를 호출할 수 있습니다.
Actuator 엔드포인트는 보안상의 이유로 기본적으로 보호되어야 합니다. 예를 들어, 민감한 엔드포인트인 /actuator/shutdown
은 기본적으로 비활성화되어 있고, 로그인 인증을 통해 보호할 수 있습니다.
management.endpoints.web.exposure.include=health,info,metrics
management.endpoint.health.show-details=always
management.endpoints.web.base-path=/actuator
보안을 강화하려면, Spring Security를 활용하여 엔드포인트 접근을 제어할 수 있습니다.
health
엔드포인트를 사용하여 배포 후 상태를 확인.추가 학습 자료