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

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.

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.

Spring Boot metrics for Prometheus using Micrometer or Spring Metrics

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.

Metrics of redis and solr in spring boot

I have services built in spring boot 2.0.2. I`m using redis and solrj.
Now if i want to get metrics of redis and solr. It don`t show in
http://localhost:8080/actuator/metrics
Is there any way e.g making custom endpoint to get redis and solr metrics?
Any help would be appreciated..
Yes, it should be possible.
Spring boot 2's default metrics framework is Micrometer
When this framework is integrated into spring boot application (via starter as usual), any metrics reported to micrometer will immediately appear in spring boot actuator.
So the question is whether the redis/solrj integration expose Metrics or not.
If they are not, you'll have to understand what exactly you want to measure and plug in the integration.
Here is the example:
import io.micrometer.core.annotation;
#Timed("my-redis-calls")
public void doSomethingInMyCode() {
//call redis here
}
Of course, there is also a programmatic interface, using annotations in not mandatory
The code shown in Mark Bramnik's answer doesn't specifically give you timing for Redis client calls, it gives you timing for doSomethingInMyCode method, which can be different.
Micrometer support seems to be available in the Lettuce 6.1 release.
MeterRegistry meterRegistry = …;
MicrometerOptions options = MicrometerOptions.create();
ClientResources resources = ClientResources.builder().commandLatencyRecorder(new MicrometerCommandLatencyRecorder(meterRegistry, options)).build();
RedisClient client = RedisClient.create(resources);
https://lettuce.io/core/release/reference/index.html#command.latency.metrics.micrometer

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

Resources