简体   繁体   English

如何在Spring Boot应用程序中将千分尺与jmx一起使用?

[英]How do i use micrometer with jmx in spring boot app?

I am fairly new to micrometer metric and having some issues with basic setup in my spring boot application. 我对千分尺相当陌生,并且在Spring Boot应用程序中对基本设置有一些问题。

Code: 码:

MeterRegistry registry = new SimpleMeterRegistry();
Timer timer = registry.timer("app.event", "type","ping");
timer.record(System.currentTimeMillis() - date.getTime(),TimeUnit.MILLISECONDS);

I tried looking for a bean with the name of ping in jmx using jconsole, but I am not able to find it. 我尝试使用jconsole在jmx中查找名称为ping的bean,但找不到。 I believe there is something basic I am missing here, but not sure of the real cause. 我相信这里缺少一些基本的东西,但是不确定真正的原因。 I tried following the micrometer documentation as well, but it seems to explain different functions of micrometer without much sample examples. 我也尝试遵循千分尺文档,但是似乎没有太多示例示例就可以解释千分尺的不同功能。 I would really appreciate any help on this. 我真的很感谢任何帮助。

Perhaps you haven't included the jmx exporter? 也许您没有包括jmx导出器?

From the documentation : 文档中

<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-jmx</artifactId>
  <version>${micrometer.version}</version>
</dependency>

You need to use the auto-configured MeterRegistry . 您需要使用自动配置的MeterRegistry So you should inject MeterRegistry into any component you want to create meter(s) rather than creating your own one there. 因此,您应该将MeterRegistry注入要创建仪表的任何组件中,而不要在此处创建自己的仪表。 Or you can create your own one as a bean if necessary. 或者,您可以根据需要将自己的bean创建为bean。

I created a sample demonstrating how to do it . 我创建了一个示例,演示了如何执行此操作 Note that it's on the so-51940816 branch, not the master . 请注意,它位于so-51940816分支上,而不是master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM