Web/환경설정 관련

스프링 부트 모니터링 (1) - 액추에이터 기본 설정

now0204 2024. 5. 14. 13:57

 

액추에이터란 

  • 스프링 부트 애플리케이션 모니터링과 관리에 필요한 기능을 제공
  • 운영에 필요한 광범위한 기능을 직접 구현할 필요 없이 쉽게 사용할 수 있다.

 

1. 액추에이터 기본 설정 

  • 액추에이터 관련 의존관계를 추가한다. 
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '3.2.4'
  • spring-boot-starter-actuator에는 spring-boot-actuator-autoconfigure와 micrometercore 의존 관계가 포함되어 있다.
  • autoconfigure는 엑추에이터 핵심 기능과 자동 구성 설정이 포함돼 있고, micrometercore에는 다양한 측정지표를 수집할 수 있는 마이크로미터 지원 기능이 포함돼 있다. 
  • application.properties 파일에 managment.endpoints.web.exposure.include 프로퍼티를 사용해서 노출할 엔드포인트를 지정할 수 있다. 
management.endpoints.web.exposure.include=* 
#전부 노출
management.endpoints.web.exposure.include=info,health
#특정 엔드 포인트만 노출

  • 기본적으로 노출되어 잇는 health 엔드포인트에 접속하면, 위와 같이 모니터링 결과를 얻을 수 있다.
  • 엔드포인트별로 얻을 수 있는 애플리케이션 정보는 커스터마이징이 가능하다. 

2. 엔드 포인트에 대해 

 

  • 엑추에이터는 health 엔드포인트 말고 다양한 엔드포인트를 기본으로 지원한다. (커스텀도 가능)
  • 엑추에이터 엔드포인트는 웹 또는 JMX(Java Management Extensions)를 통해 호출 할 수 있다.
  • 엔드포인트 노출 여부는 직접 설정할 수 있다. 기본적으로 health와 info는 HTTP로 개방되어 있고, JMX는 HTTP보다 보안성이 높기 때문에 스프링 부트가 제공하는 모든 엔드포인트는 JMX에서 개방되어 있다.  
  • /acuator로 접속하면, 엔드포인트들의 대략적인 상태를 볼 수 있다. 

모든 엔드포인트 개방

  • templated값이 true면, url끝에 달린 {toMatch}, {name}, {prefix}등에 원하는 값을 지정할 수 있다.
  • /actuator/caches/{cache}에 특정 cache이름을 지정하면, 해당 캐시의 상태를 확인할 수 있다. 
  • 기본적으로 제공되는 엔드포인트 list와 JMX 혹은 HTTP 개방 여부는 밑에 공식문서에서 확인할 수 있다.

https://docs.spring.io/spring-boot/docs/2.1.13.RELEASE/reference/html/production-ready-endpoints.html

 

53. Endpoints

Actuator endpoints let you monitor and interact with your application. Spring Boot includes a number of built-in endpoints and lets you add your own. For example, the health endpoint provides basic application health information. Each individual endpoint c

docs.spring.io


 

3. 엔드포인트 관리 

 

3.1 엔드포인트 노출 여부 결정 

management.endpoints.web.exposure.include=* 
management.endpoints.web.exposure.exclude=threaddump,heapdump,health
  • application.properties 혹은 yml 파일에서 위와 같이 include, exclude를 활용해서 노출여부를 간단하게 조절할 수 있다. 

3.2 엔드포인트 url 변경 

management.endpoints.web.base-bath=hi
  • 기본 url인 /actuator/{endpoints}에서 /actuator를 원하는 url로 변경할 수 있다.
  • 위와 같이 변경하면, /acuator가 아닌 /hi/{endpoints}로 변경된다. 

3.3 엔드포인트 port 변경 

management.server.port=8081
  • 위와 같이 변경하면, 엑추에이터의 web port도 변경할 수 있다.

3.4 엔드포인트 이름 변경 

management.endpoints.web.path-mapping.health=myhealth
  • 위 설정을 사용하면, 특정 엔드포인트(ex health)를 원하는 엔드포인트로 변경할 수 있다. 

결론적으로 위의 설정을 모두 적용하면, localhost:8081/hi/myhealth가 기존 엔드포인트 url을 대체한다. 

 


 

참고자료:

https://www.yes24.com/Product/Goods/122002340

 

실전 스프링 부트 - 예스24

인류에겐 이런 스프링 부트 가이드북이 필요했다방대한 스프링 부트 공식 문서 중 실무에서 잘 쓰이는 팁을 찾기란 어렵다. 이 책은 초급에서 중급 수준의 독자를 대상으로 스프링 부트의 기본

www.yes24.com

https://docs.spring.io/spring-boot/docs/2.1.13.RELEASE/reference/html/production-ready-endpoints.html

 

53. Endpoints

Actuator endpoints let you monitor and interact with your application. Spring Boot includes a number of built-in endpoints and lets you add your own. For example, the health endpoint provides basic application health information. Each individual endpoint c

docs.spring.io