I'm using the Spring boot actuator as an internal API that is used by another API to monitor the Spring Boot application.
The problem is that you have to query each and every property. i.e.
/actuator/metrics/jvm.memory.used
So for every GET request, I have to make multiple requests (as many as there are metrics).
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. You need to use the endpoint MetricsEndpoint
which is used by the framework when querying the /metrics
apis.
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()
. Starting from the list of provided names you can query the detail for each metric at a time.
Here you have the reference page.
If you use 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
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With