Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get Prometheus to work with Spring Boot 2.0.3

I am using Spring Boot 2.0.3.RELEASE with following dependencies:

spring-boot-starter-actuator:2.0.3.RELEASE
micrometer-core:1.0.6
micrometer-registry-prometheus:1.0.6

But when I invoke Prometheus all I keep getting is

{
    "timestamp": 1532426317772,
    "status": 406,
    "error": "Not Acceptable",
    "message": "Could not find acceptable representation",
    "path": "/actuator/prometheus"
}

*and/or from browser*
There was an unexpected error (type=Not Acceptable, status=406).
Could not find acceptable representation

I have also tried previous Prometheus releases of the range 1.0.X with Spring Boot 2 but with no luck. Could someone please suggest some insights? Many thanks.

like image 965
TKM Avatar asked Dec 23 '22 05:12

TKM


2 Answers

We recently had the same problem. While debugging Spring Boot I discovered that we had no HttpMessageConverter registered that could handle the "text/plain" MediaType, only "application/json". Because the Prometheus endpoint returns the "text/plain" MediaType we added some configuration as a temporary workaround. We added a StringHttpMessageConverter linked to the specific MediaType.

@Configuration
public class ApplicationConfiguration implements WebMvcConfigurer {

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        StringHttpMessageConverter converter = new StringHttpMessageConverter();
        converter.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_PLAIN));
            converters.add(converter);
    }
}

Hope this helps you

like image 56
Kenny Avatar answered Feb 20 '23 13:02

Kenny


May It's 406 status code which also can solved by client side with specified accept header. like this: curl -v -H "Accept: text/plain" url

like image 23
Se ven Avatar answered Feb 20 '23 13:02

Se ven