简体   繁体   中英

How to get metrics of outgoing http calls in Spring Boot?

My Spring Boot application calls other providers and I'd like to measure the time a response takes, but also would nice to measure other stuff. Is there a clean way of doing this maybe some library or package?

I'd need something which integrates seamlessly with existing apps, and I do not need to wrap the calls with System.getCurrentTimeMillis() etc.

You can use Spring Actuator,Prometheus Server/Client and Grafana Server to monitoring your application. There are 4 types of metrics available in Prometheus, you can use according to your requirements.

Prometheus Documentation

https://prometheus.io/

Grafana Documentation

http://docs.grafana.org/

Install Prometheus and Grafana servers.

You have to add the dependencies for Prometheus Client. Also Spring Actuator dependency need to add.

<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_spring_boot</artifactId>
    <version>0.0.26</version>
</dependency>
<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_hotspot</artifactId>
    <version>0.0.26</version>
</dependency>
<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_servlet</artifactId>
    <version>0.0.26</version>
</dependency>

In Configuration file you have to define bean for metrics.

@Bean
public ServletRegistrationBean servletRegistrationBean() {
    DefaultExports.initialize();
    return new ServletRegistrationBean(new MetricsServlet(), "/prometheus");
}

You can follow https://g00glen00b.be/monitoring-spring-prometheus-grafana/ for more detail.

Prometheus can monitor some metrics in the jvm.

But you may want to see the javamelody spring-boot-starter which will give metrics on the jvm and on the application and also on @Service Spring components and on RestTemplate when defined as bean to measure calls to some other providers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM