Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?

like image 600
yaseco Avatar asked Mar 12 '19 13:03

yaseco


2 Answers

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.

like image 85
NiVeR Avatar answered Sep 18 '22 22:09

NiVeR


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
...
like image 34
Karol Dowbecki Avatar answered Sep 19 '22 22:09

Karol Dowbecki