Spring Boot metrics for Prometheus using Micrometer or Spring Metrics - spring-boot

I am building a Spring Boot application and planning to use the /actuator/prometheus for data scraping by Prometheus. It seems that the main way is to use Micrometer. However, I see that there is another library, which is Spring Metrics.
What is the go to way to have custom metrics that will be scraped by prometheus?

Early in its development, Micrometer was named Spring Metrics. If you got to the project's GitHub repository (https://github.com/spring-projects/spring-metrics) you will see that it redirects to https://github.com/micrometer-metrics/micrometer as the repository was moving into the micrometer-metrics organization and renamed.
In short, you should use Micrometer.

Related

Micrometer Rest API

I have a non boot spring application with micrometer integrated. Right now we are pushing these metrics to the logging file using LoggingRegistry.
We want to enhance this project to expose these metrics in the Rest API(we cannot use actuator as turning ON auto configuration is causing issues in our non boot application).Is there any way to expose these metrics which are automatically provided by the micrometer in the Rest API?
Any example will be appreciated?
You can add PrometheusMeterRegistry, it is for this use case, see the docs: https://micrometer.io/docs/registry/prometheus

How to get spring boot cloud/actuator to support prometheus Exemplars?

The Exemplars support essentially adds the trace-id to metrics that are being scraped. I found a tutorial on how would it work with GoLang[1] but cannot figure out how to do this with spring boot libraries/functionalities. I know that Prometheus Java Client supports it as described at [2] but not sure how to get it to work with Springboot.
https://vbehar.medium.com/using-prometheus-exemplars-to-jump-from-metrics-to-traces-in-grafana-249e721d4192
https://github.com/prometheus/client_java/pull/615
Update: Exemplars are supported by Micrometer and Spring Cloud Sleuth.
I'm not 100% sure I get your question right: I'm assuming you are talking about the /actuator/prometheus endpoint.
The support for metrics in Spring is provided by Micrometer that also supports Prometheus and Spring Boot "just" sets up an actuator endpoint for it.
So the real question is: does Micrometer support exemplars? Right now it does not and we haven't had anyone asking for it so far (this issue is a little bit connected). So if you want this feature, please open an issue(Enhancement request) on GitHub.
Update: I opened an issue for this: https://github.com/micrometer-metrics/micrometer/issues/2672, please feel free to +1 or chime-in.
Adding exemplars support in Micrometer is not the end of the story, we need to add support for Spring Cloud Sleuth too and solve a few other potential issues.
Until this is implemented, I guess your best bet is using the prometheus client.

adding end points in prometheus integration

How to add/integrate rest api end points in prometheus. For eg in splunk we are monitoring micro services transactions and logs.
Lets say below spring boot:-
/abc/v1/something
/abce/v1/something2
In one line :-how can we add above micro services end points to prometheus for motioning
When using Spring Boot 2, you can easily expose your application metrics for Prometheus. See here. You'd add spring-boot-starter-actuator and the Prometheus support with micrometer-registry-prometheus to your dependencies.
This will expose the metrics under /actuator/prometheus in the Prometheus exposition format to be scraped by your Prometheus instance.
Assumung you are using Spring WebMvc, then you'll get out-of-the-box metrics for your HTTP endpoints. (Jersey support is also provided with an extra module/dependency.)

Spring Actuator - metrics aggregation from docker containers

I have a Spring Boot REST service application. This application uses Spring Actuator to display metrics and health information. How can I aggregate this information from two or more containers running the same application?
You need to export the metrics to a central system.
Spring Boot provides a couple of implementations of a marker interface
called Exporter which can be used to copy metric readings from the
in-memory buffers to a place where they can be analyzed and displayed.
More specifically personally I like exporting metrics to statsD
To export metrics to Statsd, make sure first that you have added
com.timgroup:java-statsd-client as a dependency of your project
(Spring Boot provides a dependency management for it). Then add a
spring.metrics.export.statsd.host value to your application.properties
file. Connections will be opened to port 8125 unless a
spring.metrics.export.statsd.port override is provided. You can use
spring.metrics.export.statsd.prefix if you want a custom prefix.
The information above is all from the Spring Boot documentation on metrics: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html

Is there a way of collecting metrics from Spring XD to Graphite?

While reading the documentation for Spring XD I seen that it has a model for collecting metrics.
But when I looked into the code, I have seen that this is a custom implementation for Spring XD. None the less in the project dependencies there is codahale's metrics.
No it would be pretty useful to be able to add reporters (like the Graphite reporter which is also in the libs of Spring XD ) to the collected metrics.
But I wasn't able to find anything in the documentation on wether this is possible or how this should be done.
Does somebody have a hint how to do it, or if it is possible at the moment?
Thanks,
Christoph
Spring XD runtime components (XD admin, container and single-node JVMs) use Spring Boot internally. Spring Boot supports collection of codahale's metrics:
http://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html#production-ready-code-hale-metrics
Since the codahale metrics jars are available in $XD_HOME/lib, all these metrics are already exposed at the Spring XD management endpoint.
By default management endpoint is enabled on XD admin. You can access them:
http://localhost:9393/management/metrics
For the container JVM, you can set the management port explicitly by setting XD_MGMT_PORT and access from '/management/metrics' endpoint.
You can refer to monitoring-management section in Spring XD wiki for more detail.

Resources