![](/img/trans.png)
[英]Spring Boot Actuator: How to get metrics uptime inside a custom HealthIndicator?
[英]How to get metrics of outgoing http calls in Spring Boot?
我的Spring Boot應用程序調用了其他提供程序,我希望測量響應所花費的時間,但是也很適合測量其他內容。 有沒有一種干凈的方法可以做到這一點,也許是一些庫或包?
我需要與現有應用程序無縫集成的東西,並且不需要使用System.getCurrentTimeMillis()等包裝調用。
您可以使用Spring Actuator,Prometheus Server / Client和Grafana Server來監視您的應用程序。 Prometheus提供4種類型的指標,您可以根據需要使用。
普羅米修斯文獻
Grafana文檔
安裝Prometheus和Grafana服務器。
您必須為Prometheus Client添加依賴項。 還需要添加Spring Actuator依賴項。
<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>
在配置文件中,您必須定義指標的bean。
@Bean
public ServletRegistrationBean servletRegistrationBean() {
DefaultExports.initialize();
return new ServletRegistrationBean(new MetricsServlet(), "/prometheus");
}
您可以關注https://g00glen00b.be/monitoring-spring-prometheus-grafana/了解更多信息。
Prometheus可以監視jvm中的某些指標。
但是您可能希望看到javamelody spring-boot-starter ,它將在jvm和應用程序上以及@Service Spring組件和RestTemplate上提供度量(當定義為bean來度量對其他提供程序的調用時)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.