hara
Spring Boot 2.0 - 10장: 스프링 부트 액튜에이터 본문
#Spring boot Actuator 란?
"스프링 부트 애플리케이션에서 제공하는 여러가지 정보를 모니터링하기 쉽게 해주는 기능"
컨텍스트 빈, 환경 설정, 자동 설정, JVM 상태 등 필요한 정보를 얻어서 가공할 수 있고, 모니터링할 수 있다.
#활성화
- dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
- property
//노출 정보
management.endpoints.web.exposure.include=*
//비노출 정보
management.endpoints.web.exposure.exclude=env,beans
- endPoints
ID | Description |
beans | application의 전체 Spring beans |
cashes | 사용가능한 cache |
conditions | configuration 또는 auto-configuration 되는 class들의 성공 여부와 이유 |
env | Spring Boot의 현재 환경설정 정보(application.yml의 정보 등) |
health | application의 현재 상태 |
httptrace | http를 trace한 정보 |
mappings | Request와 mapping되어있는 handler 정보 |
sessions | Spring Session이 가지고 있는 정보 |
threaddump | threaddump 정보 |
logfile | log 정보 |
metrics | metrics 정보 |
#사용자 정의 상태 체크
- HealthIndicator를 구현하여 정의할 수 있다.
- 원하는 상태를 등록하여 체크 할 수 있다.
//properties
# 심각도에 따른 순서
management.health.status.order=DOWN, MAINTENANCE, UNKOWN, UP
# 각 상태별 Http 응답 코드
management.health.status.http-mapping.DOWN=503
management.health.status.http-mapping.MAINTENANCE=503
management.health.status.http-mapping.UNKNOWN=200
management.health.status.http-mapping.UP=200
--------------------------------------------------------------------------------
//controller
@RestController
@RequestMapping("${management.endpoints.web.base-path:/actuator}")
public class CustomHealthIndicator implements HealthIndicator {
private final AtomicReference<Health> health = new AtomicReference<>(Health.up().build());
@Override
public Health health() {
return health.get();
}
@PutMapping("${management.endpoints.web.path-mapping.health:health}/up")
public Health up() {
Health up = Health.up().build();
this.health.set(up);
return up;
}
@PutMapping("${management.endpoints.web.path-mapping.health:health}/down")
public Health down() {
Health down = Health.down().build();
this.health.set(down);
return down;
}
@PutMapping("${management.endpoints.web.path-mapping.health:health}/maintenance")
public Health maintenance() {
Health maintenance = Health.status(new Status("MAINTENANCE", "점검중")).build();
this.health.set(maintenance);
return maintenance;
}
}
#매트릭(Metrics)
- JVM 정보
- thread 수
- GC 정보
- heap 정보
- DBCP 정보
- PROCESS 관련 정보
- CPU
- USAGE
- LOAD
- FILE
- 최대 사용가능한 File Descriptor 수
- 현재 사용중인 File Descriptor 수
#Actuator 한계점
actuator는 상당히 민감한 정보를 많이 볼수 있다.
그렇기 때문에 개발이 아닌 운영시에는 특정 사용자만 접근하도록 하는 식으로 보안에 철저하게 신경써야 한다.
그리고 실제 운영에서 잘 사용하기 위해서는 영구저장소인 DB나 file 등을 활용해서 저장될 필요가 있다.
#참고
- 책: Spring Boot2 Recipes 10장
- supawer0728.github.io/2018/05/12/spring-actuator/
'공부 > 스프링 부트 2 레시피' 카테고리의 다른 글
Spring Boot 2.0 - 11장: 패키징 (0) | 2020.10.05 |
---|---|
Spring Boot 2.0 - 9장: 메시징 (0) | 2020.09.16 |
Spring Boot 2.0 - 8장: 자바 엔터프라이즈 서비스 (0) | 2020.09.16 |
Spring Boot 2.0 - 4장: 스프링 MVC - 비동기 (0) | 2020.09.16 |
Spring Boot 2.0 - 7장: 데이터 처리 (0) | 2020.09.16 |
Comments