
- ์คํ๋ง ๋ถํธ๊ฐ ์ ๊ณตํ๋ ๊ฐ๋ ฅํ ๋ชจ๋ํฐ๋ง ๋ฐ ๊ด๋ฆฌ ๋๊ตฌ
- ๋ง์ดํฌ๋ก๋ฏธํฐ, ํ๋ก๋ฉํ ์ฐ์ค, ๊ทธ๋ผํ๋ ๊ฐ์ ๋ชจ๋ํฐ๋ง ์์คํ ๊ณผ ๋งค์ฐ ์ฝ๊ฒ ์ฐ๋ ๊ฐ๋ฅ
implementation 'org.springframework.boot:spring-boot-starter-actuator'
http://localhost:8080/actuator ๋ฅผ ์คํํ์ ๋ ์ด๋ฌํ ์ ๋ณด๋ค์ด ๋์ค๋ ๊ฒ์ ํ์ธ ํ ์ ์๋ค.{
"_links": {
"self": {
"href": "http://localhost:8080/actuator",
"templated": false
},
"health-path": {
"href":
"http://localhost:8080/actuator/health/{*path}",
"templated": true
},
"health": {
"href": "http://localhost:8080/actuator/health",
"templated": false
}
}
ํ๋ฉด์ ๋ณด์ด๋ http://localhost:8080/actuator/health๋ฅผ ์คํํด๋ณด๋ฉด
{"status": "UP"}
๋ฅผ ํ์ธ ํ ์์๋ ๋ฐ ์ด ์ ๋ณด๋ ์๋ฒ๊ฐ ์ ๋์ํ๊ณ ์๋์ง ์ ํ๋ฆฌ์ผ์ด์
ํฌ์ค ์ํ๋ฅผ ๋ณด์ฌ์ค๋ค.
ํ์ง๋ง ์ด๊ฑด ํฌ์ค ์ํ๋ง ๋ณด์ฌ์ฃผ๋ ๊ฒ์ด๊ณ
management:
endpoints:
web:
exposure:
include: "*"
์ ์ค์ ํด์ฃผ๊ณ (์ฐธ๊ณ ๋ก shutdown์ ์ ์ธํ ๋ชจ๋ ์๋ํฌ์ธํธ๋ฅผ ์น์ ๋
ธ์ถํ๋ ์ค์ ์ด๋ค.) http://localhost:8080/actuator๋ฅผ ํธ์ถํ๋ฉด
{
"_links": {
"self": {
"href": "http://localhost:8080/actuator",
"templated": false
},
"beans": {
"href": "http://localhost:8080/actuator/beans",
"templated": false
},
"caches": {
"href": "http://localhost:8080/actuator/caches",
"templated": false
},
"caches-cache": {
"href": "http://localhost:8080/actuator/caches/{cache}",
"templated": true
},
"health-path": {
"href": "http://localhost:8080/actuator/health/{*path}",
"templated": true
},
"health": {
"href": "http://localhost:8080/actuator/health",
"templated": false
},
"info": {
"href": "http://localhost:8080/actuator/info",
"templated": false
},
"conditions": {
"href": "http://localhost:8080/actuator/conditions",
"templated": false
},
"configprops-prefix": {
"href": "http://localhost:8080/actuator/configprops/{prefix}",
"templated": true
},
"configprops": {
"href": "http://localhost:8080/actuator/configprops",
"templated": false
},
"env": {
"href": "http://localhost:8080/actuator/env",
"templated": false
},
"env-toMatch": {
"href": "http://localhost:8080/actuator/env/{toMatch}",
"templated": true
},
"loggers": {
"href": "http://localhost:8080/actuator/loggers",
"templated": false
},
"loggers-name": {
"href": "http://localhost:8080/actuator/loggers/{name}",
"templated": true
},
"heapdump": {
"href": "http://localhost:8080/actuator/heapdump",
"templated": false
},
"threaddump": {
"href": "http://localhost:8080/actuator/threaddump",
"templated": false
},
"metrics": {
"href": "http://localhost:8080/actuator/metrics",
"templated": false
},
"metrics-requiredMetricName": {
"href": "http://localhost:8080/actuator/metrics/{requiredMetricName}",
"templated": true
},
"scheduledtasks": {
"href": "http://localhost:8080/actuator/scheduledtasks",
"templated": false
},
"mappings": {
"href": "http://localhost:8080/actuator/mappings",
"templated": false
}
}
}
์ด๋ ๊ฒ ๋ง์ ๊ธฐ๋ฅ๋ค์ ํ์ธ ๊ฐ๋ฅํ๋ค.
์๋ํฌ์ธํธ(EndPoint)
- ์ก์ถ์์ดํฐ๊ฐ ์ ๊ณตํ๋ ๊ธฐ๋ฅ ํ๋ํ๋๋ฅผ ์๋ํฌ์ธํธ(EndPoint)๋ผ๊ณ ํ๋ค.
- ๊ฐ๊ฐ์ ์๋ํฌ์ธํธ(EndPoint)๋
/actuator/{์๋ํฌ์ธํธ๋ช }์ผ๋ก ์ ๊ทผ์ด ๊ฐ๋ฅํ๋ค.
์์)http://localhost:8080/actuator/health
๋๋ถ๋ถ์ ์๋ํฌ์ธํธ(EndPoint)๋ ํ์ฑํ ๋์ด์์ง๋ง(
shutdown์ ์ธ) ์ค์ ์ผ๋ก ์ด๋ค ์๋ํฌ์ธํธ๋ฅผ ๋ ธ์ถํ ์ง ์ ํ์ด ๊ฐ๋ฅํ๋ค.
management:
endpoint:
shutdown:
enabled: true
management.endpoint.{์๋ํฌ์ธํธ๋ช
}.enabled=true ์ ์ฉshutdown์ ํ์ฑํ ์ํค๊ณ http://localhost:8080/actuator/shutdown POST ์์ฒญํ๋ฉด ์๋ฒ๊ฐ ์ข
๋ฃbeans: ์คํ๋ง ์ปจํ
์ด๋์ ๋ฑ๋ก๋ ์คํ๋ง ๋น์ ๋ณด์ฌ์ค๋ค.conditions: ๋น์ ๋ฑ๋กํ ๋ ํ๊ฐ ์กฐ๊ฑด๊ณผ ์ผ์นํ๊ฑฐ๋ ์ผ์นํ์ง ์๋ ์ด์ ๋ฅผ ๋ณด์ฌ์ค๋ค.configprops: @ConfigurationProperties ์ ๋ณด๋ฅผ ๋ณด์ฌ์ค๋ค.env: ์ ํ๋ฆฌ์ผ์ด์
์ ํ๊ฒฝ(Environment) ์ ๋ณด๋ฅผ ๋ณด์ฌ์ค๋ค.health: ์ ํ๋ฆฌ์ผ์ด์
์ ํฌ์ค ์ํ๋ฅผ ๋ณด์ฌ์ค๋ค.httpexchanges: HTTP ํธ์ถ ๋ฐ ์๋ต ์ ๋ณด๋ฅผ ์ ๊ณตํ๋ค. (HttpExchangeRepository๋ฅผ ๊ตฌํํ ๋น ํ์)info: ์ ํ๋ฆฌ์ผ์ด์
์ ๋ณด๋ฅผ ๋ณด์ฌ์ค๋ค.loggers: ๋ก๊ฑฐ ์ค์ ์ ํ์ธํ๊ณ ๋ณ๊ฒฝํ ์ ์๋ค.metrics: ์ ํ๋ฆฌ์ผ์ด์
์ ๋ฉํธ๋ฆญ ์ ๋ณด๋ฅผ ๋ณด์ฌ์ค๋ค.mappings: @RequestMapping ์ ๋ณด๋ฅผ ๋ณด์ฌ์ค๋ค.threaddump: ์ฐ๋ ๋ ๋คํ๋ฅผ ์คํํ์ฌ ๋ณด์ฌ์ค๋ค.shutdown: ์ ํ๋ฆฌ์ผ์ด์
์ ์ข
๋ฃํ๋ค. (๊ธฐ๋ณธ์ ์ผ๋ก ๋นํ์ฑํ๋์ด ์์)http://localhost:8080/actuator/health
์ ํ๋ฆฌ์ผ์ด์ ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ฉด ๋น ๋ฅด๊ฒ ๋ฌธ์ ํ์ ๊ฐ๋ฅ
์ข ๋ ์์ธํ๊ฒ ๋ณด๊ธฐ ์ํด์๋ ๋ค์๊ณผ ๊ฐ์ ์ค์ ํ์
management:
endpoint:
health:
show-details: always
๊ฐ๊ฐ์ ํญ๋ชฉ์ด ์์ฃผ ์์ธํ๊ฒ ๋ ธ์ถ๋๋๊ฒ์ด ๋ถ๋ด์ค๋ฌ์ฐ๋ฉด
management:
endpoint:
health:
show-components: always
show-details ์ ๊ฑฐ
ํฌ์ค ์ด์ ์ํ
{
"status": "DOWN",
"components": {
"db": {
"status": "DOWN"
},
"diskSpace": {
"status": "UP"
},
"ping": {
"status": "UP"
}
}
}
Down์ถ๊ฐ์ ์ผ๋ก db,mongo,redis,diskspace,ping ๊ฐ์ ์ ๋ง์ ํฌ์ค ๊ธฐ๋ฅ ์ ๊ณต
์ ํ๋ฆฌ์ผ์ด์ ๊ธฐ๋ณธ ์ ๋ณด๋ฅผ ๋ ธ์ถ
java : ์๋ฐ ๋ฐํ์ ์ ๋ณดos : OS ์ ๋ณดenv : Environment ์์ info.build : ๋น๋ ์ ๋ณด, META-INF/build-info.properties ํ์ผ์ด ํ์ํ๋ค.git : git ์ ๋ณด, git.properties ํ์ผ์ด ํ์ํ๋ค.์ฒ์ ์คํํ๋ฉด ์ ๋ณด๊ฐ ๋ณด์ด์ง ์๋๋ค. ๋ฐ๋ผ์ ์ค์ ํด์ค๋ค.
application.yml
management:
info:
java:
enabled: true
os:
enabled: true
management.info.<id>.enabeld ๊ฐ true์ง์ http://localhost:8080/actuator/info ์คํ
application.yml
management:
info:
env:
enabled: true
info:
app:
name: hello-actuator
company: yh
๋น๋ ์ ๋ณด ๋ ธ์ถ์ ์ํด์๋
META-INF/build-info.properties์ ์์ฑ
build.gradle - ๋น๋ ์ ๋ณด ์ถ๊ฐ
springBoot {
buildInfo()
}
{
"build": {
"artifact": "actuator",
"name": "actuator",
"time": "2023-01-01T00:00:00.000Z",
"version": "0.0.1-SNAPSHOT",
"group": "hello"
}
}
loggers ์๋ํฌ์ธํธ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ก๊น ๊ณผ ๊ด๋ จ๋ ์ ๋ณด๋ฅผ ํ์ธํ๊ณ , ๋ ์ค์๊ฐ์ผ๋ก ๋ณ๊ฒฝ ๊ฐ๋ฅ
package yuhan.actuatorstart;
@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:
yuhan.actuatorstart: debug
LogController ํด๋์ค๋ debug ๋ ๋ฒจ์ ์ํฅ์ ๋ฐ๋๋ค.
http://localhost:8080/actuator/loggers ์ ์คํํด๋ณด๋ฉด
{
"levels": [
"OFF",
"ERROR",
"WARN",
"INFO",
"DEBUG",
"TRACE"
],
"loggers": {
"ROOT": {
"configuredLevel": "INFO",
"effectiveLevel": "INFO"
},
"_org.springframework": {
"effectiveLevel": "INFO"
},
"yuhan": {
"effectiveLevel": "INFO"
},
"yuhan.ActuatorApplication": {
"effectiveLevel": "INFO"
},
"yuhan.actuatorstart": {
"configuredLevel": "DEBUG",
"effectiveLevel": "DEBUG"
},
" yuhan.actuatorstart.LogController": {
"effectiveLevel": "DEBUG"
}
}
}
์ด๋ ๊ฒ ๋ก๊ทธ ์ ๋ณด๋ค์ ํ์ธ ํ ์ ์๋ค.
๐ค
- ๋ก๊ทธ๋ฅผ ๋ณ๋๋ก ์ค์ ํ์ง ์์ผ๋ฉด ์คํ๋ง ๋ถํธ๋ ๊ธฐ๋ณธ์ผ๋ก
INFO๋ฅผ ์ฌ์ฉ
์ฐ๋ฆฌ๋yuhan.actuatorstart๋DEBUG
๋ก ์ค์ ํ๋ค.- ๊ทธ๋์ ํด๋น ๋ถ๋ถ์์
configuredLevel์ดDEBUG๋ก ์ค์ ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค. ๊ทธ๋ฆฌ๊ณ ๊ทธ ํ์๋DEBUG๋ ๋ฒจ์ด ์ ์ฉhttp://localhost:8080/actuator/loggers/yuhan.actuatorstart๋ก ๋ ์์ธํ ์กฐํ ๊ฐ๋ฅ
โผ๏ธ ์ค์๊ฐ ๋ก๊ทธ ๋ ๋ฒจ ๋ณ๊ฒฝ
์ด์ ์๋ฒ๋ ๋ณดํต ์์ฒญ๋ ๋ง๊ณ ๋ก๊ทธ๋ ๋๋ฌด ๋ง์ด ๋จ๊ธฐ ๋๋ฌธ์
DEBUG๋ก ์ถ๋ ฅํ๊ฒ ๋๋ฉด ์ฑ๋ฅ์ด๋ ๋์คํฌ์ ์ํฅ์ ์ค๋ค. ๊ทธ๋์ ์ด์ ์๋ฒ๋ ์ค์ํ๋ค๊ณ ํ๋จ๋๋INFO๋ก๊ทธ ๋ ๋ฒจ์ ์ฌ์ฉ
loggers ์๋ํฌ์ธํธ๋ฅผ ์ฌ์ฉํ๋ฉด ์ ํ๋ฆฌ์ผ์ด์
์ ๋ค์ ์์ํ์ง ์๊ณ , ์ค์๊ฐ์ผ๋ก ๋ก๊ทธ ๋ ๋ฒจ์ ๋ณ๊ฒฝ ๊ฐ๋ฅhttp://localhost:8080/actuator/loggers/yuhan.actuatorstar ์๋ค๊ฐ POST ๋ก ์ ์กํ๊ณ
{
"configuredLevel": "TRACE"
}
GET์ผ๋ก ์์ฒญํด์ ํ์ธํด๋ณด๋ฉด configuredLevel ์ด TRACE
http://localhost:8080/actuator/loggers/yuhan.actuatorstar
๋ก ๋ณ๊ฒฝ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
{
"configuredLevel": "TRACE",
"effectiveLevel": "TRACE"
}
์ก์ธ์์ดํฐ๊ฐ ์ ๊ณตํ๋ ๊ธฐ๋ฅ๋ค์ ์ฐ๋ฆฌ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ด๋ถ ์ ๋ณด๋ฅผ ๋๋ฌด ๋ง์ด ๋ ธ์ถํ๋ค. ์ก์ธ์์ดํฐ์ ์๋ํฌ์ธํธ๋ค์ ์ธ๋ถ ์ธํฐ๋ท์์ ์ ๊ทผ์ด ๋ถ๊ฐ๋ฅํ๊ฒ ๋ง๊ณ , ๋ด๋ถ์์๋ง ์ ๊ทผ ๊ฐ๋ฅํ ๋ด๋ถ๋ง์ ์ฌ์ฉํ๋ ๊ฒ ์ด ์์ ํ๋ค.
์ก์ธ์์ดํฐ ํฌํธ ์ค์
management.server.port=9292
์ฐธ๊ณ :