2023. 5. 15. 11:39ใ์ธํ๋ฐ/์คํ๋ง ๋ถํธ - ํต์ฌ ์๋ฆฌ์ ํ์ฉ
์คํ๋ง๋ถํธ Actuator (tistory.com)
์คํ๋ง๋ถํธ Actuator
1๏ธโฃ Spring Actuator ์ค๋ฌด์์๋ ๊ฐ๋ฐ์ ํ๋ค ํ๋ฉด ์๊ตฌ์ฌํญ๋๋ก ๊ฐ๋ฐ์ ํ๋ ๊ฒ์ ๋์ด์ ๋ง๋ ์๋น์ค์ ๋ฌธ์ ๊ฐ ์๋์ง ์๋์ง ๋ชจ๋ํฐ๋งํ๊ณ ์งํ๋ค์ ์ฌ์ด์ ๊ฐ์ํ๋ ํ๋์ด ํ์ํ๋ค. ์ด๋ฐ ํ
hyejin.tistory.com
์ ๋ฒ ๊ธ์์ ์คํ๋ง ์ก์ธ์์ดํฐ, ์ฌ์ฉ ๋ฐฉ๋ฒ, ์ค์ ํ๋ ๋ฐฉ๋ฒ ๋ฑ์ ๋ํด์ ๋ฐฐ์ ๋ค.
๊ทธ๋ฆฌ๊ณ ๋ง์ง๋ง์ ์คํ๋ง๋ถํธ๊ฐ ์ ๊ณตํ๋ ๋ค์ํ ์ค๋ํฌ์ธํธ์ ๋ํด์ ์ข ๋ฅ๋ฅผ ๋ดค๋๋ฐ ๊ทธ ์ค ์์ฃผ? ์ฌ์ฉํ๋ ๊ฒ๋ค์ ์์๋ณผ ๊ฒ์ด๋ค.
1๏ธโฃ health
health ์ ๋ณด๋ฅผ ์ฌ์ฉํ๋ฉด ์ ํ๋ฆฌ์ผ์ด์ ์์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ ๋ ๋ฌธ์ ๋ฅผ ์ข ๋ ๋น ๋ฅด๊ฒ ์ธ์งํ ์ ์๋ค.
http://localhost:8080/actuator/health
์๋ฌด ์ค์ ์์ด health ๋ฅผ ๋ณด๋ฉด ๋จ์ํ ์ ํ๋ฆฌ์ผ์ด์ ์ด ๋์ํ๋์ง ์ํ๋ง ํ์ธํ ์ ์๋ค.
์ถ๊ฐ๋ก ์ค์ ํ๋ฉด ์ ํ๋ฆฌ์ผ์ด์ ์ด ์ฌ์ฉํ๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค๊ฐ ์๋ตํ๋์ง, ๋์คํฌ ์ฌ์ฉ๋์ ๋ฌธ์ ๊ฐ ์๋์ง ๋ฑ์ ์ ๋ณด๋ฅผ ํฌํจํด์ ํ์ธํ ์ ์๋ค.
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
shutdown:
enabled: true
health:
show-details: always
management.endpoint.health.show-details ๋ฅผ always๋ก ์ค์ ํด์ฃผ๋ฉด ํฌ์ค ์ ๋ณด๋ฅผ ์ข ๋ ์์ธํ ํ์ธํ ์ ์๋ค.
-> ์ด๋ ๊ฒ ๊ฐ๊ฐ์ ํญ๋ชฉ์ด ์์ธํ๊ฒ ๋ ธ์ถ๋๋๋ฐ ์ด๋ ๊ฒ ๋ ธ์ถ๋๋๊ฒ ๋ถ๋ด์ค๋ฝ๋ค๋ฉด show-detail ์ต์ ์ ๋๊ณ show-components ์ต์ ์ ํค๋ฉด ๋๋ค. ๊ทธ๋ฌ๋ฉด ๋ฐ์ ์์ธํ ์ ๋ณด๋ ์๋์ค๊ณ status ์ ๋๋ง ๋ํ๋๊ฒ ๋๋ค.
* ๊ทธ๋ฆฌ๊ณ ์ด๋ ํฌ์ค ์ปดํฌ๋ํธ ์ค์ ํ๋๋ผ๋ ๋ฌธ์ ๊ฐ ์๋ค๋ฉด ์ ์ฒด ์ํ๋ DOWN์ด ๋๋ค.
2๏ธโฃ info
info ๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ธฐ๋ณธ ์ ๋ณด๋ฅผ ๋ ธ์ถํ๋ค.
๊ธฐ๋ณธ์ผ๋ก ์ ๊ณตํ๋ ์ ๋ณด๋ค๋ก๋
- java : ์๋ฐ ๋ฐํ์ ์ ๋ณด
- os : OS ์ ๋ณด
- env : Environment ์์ info ๋ก ์์ํ๋ ์ ๋ณด
- build : ๋น๋ ์ ๋ณด -> META-INF/build-info.properties ํ์ผ ํ์
- git : git ์ ๋ณด -> git.properties ํ์ผ ํ์
๊ทธ๋ฆฌ๊ณ ์ด๋ java, os, env ๋ ๋นํ์ฑํ ๋์ด ์๊ธฐ ๋๋ฌธ์ ํ์ธํ๋ ค๋ฉด ํ์ฑํํด์ค์ผ ํ๋ค.
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
shutdown:
enabled: true
health:
show-details: always
info:
java:
enabled: true
os:
enabled: true
env:
enabled: true
management.info.java, os, env ๋ฅผ true๋ก ์ค์ ํด์ฃผ๋ฉด ํ์ฑํ๋๋ค.
๊ทธ๋ฆฌ๊ณ /actuator/info ํ๋ฉด java, os, env ์ ๋ณด๋ฅผ ํ์ธํ ์ ์๋ค.
build ์ ๋ณด๋ฅผ ๋ ธ์ถํ๋ ค๋ฉด META-INF/build-info.propertiesํ์ผ์ด ํ์ํ๋ฐ
springBoot {
buildInfo()
}
build.gradle์ ์์ ์ฝ๋๋ฅผ ์ถ๊ฐํ๊ณ build ํด์ฃผ๋ฉด ํ์ผ์ด ์์ฑ๋๋ค.
๊ทธ๋ฆฌ๊ณ git ์ ๋ณด๋ฅผ ๋ ธ์ถํ๋ ค๋ฉด git.properties ํ์ผ์ด ํ์ํ๊ณ ,
id "com.gorylenko.gradle-git-properties" version "2.4.1" //git info
build.gradle์ plugin์ผ๋ก ์ด๊ฑธ ์ถ๊ฐํด์ค์ผ ํ๋ค.
(๊ทธ๋ฆฌ๊ณ ๋น์ฐํ๊ฑด๋ฐ ํด๋น ํ๋ก์ ํธ๊ฐ ๊น์ผ๋ก ๊ด๋ฆฌ๋๊ณ ์์ด์ผ ํ๋ค.)
3๏ธโฃ logger
logger ์ค๋ํฌ์ธํธ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ก๊น ๊ณผ ๊ด๋ จ๋ ์ ๋ณด๋ฅผ ํ์ธํ๊ณ , ๋ ์ค์๊ฐ์ผ๋ก logging level์ ๋ณ๊ฒฝํ ์ ์๋ค.
LogController
@Slf4j
@RestController
public class LogController
{
@GetMapping("/log")
public String log()
{
log.trace("trace log");
log.debug("debug log");
log.info("info log");
log.warn("warn log");
log.error("error log");
return "ok";
}
}
application.yml
logging:
level:
hello.controller: debug
applicationi.yml์ hello.controller ํจํค์ง ํฌํจ ํ์ ํจํค์ง๋ debug ๋ ๋ฒจ๋ก ์ถ๋ ฅํ๋๋ก ํ๋ค.
๊ทธ ๋ค์ http://localhost:8080/log ํ๋ฉด
debug ๋ ๋ฒจ๊น์ง ์ถ๋ ฅ๋๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
http://localhost:8080/actuator/loggers ๋ฅผ ํ๋ฉด
์ด๋ ๊ฒ ๋ก๊น ๊ณผ ๊ด๋ จ๋ ์ ๋ณด๋ฅผ ํ์ธํ ์ ์๊ณ ,
์ฐ๋ฆฌ๊ฐ ์ค์ ํ LogController๋ ๋ ๋ฒจ์ด debug์ธ ๊ฒ์ ํ์ธํ ์ ์๋ค. (๋ณ๋ ์ค์ ์์ผ๋ฉด info๊ฐ ๊ธฐ๋ณธ)
๊ทธ๋ฆฌ๊ณ ๋ ์์ธํ
http://localhost:8080/actuator/loggers/hello.controller
{๋ก๊ฑฐ ์ด๋ฆ} ์ผ๋ก ์กฐํํ๋ฉด ์ข ๋ ์์ธํ๊ฒ ์กฐํํ ์ ์๋ค.
* ์ค์๊ฐ ๋ก๊ทธ ๋ ๋ฒจ ๋ณ๊ฒฝ
๊ทธ๋ฆฌ๊ณ loggers ์ค๋ํฌ์ธํธ๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ค์ ์์ํ์ง ์๊ณ ์ค์๊ฐ์ผ๋ก ๋ก๊ทธ ๋ ๋ฒจ์ ๋ณ๊ฒฝํ ์๋ ์๋ค.
http://localhost:8080/actuator/loggers/{๋ก๊ฑฐ์ด๋ฆ} ์ POST๋ก ์์ฒญํ๊ณ
configuredLevel์ ์ํ๋ ๋ ๋ฒจ๋ก ์ง์ ํด์ ์์ฒญํ๊ณ , ์์ฒญ ์ฑ๊ณตํ๋ฉด 204 ์๋ต์ด ์จ๋ค.
4๏ธโฃ HTTP ์์ฒญ ์๋ต ๊ธฐ๋ก : httpexchanges
httpexchanges ์ค๋ํฌ์ธํธ๋ฅผ ํตํด์ HTTP ์์ฒญ๊ณผ ์๋ต์ ๊ณผ๊ฑฐ ๊ธฐ๋ก์ ํ์ธํ ์ ์๋ค.
HttpExchangeRepository ์ธํฐํ์ด์ค์ ๊ตฌํ์ฒด๋ฅผ ๋น์ผ๋ก ๋ฑ๋กํ๋ฉด httpexchanges ์ค๋ํฌ์ธํธ๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
(์คํ๋ง ๋ถํธ๋ ๊ธฐ๋ณธ์ผ๋ก InMemoryHttpExchangeRepository ๊ตฌํ์ฒด๋ฅผ ์ ๊ณต)
@SpringBootApplication
public class ActuatorApplication {
public static void main(String[] args) {
SpringApplication.run(ActuatorApplication.class, args);
}
@Bean
public InMemoryHttpExchangeRepository httpExchangeRepository()
{
return new InMemoryHttpExchangeRepository();
}
}
InMemoryHttpExchangeRepository๋ฅผ ๋น์ผ๋ก ๋ฑ๋กํด์ค ๋ค์
http://localhost:8080/actuator/httpexchanges ์คํํด๋ณด๋ฉด
์ง๊ธ๊น์ง ์คํํ๋ HTTP ์์ฒญ๊ณผ ์๋ต ์ ๋ณด๋ฅผ ํ์ธํ ์ ์๋ค.
(์ฐ๋ฆฌ๊ฐ ์์ฒญํ๋ /log ๋ ์๋ ๊ฒ์ ํ์ธํ ์ ์๋ค. )
* ๊ทผ๋ฐ httpexchanges ๋ ๋งค์ฐ ๋จ์ํ๊ณ ๊ธฐ๋ฅ์ ์ ํ์ด ๋ง๊ธฐ ๋๋ฌธ์ ๊ฐ๋ฐ ๋จ๊ณ์์๋ง ์ฌ์ฉํ๊ณ ,
์ค์ ์ด์ ์๋น์ค์์๋ ๋ชจ๋ํฐ๋ง ํด์ด๋ ํํฌ์ธํธ, Zipkin ๊ฐ์ ๊ธฐ์ ์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข๋ค๊ณ ํ๋ค.
5๏ธโฃ ์ก์ธ์์ดํฐ์ ๋ณด์
๋ณด๋ฉด ์ก์ธ์์ดํฐ๋ ํธ๋ฆฌํ๊ฒ ์ ํ๋ฆฌ์ผ์ด์ ์ํ ๋ฑ์ ํ์ธํ ์ ์์ง๋ง, ์ ํ๋ฆฌ์ผ์ด์ ๋ด๋ถ ์ ๋ณด๋ฅผ ๋๋ฌด ๋ง์ด ๋ ธ์ถํ๊ฒ ๋๋ค.
๊ทธ๋์ ๊ณต๊ฐ๋ ๊ณณ์ ์ก์ธ์์ดํฐ์ ์ค๋ ํฌ์ธํธ๋ค์ ๊ณต๊ฐํ๋ ๊ฒ์ ์ข์ง ์๋ค.
-> ์ก์ธ์์ดํฐ์ ์ค๋ํฌ์ธํธ๋ค์ ์ธ๋ถ ์ธํฐ๋ท์์ ์ ๊ทผ์ด ๋ถ๊ฐ๋ฅํ๊ฒ ๋ง๊ณ , ๋ด๋ถ์์๋ง ์ ๊ทผ ๊ฐ๋ฅํ ๋ด๋ถ๋ง์ ์ฌ์ฉํ๋ ๊ฒ์ด ์์ ํ๋ค.
* ์ก์ธ์์ดํฐ๋ฅผ ๋ค๋ฅธ ํฌํธ์์ ์คํ
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
shutdown:
enabled: true
health:
show-details: always
info:
java:
enabled: true
os:
enabled: true
env:
enabled: true
server:
port: 9292
management.server.port = 9292 ๋ก ์ค์ ํด์ ์ก์ธ์์ดํฐ ๊ธฐ๋ฅ์ ์ฌ์ฉํ๋ ค๋ฉด ์ ํ๋ฆฌ์ผ์ด์ ์๋ฒ์๋ ๋ค๋ฅธ ํฌํธ์์ ์คํํ๋๋ก ์ค์ ํด์ค ์ ์๋ค.
* ์ก์ธ์์ดํฐ URL ๊ฒฝ๋ก์ ์ธ์ฆ ์ค์
์์ ๋ฐฉ๋ฒ์ฒ๋ผ ํฌํธ๋ก ๋ถ๋ฆฌํ๋ ๊ฒ์ด ์ด๋ ต๋ค๋ฉด /actuator ๊ฒฝ๋ก์ ์๋ธ๋ฆฟ ํํฐ ๋๋ ์คํ๋ง ์ธํฐ์ ํฐ, ์คํ๋ง ์ํ๋ฆฌํฐ๋ฅผ ํตํด์ ์ธ์ฆ๋ ์ฌ์ฉ์๋ง ์ ๊ทผํ๊ณ ์ฌ์ฉํ ์ ์๋๋ก ์ถ๊ฐ ๊ฐ๋ฐ์ด ํ์ํ๋ค.
* ์ค๋ํฌ์ธํธ ๊ฒฝ๋ก ๋ณ๊ฒฝ
/actuator ๊ฒฝ๋ก ๋์ ์ ๊ธฐ๋ณธ ๊ฒฝ๋ก๋ฅผ ๋ณ๊ฒฝํด์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ๋ ์๋ค.
management.endpoints.web.base-path = "" ๋ก ์ค์ ํ๋ฉด ๊ฒฝ๋ก๋ฅผ ๋ณ๊ฒฝํ ์๋ ์๋ค.
'์ธํ๋ฐ > ์คํ๋ง ๋ถํธ - ํต์ฌ ์๋ฆฌ์ ํ์ฉ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์คํ๋ง & ํ๋ก๋ฉํ ์ฐ์ค (์ค์น, ์ค์ , ๊ธฐ๋ณธ ๊ธฐ๋ฅ) (0) | 2023.05.18 |
---|---|
์คํ๋ง ๋ชจ๋ํฐ๋ง (์ก์ธ์์ดํฐ, ๋ง์ดํฌ๋ก๋ฏธํฐ, ๋ฉํธ๋ฆญ, ํ๋ก๋ฉํ ์ฐ์ค, ๊ทธ๋ผํ๋) (0) | 2023.05.16 |
์คํ๋ง๋ถํธ Actuator (0) | 2023.05.15 |
์คํ๋ง YAML, @Profile (0) | 2023.05.11 |
์คํ๋ง ์ธ๋ถ ์ค์ ์ฌ์ฉ ๋ฐฉ๋ฒ (Environment) (0) | 2023.05.11 |