I'm using Micrometer in Java Spring Boot 1.5 application to scrape custom metrics for Prometheus.
I'm using "guageCollectionSize" method to count the number of entries in a HashMap used in a service. 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.
Please find the code below
private Map
private MeterRegistry registry;
_strings = new ConcurrentHashMap
_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()); //Prints 2
Can someone tell me what is wrong with this implementation or is there are alternative implementation to do the same?
@renjithseban Looking at your description, you're creating your own PrometheusMeterRegistry but you should use the auto-configured one.
I created a sample that uses the auto-configured one: https://github.com/izeye/sample-micrometer-spring-boot/blob/gh-738/src/main/java/com/izeye/sample/web/SampleController.java#L26-L37
and added a test for it: https://github.com/izeye/sample-micrometer-spring-boot/blob/gh-738/src/test/java/com/izeye/sample/SpringBootActuatorMetricsPrometheusTests.java
Thanks izeye. It worked
Most helpful comment
@renjithseban Looking at your description, you're creating your own
PrometheusMeterRegistrybut you should use the auto-configured one.I created a sample that uses the auto-configured one: https://github.com/izeye/sample-micrometer-spring-boot/blob/gh-738/src/main/java/com/izeye/sample/web/SampleController.java#L26-L37
and added a test for it: https://github.com/izeye/sample-micrometer-spring-boot/blob/gh-738/src/test/java/com/izeye/sample/SpringBootActuatorMetricsPrometheusTests.java