如何一次查询所有/actuator/metrics?

How to query all /actuator/metrics at once?

我正在使用 Spring 引导执行器作为内部 API,另一个 API 使用它来监视 Spring 引导应用程序。

问题是您必须查询每个 属性。 IE。 /actuator/metrics/jvm.memory.used

所以对于每个 GET 请求,我都必须发出多个请求(有多少指标就有多少)。

是否可以一次查询全部?

您没有开箱即用的 spring 提供的 api 引导,但如果您愿意,可以很容易地做到这一点。您需要使用框架在查询 /metrics api 时使用的端点 MetricsEndpoint

您需要在您的服务中 @Autowire 它,之后您可以使用它通过方法 listNames() 获取所有指标的名称。从提供的名称列表开始,您可以一次查询每个指标的详细信息。

Here 你有参考页。

如果你使用Prometheus it will expose new /actuator/prometheus endpoint which will list all the metrics at once. 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
...