春季启动指标statsd无法启动

时间:2018-09-24 04:21:06

标签: spring-boot spring-boot-actuator statsd

我已经构建了一个Spring Boot服务应用程序,并且运行良好。 现在,我想向我的服务添加监视功能。目前,我在本地运行statsd-logger。 因此,我开始按照此文档实施指标: Spring-boot metrics export statsd,但无法启动。

这是我添加的内容:

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

然后我在启动服务时发现此错误:

...
...
...
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

而statsd-logger实际上从我的服务接收消息:

⇒  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

有人遇到同样的问题吗?我可能错过了什么?

1 个答案:

答案 0 :(得分:2)

我认为缺少定制程序bean的错误与statsd集成完全无关,请确保您具有其他定制功能。

请注意:假设您使用的是Spring Boot 2,则不需要

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

请检查您的问题是否不是由将micrometer-core标记为可选引起的。还要删除该依赖关系,它已经由执行器以正确的方式引入:

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