songining

Spring Actuator๋ž€? 

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ƒํƒœ๋ฅผ ๋ชจ๋‹ˆํ„ฐ๋ง, Metric ์ˆ˜์ง‘์„ ์œ„ํ•œ Http Endpoint๋ฅผ ์ œ๊ณตํ•ด์ฃผ๋Š” ๋ชจ๋“ˆ์ด๋‹ค. 

(์š”์•ฝํ•˜๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ƒํƒœ๋ฅผ ์ „์ฒด์ ์œผ๋กœ ์•Œ ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” ๊ธฐ๋Šฅ!)

 

    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator
    implementation 'org.springframework.boot:spring-boot-starter-actuator:3.0.1'

๋‹ค์Œ๊ณผ ๊ฐ™์ด dependency๋งŒ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. 

 

Ex) spring ์„ค์ • yaml ํŒŒ์ผ์— ์•„๋ž˜์™€ ๊ฐ™์ด ์–ด๋–ค endpoint๋“ค์„ ํฌํ•จํ• ์ง€ ๋ช…์‹œํ•ด์ฃผ๋ฉด ๋œ๋‹ค. 

management:
  endpoints:
    web:
      exposure:
        include: refresh,health,beans,httpexchanges

 

์ฃผ์š” ์—”๋“œ ํฌ์ธํŠธ ์ข…๋ฅ˜

beans 

- ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋ชจ๋“  Spring Bean ๋ชฉ๋ก์„ ํ‘œ์‹œํ•ด์ค€๋‹ค. 

- http://localhost:8080/actuator/beans

 

health (์ฃผ๋กœ ์‚ฌ์šฉํ•˜๋Š” endpoint)

- ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ํ˜„์žฌ ์ƒํƒœ ์ •๋ณด๋ฅผ ํ‘œ์‹œํ•œ๋‹ค.

- http://localhost:8080/actuator/health

 

httpexchanges(httptrace)

- ์ตœ๊ทผ 100๊ฐœ์˜ http ์š”์ฒญ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

management.trace.http.include=request-headers,response-headers,cookies,errors

๋…ธ์ถœ ์‹œ ํฌํ•จ์‹œํ‚ฌ ๊ด€๋ จ ์š”์†Œ๋“ค์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

@Bean
public InMemoryHttpExchangeRepository createTraceRepository() {
    return new InMemoryHttpExchangeRepository();
}

๋นˆ์œผ๋กœ InMemoryHttpExchangeRepository๋ฅผ ๋“ฑ๋กํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค. 

- http://localhost:8080/actuator/httpexchanges

 

env

- ์Šคํ”„๋ง์˜ ๋ชจ๋“  ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์ •๋ณด๋ฅผ ํ‘œ์‹œ (๋ณด์•ˆ์ƒ ๋น„์ถ”์ฒœ)

- management.endpoint.env.keys-to-sanitize ์†์„ฑ์„ ํ†ตํ•ด ๋ฏผ๊ฐํ•œ ์†์„ฑ์„ ๊ฐ€๋ฆด ์ˆ˜ ์žˆ๋‹ค.

- http://localhost:8080/actuator/env

 

metrics

- ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๊ฐ์ข… ์ง€ํ‘œ๋ฅผ ์ œ์‹œํ•œ๋‹ค. (CPU ์‚ฌ์šฉ๋ฅ , ์ปค๋„ฅ์…˜ํ’€..) 

- http://localhost:8080/actuator/metrics

- cpu ์‚ฌ์šฉ๋ฅ  ํ™•์ธ

http://localhost:8080/actuator/metrics/process.cpu.usage

 

conditions

- ์Šคํ”„๋ง ์ž๋™ configuration ๊ณผ ์ง์ ‘ ์„ค์ •ํ•œ configuration class๋“ค์˜ ์„ฑ๊ณต ์—ฌ๋ถ€์™€ ์ด์œ ๋ฅผ ์„ค๋ช…ํ•œ๋‹ค. 

- http://localhost:8080/actuator/conditions

 

refresh

- ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์„ค์ • ์ •๋ณด๋ฅผ refresh ํ•  ์ˆ˜ ์žˆ๋‹ค.

- [POST] http://localhost:8080/actuator/refresh

 

๊ทธ ์™ธ์—๋„ ๊ณต์‹ ๋ฌธ์„œ๋ฅผ ๋ณด๋ฉด ๋‹ค์–‘ํ•œ API ๋“ค์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. 

https://docs.spring.io/spring-boot/docs/3.0.x/actuator-api/htmlsingle/#httpexchanges

 

Spring Boot Actuator Web API Documentation

The conditions endpoint provides information about the evaluation of conditions on configuration and auto-configuration classes. 5.1. Retrieving the Report To retrieve the report, make a GET request to /actuator/conditions, as shown in the following curl-b

docs.spring.io

 

actuator๋Š” ๊ฐœ๋ฐœ์ž์—๊ฒŒ๋Š” ํŽธ์˜๋ฅผ ์ฃผ์ง€๋งŒ ๋ณด์•ˆ์ƒ ๋ฌธ์ œ๋กœ ์•ˆ์ „ํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ํ•„์š”๊ฐ€ ์žˆ๋‹ค. 

 

Spring Actuator ์•ˆ์ „ํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•

  • management.endpoints.enabled-by-default  ์†์„ฑ์„ false๋กœ ํ•˜์—ฌ ๋ชจ๋“  endpoint์— ๋Œ€ํ•ด disable ์ƒํƒœ๋ฅผ ์œ ์ง€ํ•˜๊ณ  ์šด์˜์ƒ ํ•„์š”ํ•œ endpoint๋งŒ true๋กœ ์„ค์ •ํ•˜์ž.
  • actuator endpoint๋Š” enable์‹œํ‚จ๋‹ค๊ณ  ๋ฐ”๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ expose์— ๋ช…์‹œํ•ด์ฃผ์–ด์•ผ ํ•˜๋Š”๋ฐ expose์— Includeํ•  ๋•Œ, aterisk(*)๊ฐ€ ์•„๋‹Œ ํ•„์š”ํ•œ endpoint๋งŒ ๋ช…์‹œํ•ด์ฃผ๋„๋ก ํ•˜์ž.

       ex) management.endpoints.web.exposure.include=health,httpexchanges

  •  acutator ์ ‘๊ทผํ•  ๋•Œ์—๋Š” ์ธ์ฆ์ด ๋œ ๊ถŒํ•œ์ด ์žˆ๋Š” ์‚ฌ์šฉ์ž๋งŒ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•˜๋„๋ก ํ•˜์ž. 
  • acutator๋Š” ์„œ๋น„์Šค ์šด์˜์— ์‚ฌ์šฉ๋˜๋Š” ํฌํŠธ์™€ ๋‹ค๋ฅธ ํฌํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
  • acutator default ๊ฒฝ๋กœ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ , ๊ฒฝ๋กœ๋ฅผ ๋ณ€๊ฒฝํ•˜์—ฌ ์šด์˜ํ•œ๋‹ค.

์ฐธ๊ณ 

https://techblog.woowahan.com/9232/

 

Security Actuator ์•ˆ์ „ํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๊ธฐ | ์šฐ์•„ํ•œํ˜•์ œ๋“ค ๊ธฐ์ˆ ๋ธ”๋กœ๊ทธ

{{item.name}} ์•ˆ๋…•ํ•˜์„ธ์š”, ์šฐ์•„ํ•œํ˜•์ œ๋“ค SOCํŒ€์—์„œ Application Security๋ฅผ ๋‹ด๋‹นํ•˜๊ณ  ์žˆ๋Š” ๊ถŒํ˜„์ค€์ž…๋‹ˆ๋‹ค. ์˜ค๋Š˜ ์ค€๋น„ํ•œ ์ฃผ์ œ๋Š” ๊ฐœ๋ฐœ์ž์—๊ฒŒ ํŽธ๋ฆฌํ•จ์„ ์ œ๊ณตํ•˜๋‚˜, ์ž˜๋ชป ์‚ฌ์šฉํ•˜๋ฉด ๋งค์šฐ ์œ„ํ—˜ํ•œ Actuator๋ฅผ ์•ˆ์ „ํ•˜

techblog.woowahan.com