How to remove default Metrics data provided by Spring Actuator - spring

I am trying to get Production metrics for my application. I am using Actuator on top of Spring Boot. Actuator exposes an endpoint for that "/metrics". I have Autowired CounterService class to get my own metrics data. I will be displaying the metrics data in one of our Application Management UI. The problem here is that I don't want all the default metrics data, as the Response JSON given back by the /metrics endpoint is kind off heavy for me to parse and most of the default metrics data are useless for me and give it to the UI. I have gone through the Spring Docs, I didn't get any help.
Appreciate your help on this!

Oh So I found a way to deal with the scenario. Actually Spring This GitHub Link pretty much solves my problem. Actuator Supports Reqex support to query for the data you need. So my url looks like this now : http://{{hostname}}/metrics/counter.*.count instead of this http://{{hostname}}/metrics/. Hope this helps.

Have you tried wrapping the response class from metrics, with a Custom class?

Related

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.

Custom Spring Actuator Endpoint which has subsystem and can be added dynamically

I'm looking for a way to implement custom endpoints for a reactive application using Spring Boot 2.2.
The endpoints have some subsystems and perform specific resource operations on the subsystems. The URL paths look like:
/actuator/system1/subsystem_a
/actuator/system1/subsystem_b
/actuator/system2/subsystem_c
Furthermore, system1 and system2 are not both always deployed, so I'd like to add dynamically the endpoints of the deployed system only.
I know I can use ReactiveHealthContributorRegistry to add custom health check endpoints dynamically. Is there a similar way for a fully custom endpoint?
Thanks in advance.
It seems there is no way to construct such complex endpoints like what I asked in Spring Boot Actuator.
I finally decided to use RouterFunction and HandlerFunction referring to the following websites.
https://www.baeldung.com/spring-5-functional-web
https://spring.io/blog/2016/09/22/new-in-spring-5-functional-web-framework

Spring boot metrics for rest api with PathVariables

In my spring boot project I would like to keep count of how many times the rest api endpoint responded with status 200. The spring boot actuator metrics endpoint came close to solving this issue for me out of the box.
However, the /metrics endpoint names provided the aggregate of responses by the endpoint method rather than each of the dynamic endpoints created through #PathVariable.
For example:
while I can get http://localhost:8084/myproject/actuator/metrics/http.server.requests?tag=status:200,uri:/api/users/{id}/books
I would like to do something like
http://localhost:8084/myproject/actuator/metrics/http.server.requests?tag=status:200,uri:/api/users/1/books
and
http://localhost:8084/myproject/actuator/metrics/http.server.requests?tag=status:200,uri:/api/users/2/books
and so on.
Is there an easy way to do this?
You can roll your own WebMvcTagsProvider. That's the place where you can hook into the tag generation. Have a look at DefaultWebMvcTagsProvider to get insight on how it is done for the default behaviour.
A note: The default tagging is done on purpose the way it is to hinder metrics explosion, because every metric name + tag combination is a new metric. So be aware of that.

Spring actuator viewer

Are there any applications that wrap spring actuator metrics in some nice appealing form, instead of JSON? I would like to have nice view of all existing beans, to learn how spring actualy works.
Take a look at spring-boot-admin:
https://github.com/codecentric/spring-boot-admin
According to spring documentation, actuator can provide data to dropwizard metrics regestry. Dropwizard in its turn supports streaming metrics to Ganglia and Graphite backends.
Graphite can draw some charts but those look pretty plain. You can integrate it with graphana dashboard to achieve impressive visualisation.

Spring XD REST Service

I would like to have a REST service to expose the data read and processed from Spring XD. Similar to the one in the Analytics Server.
For example I would like my own functions which can be exposed similar to Counters and be able to access the data from a web browser.
Is there any tutorial? I have searched and found that Spring Boot is the one but I am looking for help on how I integrate it with Spring XD.
Would be very helpful if someone can point me to the instructions on how I can achieve this.
You can use trigger as a source with http-client as a processor processor to access any web browsers info regardless if it is a web service URL or not.
Moha.

Resources