본문으로 바로가기

 

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에서 정상 등록되는 것을 확인 할 수 있다.