启用弹簧千分尺端点的指标
我将Java Spring项目从Java 8迁移到Java 11。因此,我需要用千分尺替换Dropwizard指标。达到某些端点时,Dropwizard指标正在记录状态和响应。 例如:端点localhost:8080/my_service/v1/api/some/endpoint
- >>并记录了指标 Metrics.prefix.counter.status.200.v1.api.some.endpoint
Metrics.prefix.gauge.response.v1.api.some.endpoint
有没有办法在微米中使用相同的方法?我知道有@counted
注释,但由于某种原因,它行不通。 (我将其放在端点方法上)。
我的适当文件文件(仅与指标相关的值):
management.metrics.export.statsd.enabled=true
management.metrics.export.statsd.host=****
management.metrics.export.statsd.port=8125
management.metrics.export.statsd.flavor=etsy
management.metrics.export.statsd.prefix=metrics.prefix
management.metrics.export.statsd.polling-frequency=10s
management.metrics.web.server.auto-time-requests=:true
I'm migrating Java Spring project from java 8 to java 11. So I need to replace dropwizard metrics with micrometer. Dropwizard metrics were recording statuses and responses when hitting certain endpoint.
E.g: endpoint localhost:8080/my_service/v1/api/some/endpoint
-->> and metrics recordedmetrics.prefix.counter.status.200.v1.api.some.endpoint
metrics.prefix.gauge.response.v1.api.some.endpoint
Is there a way to anable the same in Micrometer? I'm aware there is @Counted
annotation, but for some reason it doesn't work. (I'm putting it on endpoint method).
My propertries file (metrics-related values only):
management.metrics.export.statsd.enabled=true
management.metrics.export.statsd.host=****
management.metrics.export.statsd.port=8125
management.metrics.export.statsd.flavor=etsy
management.metrics.export.statsd.prefix=metrics.prefix
management.metrics.export.statsd.polling-frequency=10s
management.metrics.web.server.auto-time-requests=:true
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用Spring创建端点(MVC或WebFlux),则无需执行任何操作即可查看这些指标。
您应该看到
http.server.requests
,其中包含上面名称(URI,状态)等的所有详细信息(作为标签)。为了制作
@Counted
(和/或@timed
工作),您需要创建countedaspect
(和/或timeDaspect
/code>)@bean
,但是正如我所说,如果您仅在受控中使用它,则不需要它们。You don't need to do anything to see those metrics if you are using Spring to create your endpoint (mvc or webflux).
You should see
http.server.requests
which has all the details (as tags) that you have in the name above (uri, status) and more.In order to make
@Counted
(and/or@Timed
work) you need to create aCountedAspect
(and/orTimedAspect
)@Bean
but as I said, if you only use it on the controlled, they are not needed.