integrating prometheus with play + spring application - spring

I am new to prometheus + spring. My application runs on play + spring. In order to use micrometer for monitoring, I added :
"org.springframework.boot" % "spring-boot-starter-actuator" % "2.2.4.RELEASE",
"io.micrometer" % "micrometer-registry-prometheus" % "1.2.0"
and management.endpoints.web.exposure.include="prometheus" in application.conf.
while trying to use spring boot actuator in spring application.
When I bring up my service locally and try to hit:
http://localhost:<service_port>/actuator/prometheus
it gives 404.
Can anyone give any lead on this?

The Prometheus endpoint is provided by the Spring Actuators. Those are endpoints that are automatically created. I don't believe there is any support for the Play Framework and those actuators.
You could use play prometheus filters to create the play equivalent endpoint. You'll want to ensure the CollectorRegistry is the same between the Play and Micrometer metrics.

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

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.

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.)

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

How does the Spring Boot Actuator work together with the Netflix Servo?

There are Spring Boot project that uses a Netflix Servo to collect metrics and send to Graphite.
I want to send metrics with the Spring Boot Actuator on Graphite, such as number request per every endpoint and time of response for every request, instead of creating custom metric.
But I ran into the problem. When I use the library only spring-boot-starter-actuator, then the desired parameters displays:
but when I apply library spring-cloud-starter-eureka, displayed only time of response from servo:
If someone faced with this problem, can you explain why it happens and how to solve it?
I use such version Spring Boot - 1.5.9.RELEASE and Spring Cloud - Edgware.SR1.
I will be glad to any response)
Link to test project: https://github.com/rmartseniuk/spring-metric

Resources