[英]Custom metrics using Micrometer is not available in Prometheus endpoint
I'm using Micrometer in Java Spring Boot 1.5 application to scrape custom metrics for Prometheus. 我在Java Spring Boot 1.5应用程序中使用Micrometer来为Prometheus刮取自定义指标。
I'm using "guageCollectionSize" method to count the number of entries in a HashMap. 我正在使用“ guageCollectionSize”方法来计算HashMap中的条目数。 When I print the guage value, I'm getting the correct output as expected.
当我打印测量值时,我得到了预期的正确输出。 But the problem is that I'm not able to view the custom metric in /prometheus endpoint.
但是问题是我无法在/ prometheus端点中查看自定义指标。
Please find the code below 请在下面找到代码
private Map<String, String> _strings;
private MeterRegistry registry;
_strings = new ConcurrentHashMap<String, String>();
_strings.put("Test","Test");
_strings.put("Test2","Test");
registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
registry.gaugeCollectionSize("strings_count", Tags.empty(),_strings.keySet());
System.out.println(registry.get("strings_count").gauge().value());
Can someone please help me to fix this issue? 有人可以帮我解决此问题吗?
As I told you on the GitHub issue which you created on the project repository, you're creating your own PrometheusMeterRegistry
but you should use the auto-configured one. 正如我在项目存储库上创建的GitHub问题上告诉您的那样 ,您正在创建自己的
PrometheusMeterRegistry
但应使用自动配置的PrometheusMeterRegistry
。
I created a sample that uses the auto-configured one and added a test for it. 我创建了一个使用自动配置的示例 ,并为此添加了一个测试 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.