Micrometer Rest API - spring

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

Related

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

Implement Spring Cloud Sleuth's TracingWebFillter in Spring WebFlux

I have a Spring Boot Reactive application using Functional Endpoints ( Kotlin) that uses Spring Cloud Sleuth. I want to customize the response headers to include the trace id. I looked at the manual and saw the section on using the TraceFilter : 1
I tried to do the same using a TraceWebFilter, but it doesn't expose the constructors. Is there a way to implement this customization when using the Reactive Web Framework.
I am using version 2.0.0.M5 for Spring Cloud Sleuth
Thanks in advance!
Please check out the latest master - we've migrated to Brave. You can write your WebFilter that will delegate to TraceWebFilter. Or you can just copy our TraceWebFilter and alter it in the way you need to.

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