spring actuator는 기본적으로 io.micrometer.core.instrument을 지원한다.
io.prometheus.client하위 패키지의 사용하려면 실제 metric 설정시 연동이 되지 않는 것을 알수 있다.
스프링 부트에서는 해당 패키지를 사용할 수 있도록 지원한다.
management.endpoint.prometheus.enabled=true
resource에 해당 프로퍼티를 등록하면 autoConfiguration 에서
public class PrometheusScrapeEndpoint {
private final CollectorRegistry collectorRegistry;
public PrometheusScrapeEndpoint(CollectorRegistry collectorRegistry) {
this.collectorRegistry = collectorRegistry;
}
@ReadOperation(
produces = {"text/plain; version=0.0.4; charset=utf-8"}
)
public String scrape() {
try {
Writer writer = new StringWriter();
TextFormat.write004(writer, this.collectorRegistry.metricFamilySamples());
return writer.toString();
} catch (IOException var2) {
throw new RuntimeException("Writing metrics failed", var2);
}
}
}
해당 빈을 등록해준다.
이 빈을 통해 io.prometheus.client하위를 가져올 수 있다.
등록 된 빈을 통해 이제 이걸 가져와서
.register(collectorRegistry);
등록하게 되면 springboot actuator prometheus에서 정상 등록되는 것을 확인 할 수 있다.
'Programming Bookmark > Spring - Java' 카테고리의 다른 글
Missing required configuration "key.serializer" which has no default value - spring kafka 설정시 에러 (0) | 2020.04.09 |
---|---|
spring dispatcher render 직전 디버그 (0) | 2020.03.03 |
Spring boot Test MockMvc 사용하여 테스트하기 (0) | 2019.12.16 |
java local ip spring에서 쉽게 얻기 (0) | 2019.12.03 |
Spring security 래퍼런스와 Github 주소 공유 (0) | 2019.05.09 |