Search code examples
spring-bootspring-boot-actuatorstatsd

Spring-boot metrics statsd won't start


I have built a spring-boot service app, and it's running well. Now I wanted to add monitoring feature to my service. currently I have statsd-logger running on my local. So I started to implement metrics following this doc: Spring-boot metrics export statsd, but it fails to start.

Here's what I added:

pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-core</artifactId>
    <optional>true</optional>
</dependency>
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-spring-legacy</artifactId>
    <version>1.0.6</version>
</dependency>
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-statsd</artifactId>
    <version>${micrometer.version}</version>
</dependency>

application.properties

management.metrics.export.statsd.enabled=true
management.metrics.export.statsd.host=localhost
management.metrics.export.statsd.port=8125
management.metrics.export.statsd.flavor=etsy

Then I found this error when started the service:

...
...
...
10:19:57.088 [main] INFO  org.eclipse.jetty.server.Server:411 - Started @8790ms 
10:19:58.517 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerAdapter:574 - Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@564fabc8: startup date [Mon Sep 24 10:19:50 WIB 2018]; root of context hierarchy 
10:19:58.697 [main] WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext:558 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'metricsAsyncRestTemplateInitializer' defined in class path resource [io/micrometer/spring/autoconfigure/web/client/RestTemplateMetricsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'metricsAsyncRestTemplateInitializer' parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'io.micrometer.spring.web.client.MetricsRestTemplateCustomizer' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} 
10:19:58.701 [main] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean:597 - Closing JPA EntityManagerFactory for persistence unit 'default' 
10:19:58.703 [main] INFO  com.jolbox.bonecp.BoneCP:159 - Shutting down connection pool... 
10:19:58.709 [main] INFO  com.jolbox.bonecp.BoneCP:188 - Connection pool has been shutdown. 
10:19:58.757 [main] INFO  org.eclipse.jetty.server.session:167 - node0 Stopped scavenging 
10:19:58.761 [main] INFO  o.e.j.server.handler.ContextHandler:1020 - Stopped o.s.b.w.e.j.JettyEmbeddedWebAppContext@1a01ffff{application,/user-service,[file:///private/var/folders/83/kwg9txkx3cjgcw79_rz4dqr40000gn/T/jetty-docbase.3480800862360239089.8080/, jar:file:/Users/company/.m2/repository/io/springfox/springfox-swagger-ui/2.4.0/springfox-swagger-ui-2.4.0.jar!/META-INF/resources],UNAVAILABLE} 
10:19:58.797 [main] INFO  o.s.b.a.l.ConditionEvaluationReportLoggingListener:101 - 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 
10:19:58.978 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter:42 - 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of method metricsAsyncRestTemplateInitializer in io.micrometer.spring.autoconfigure.web.client.RestTemplateMetricsAutoConfiguration required a bean of type 'io.micrometer.spring.web.client.MetricsRestTemplateCustomizer' that could not be found.


Action:

Consider defining a bean of type 'io.micrometer.spring.web.client.MetricsRestTemplateCustomizer' in your configuration.


Process finished with exit code 1

while statsd-logger actually receiving the message from my service:

⇒  statsd-logger
Server listening on 0.0.0.0:8125
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: jvm.gc.pause 10|ms|#action:end of minor GC,cause:Allocation Failure
StatsD Metric: jvm.gc.memory.promoted 8192|c|#statistic:count
StatsD Metric: jvm.gc.memory.allocated 169345024|c|#statistic:count
StatsD Metric: logback.events 1|c|#statistic:count,level:warn
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: jvm.gc.pause 21|ms|#action:end of minor GC,cause:Allocation Failure
StatsD Metric: jvm.gc.memory.promoted 4862520|c|#statistic:count
StatsD Metric: jvm.gc.memory.allocated 260046848|c|#statistic:count
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: jvm.gc.pause 15|ms|#action:end of minor GC,cause:Metadata GC Threshold
StatsD Metric: jvm.gc.memory.promoted 4653536|c|#statistic:count
StatsD Metric: jvm.gc.memory.allocated 255163952|c|#statistic:count
StatsD Metric: jvm.gc.pause 122|ms|#action:end of major GC,cause:Metadata GC Threshold
StatsD Metric: jvm.gc.memory.promoted 7943104|c|#statistic:count
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:warn
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: logback.events 1|c|#statistic:count,level:info
StatsD Metric: jvm.gc.max.data.size 2863661056|g|#statistic:value
StatsD Metric: jvm.gc.live.data.size 39307296|g|#statistic:value
StatsD Metric: jvm.buffer.count 3|g|#statistic:value,id:direct
StatsD Metric: jvm.buffer.memory.used 11342|g|#statistic:value,id:direct
StatsD Metric: jvm.buffer.total.capacity 11341|g|#statistic:value,id:direct
StatsD Metric: jvm.buffer.count 0|g|#statistic:value,id:mapped
StatsD Metric: jvm.buffer.memory.used 0|g|#statistic:value,id:mapped
StatsD Metric: jvm.buffer.total.capacity 0|g|#statistic:value,id:mapped
StatsD Metric: jvm.memory.used 10629696|g|#statistic:value,area:nonheap,id:Code Cache
StatsD Metric: jvm.memory.committed 10813440|g|#statistic:value,area:nonheap,id:Code Cache
StatsD Metric: jvm.memory.max 251658240|g|#statistic:value,area:nonheap,id:Code Cache
StatsD Metric: jvm.memory.used 57925344|g|#statistic:value,area:nonheap,id:Metaspace
StatsD Metric: jvm.memory.committed 60841984|g|#statistic:value,area:nonheap,id:Metaspace
StatsD Metric: jvm.memory.max -1|g|#statistic:value,area:nonheap,id:Metaspace
StatsD Metric: jvm.memory.used 8082776|g|#statistic:value,area:nonheap,id:Compressed Class Space
StatsD Metric: jvm.memory.committed 8675328|g|#statistic:value,area:nonheap,id:Compressed Class Space
StatsD Metric: jvm.memory.max 1073741824|g|#statistic:value,area:nonheap,id:Compressed Class Space
StatsD Metric: jvm.memory.used 32060744|g|#statistic:value,area:heap,id:PS Eden Space
StatsD Metric: jvm.memory.committed 336592896|g|#statistic:value,area:heap,id:PS Eden Space
StatsD Metric: jvm.memory.max 1387790336|g|#statistic:value,area:heap,id:PS Eden Space
StatsD Metric: jvm.memory.used 0|g|#statistic:value,area:heap,id:PS Survivor Space
StatsD Metric: jvm.memory.committed 20971520|g|#statistic:value,area:heap,id:PS Survivor Space
StatsD Metric: jvm.memory.max 20971520|g|#statistic:value,area:heap,id:PS Survivor Space
StatsD Metric: jvm.memory.used 39307296|g|#statistic:value,area:heap,id:PS Old Gen
StatsD Metric: jvm.memory.committed 224919552|g|#statistic:value,area:heap,id:PS Old Gen
StatsD Metric: jvm.memory.max 2863661056|g|#statistic:value,area:heap,id:PS Old Gen
StatsD Metric: jvm.threads.peak 39|g|#statistic:value
StatsD Metric: jvm.threads.daemon 23|g|#statistic:value
StatsD Metric: jvm.threads.live 33|g|#statistic:value
StatsD Metric: jvm.classes.loaded 11729|g|#statistic:value
StatsD Metric: jvm.classes.unloaded 0|c|#statistic:count
StatsD Metric: process.uptime 9105|g|#statistic:value
StatsD Metric: process.start.time 1537762685461|g|#statistic:value
StatsD Metric: system.cpu.count 8|g|#statistic:value
StatsD Metric: system.load.average.1m 3.060059|g|#statistic:value
StatsD Metric: system.cpu.usage 0|g|#statistic:value
StatsD Metric: process.cpu.usage 0|g|#statistic:value
StatsD Metric: process.files.open 184|g|#statistic:value
StatsD Metric: process.files.max 10240|g|#statistic:value
StatsD Metric: statsd.queue.size 0|g|#statistic:value
StatsD Metric: statsd.queue.capacity 2147483647|g|#statistic:value

Does anyone experience the same problem? What might I have missed?


Solution

  • I think the error of the missing customizer bean has nothing to do with the statsd integration at all, make sure that what other customization you have in place.

    As a side note: Assuming you're on Spring Boot 2, you won't need

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-spring-legacy</artifactId>
        <version>1.0.6</version>
    </dependency>
    

    And please check if you're problems aren't caused by marking micrometer-core as optional. Remove that dependency as well, it's brought in by actuator already in the right way:

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-core</artifactId>
        <optional>true</optional>
    </dependency>