[英]How to query all /actuator/metrics at once?
I'm using the Spring boot actuator as an internal API that is used by another API to monitor the Spring Boot application. 我使用Spring启动执行器作为内部API,另一个API使用它来监视Spring Boot应用程序。
The problem is that you have to query each and every property. 问题是你必须查询每个属性。 ie /actuator/metrics/jvm.memory.used
即/actuator/metrics/jvm.memory.used
So for every GET request, I have to make multiple requests (as many as there are metrics). 因此,对于每个GET请求,我必须发出多个请求(与指标一样多)。
Is it possible to query all of them at once? 是否可以一次查询所有这些?
You don't have an api given by spring boot out of the box, but you can make it very easly if you want to. 你没有开箱即用的弹簧开关api,但如果你愿意,你可以很容易地做到。 You need to use the endpoint MetricsEndpoint
which is used by the framework when querying the /metrics
apis. 您需要使用在查询/metrics
apis时框架使用的端点MetricsEndpoint
。
You need to @Autowire
it in your service and afterwards you can use it get the names of all metrics by using the method listNames()
. 您需要在服务中@Autowire
,然后您可以使用方法listNames()
获取所有指标的名称。 Starting from the list of provided names you can query the detail for each metric at a time. 从提供的名称列表开始,您可以一次查询每个指标的详细信息。
If you use Prometheus it will expose new /actuator/prometheus
endpoint which will list all the metrics at once. 如果您使用Prometheus ,它将显示新的/actuator/prometheus
端点,它将立即列出所有指标。 See this tutorial for examples : 有关示例,请参阅本教程 :
# HELP jvm_buffer_memory_used_bytes An estimate of the memory that the Java virtual machine is using for this buffer pool
# TYPE jvm_buffer_memory_used_bytes gauge
jvm_buffer_memory_used_bytes{id="direct",} 81920.0
jvm_buffer_memory_used_bytes{id="mapped",} 0.0
# HELP jvm_threads_live The current number of live threads including both daemon and non-daemon threads
# TYPE jvm_threads_live gauge
jvm_threads_live 23.0
# HELP tomcat_global_received_bytes_total
# TYPE tomcat_global_received_bytes_total counter
tomcat_global_received_bytes_total{name="http-nio-8080",} 0.0
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.