Actuator

Spring Actuator

Spring actuator๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ชจ๋‹ˆํ„ฐ๋ง ๋ฐ ๊ด€๋ฆฌ์—์„œ ๋„์›€์„ ์ค„ ์ˆ˜ ์žˆ๋‹ค.

  • ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ƒํƒœ์™€ ๋ฉ”ํŠธ๋ฆญ์„ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๊ณ  ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋Š” ๋ชจ๋“ˆ

HTTP ๋ฐฉ์‹๊ณผ JMX ๋ฐฉ์‹์ด ์žˆ์œผ๋ฉฐ HTTP ๋ฐฉ์‹์ด ์‚ฌ์šฉํ•˜๊ธฐ ํŽธํ•ด์„œ ์ฃผ๋กœ health check ์šฉ๋„๋กœ endpoint๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ ๊ฐ™๋‹ค.

# dependency
implementation ("org.springframework.boot:spring-boot-starter-actuator")

Actuator ์•ˆ์ „ํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๊ธฐ

Actuator๋Š” ๊ฐœ๋ฐœ์ž์—๊ฒŒ ํŽธ์˜๋ฅผ ์ฃผ๋Š” ๊ธฐ๋Šฅ์ด์ง€๋งŒ IP, ๋น„๋ฐ€๋ฒˆํ˜ธ์™€ ๊ฐ™์€ ์ค‘์š”ํ•œ ์ •๋ณด๋“ค์ด ์œ ์ถœ๋  ์ˆ˜ ์žˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด env endpoint๊ฐ€ ํ•„์š”ํ•˜์—ฌ ํ•ด๋‹น endpoint๋ฅผ expose ์‹œํ‚ค๋ฉด ํ•ด๋‹น ์„œ๋น„์Šค์˜ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๊ฐ€ ๋…ธ์ถœ ๋  ๊ฒƒ์ด๋‹ค.

1. ํ•„์š”ํ•œ endpoint๋Š” ํ™”์ดํŠธ๋ฆฌ์ŠคํŠธ ํ˜•ํƒœ๋กœ ์šด์˜ํ•œ๋‹ค.

Actuator๋Š” shut down endpoint๋ฅผ ์ œ์™ธํ•˜๊ณ  ๊ธฐ๋ณธ์œผ๋กœ enable๋กœ ํ™œ์„ฑํ™” ๋˜์–ด์žˆ๋‹ค.

์ด๋Ÿฐ ๊ธฐ๋ณธ ์„ค์ •์„ ๋”ฐ๋ฅด์ง€ ์•Š์œผ๋ ค๋ฉด management.endpoints.enabled-by-default=false๋กœ ์„ค์ •ํ•œ๋‹ค.

๋˜, ์šด์˜์ค‘์— ํ•„์š”ํ•œ endpoint๊ฐ€ ์žˆ๋‹ค๋ฉดmanagement.endpoint.[endpoint name].enable=true ์†์„ฑ์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜, ์—ฌ๋Ÿฌ endpoint๋ฅผ ์ง€์ •ํ•˜๋ ค๋ฉด management.endpoints.~.include ์†์„ฑ์„ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

  • includeํ•  ๋•Œ๋Š” ๊ผญ ํ•„์š”ํ•œ ์ •๋ณด๋งŒ ์ง€์ •ํ•˜๊ณ  asterisk(*) ์‚ฌ์šฉ์„ ์ง€์–‘ํ•˜์ž.

2. shutdown endpoint๋Š” ์ ˆ๋Œ€ enableํ•˜์ง€ ์•Š๋Š”๋‹ค.

์„œ๋น„์Šค ๊ฐ€์šฉ์„ฑ์„ ์นจํ•ดํ•  ์šฐ๋ ค๊ฐ€ ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค.

3. JMXํ˜•ํƒœ๋กœ Actuator ์‚ฌ์šฉ์ด ํ•„์š”ํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ, ๋ฐ˜๋“œ์‹œ disableํ•œ๋‹ค.

JMX๋Š” Default๋กœ expose๋˜์–ด์žˆ๋Š” endpoint๊ฐ€ ๋งŽ๊ธฐ ๋•Œ๋ฌธ์—, ์‚ฌ์šฉํ•˜์ง€ ์•Š์Œ์—๋„ enable ์‹œ์ผœ๋‘๋ฉด ์ž ์žฌ์  ์œ„ํ—˜์ด ๋  ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค.

management.endpoints.jmx.exposure.exclude: ์†์„ฑ์„ ์‚ฌ์šฉํ•œ๋‹ค.

4. Actuator endpoint์— ์ ‘๊ทผํ•  ๋•Œ๋Š” ์ธ์ฆ๋œ ์‚ฌ์šฉ์ž์™€ ๊ถŒํ•œ์ด ์กด์žฌํ•˜๋Š” ์‚ฌ์šฉ์ž๋งŒ์ด ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋„๋กํ•œ๋‹ค.

properties ์˜ˆ์‹œ

[์„ค์ • yml]

  • management.endpoints.web.base-path: /management

    • ๊ธฐ๋ณธ ๊ฒฝ๋กœ๋Š” /actuactor์ด๋‹ค. base-path๋ฅผ ์„ค์ •ํ•˜๋ฉด ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๋‹ค.

  • endpoints.web.expousre:

    • ๋’ค์— include, exclude ์˜ต์…˜์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Œ.

    • asterisk(*) ์‚ฌ์šฉ์„ ์ง€์–‘

  • endpoints.enabled-by-default:

    • true์ด๋ฉด shut down์„ ์ œ์™ธํ•œ endpoint๊ฐ€ ์ „๋ถ€ enable ๋˜์–ด์žˆ๋‹ค.

    • false๋กœ ํ•˜๊ณ  includeํ•ด๋„ ๋…ธ์ถœ๋˜์ง€ ์•Š๋Š”๋‹ค. ๋…ธ์ถœํ•˜๊ณ  ์‹ถ์œผ๋ฉด manage.endpoint:์—์„œ ์ž‘์„ฑํ•˜๋ฉด ๋œ๋‹ค.

Last updated