Prometheus(prometheus

prometheus 端点以 Prometheus 服务器所需的格式提供 Spring Boot 应用的指标数据。

获取全部指标

要获取所有指标,请像以下基于 curl 的示例一样,向 /actuator/prometheus 发起 GET 请求:

$ curl 'http://localhost:8080/actuator/prometheus' -i -X GET

响应结果类似如下:

HTTP/1.1 200 OK
Content-Type: text/plain;version=0.0.4;charset=utf-8
Content-Length: 3087

# HELP jvm_buffer_count_buffers An estimate of the number of buffers in the pool
# TYPE jvm_buffer_count_buffers gauge
jvm_buffer_count_buffers{id="direct"} 4.0
jvm_buffer_count_buffers{id="mapped"} 0.0
jvm_buffer_count_buffers{id="mapped - 'non-volatile memory'"} 0.0
# 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"} 61440.0
jvm_buffer_memory_used_bytes{id="mapped"} 0.0
jvm_buffer_memory_used_bytes{id="mapped - 'non-volatile memory'"} 0.0
# HELP jvm_buffer_total_capacity_bytes An estimate of the total capacity of the buffers in this pool
# TYPE jvm_buffer_total_capacity_bytes gauge
jvm_buffer_total_capacity_bytes{id="direct"} 61440.0
jvm_buffer_total_capacity_bytes{id="mapped"} 0.0
jvm_buffer_total_capacity_bytes{id="mapped - 'non-volatile memory'"} 0.0
# HELP jvm_memory_committed_bytes The amount of memory in bytes that is committed for the Java virtual machine to use
# TYPE jvm_memory_committed_bytes gauge
jvm_memory_committed_bytes{area="heap",id="G1 Eden Space"} 1.05906176E8
jvm_memory_committed_bytes{area="heap",id="G1 Old Gen"} 9.8566144E7
jvm_memory_committed_bytes{area="heap",id="G1 Survivor Space"} 9437184.0
jvm_memory_committed_bytes{area="nonheap",id="CodeHeap 'non-nmethods'"} 2555904.0
jvm_memory_committed_bytes{area="nonheap",id="CodeHeap 'non-profiled nmethods'"} 6029312.0
jvm_memory_committed_bytes{area="nonheap",id="CodeHeap 'profiled nmethods'"} 2.94912E7
jvm_memory_committed_bytes{area="nonheap",id="Compressed Class Space"} 1.1599872E7
jvm_memory_committed_bytes{area="nonheap",id="Metaspace"} 8.5131264E7
# HELP jvm_memory_max_bytes The maximum amount of memory in bytes that can be used for memory management
# TYPE jvm_memory_max_bytes gauge
jvm_memory_max_bytes{area="heap",id="G1 Eden Space"} -1.0
jvm_memory_max_bytes{area="heap",id="G1 Old Gen"} 1.610612736E9
jvm_memory_max_bytes{area="heap",id="G1 Survivor Space"} -1.0
jvm_memory_max_bytes{area="nonheap",id="CodeHeap 'non-nmethods'"} 5849088.0
jvm_memory_max_bytes{area="nonheap",id="CodeHeap 'non-profiled nmethods'"} 1.22912768E8
jvm_memory_max_bytes{area="nonheap",id="CodeHeap 'profiled nmethods'"} 1.22896384E8
jvm_memory_max_bytes{area="nonheap",id="Compressed Class Space"} 1.073741824E9
jvm_memory_max_bytes{area="nonheap",id="Metaspace"} -1.0
# HELP jvm_memory_used_bytes The amount of used memory
# TYPE jvm_memory_used_bytes gauge
jvm_memory_used_bytes{area="heap",id="G1 Eden Space"} 3.7748736E7
jvm_memory_used_bytes{area="heap",id="G1 Old Gen"} 7.9550064E7
jvm_memory_used_bytes{area="heap",id="G1 Survivor Space"} 9429968.0
jvm_memory_used_bytes{area="nonheap",id="CodeHeap 'non-nmethods'"} 1627392.0
jvm_memory_used_bytes{area="nonheap",id="CodeHeap 'non-profiled nmethods'"} 5970560.0
jvm_memory_used_bytes{area="nonheap",id="CodeHeap 'profiled nmethods'"} 2.943872E7
jvm_memory_used_bytes{area="nonheap",id="Compressed Class Space"} 1.1215128E7
jvm_memory_used_bytes{area="nonheap",id="Metaspace"} 8.4249168E7

默认响应内容类型为 text/plain;version=0.0.4。 当使用合适的 Accept 头时,该端点也可以生成 application/openmetrics-text;version=1.0.0,如下基于 curl 的示例:

$ curl 'http://localhost:8080/actuator/prometheus' -i -X GET \
    -H 'Accept: application/openmetrics-text; version=1.0.0; charset=utf-8'

响应结果类似如下:

HTTP/1.1 200 OK
Content-Type: application/openmetrics-text;version=1.0.0;charset=utf-8
Content-Length: 3096

# TYPE jvm_buffer_count_buffers gauge
# HELP jvm_buffer_count_buffers An estimate of the number of buffers in the pool
jvm_buffer_count_buffers{id="direct"} 4.0
jvm_buffer_count_buffers{id="mapped"} 0.0
jvm_buffer_count_buffers{id="mapped - 'non-volatile memory'"} 0.0
# TYPE jvm_buffer_memory_used_bytes gauge
# HELP jvm_buffer_memory_used_bytes An estimate of the memory that the Java virtual machine is using for this buffer pool
jvm_buffer_memory_used_bytes{id="direct"} 61440.0
jvm_buffer_memory_used_bytes{id="mapped"} 0.0
jvm_buffer_memory_used_bytes{id="mapped - 'non-volatile memory'"} 0.0
# TYPE jvm_buffer_total_capacity_bytes gauge
# HELP jvm_buffer_total_capacity_bytes An estimate of the total capacity of the buffers in this pool
jvm_buffer_total_capacity_bytes{id="direct"} 61440.0
jvm_buffer_total_capacity_bytes{id="mapped"} 0.0
jvm_buffer_total_capacity_bytes{id="mapped - 'non-volatile memory'"} 0.0
# TYPE jvm_memory_committed_bytes gauge
# HELP jvm_memory_committed_bytes The amount of memory in bytes that is committed for the Java virtual machine to use
jvm_memory_committed_bytes{area="heap",id="G1 Eden Space"} 1.05906176E8
jvm_memory_committed_bytes{area="heap",id="G1 Old Gen"} 9.8566144E7
jvm_memory_committed_bytes{area="heap",id="G1 Survivor Space"} 9437184.0
jvm_memory_committed_bytes{area="nonheap",id="CodeHeap 'non-nmethods'"} 2555904.0
jvm_memory_committed_bytes{area="nonheap",id="CodeHeap 'non-profiled nmethods'"} 6029312.0
jvm_memory_committed_bytes{area="nonheap",id="CodeHeap 'profiled nmethods'"} 2.9425664E7
jvm_memory_committed_bytes{area="nonheap",id="Compressed Class Space"} 1.1599872E7
jvm_memory_committed_bytes{area="nonheap",id="Metaspace"} 8.4934656E7
# TYPE jvm_memory_max_bytes gauge
# HELP jvm_memory_max_bytes The maximum amount of memory in bytes that can be used for memory management
jvm_memory_max_bytes{area="heap",id="G1 Eden Space"} -1.0
jvm_memory_max_bytes{area="heap",id="G1 Old Gen"} 1.610612736E9
jvm_memory_max_bytes{area="heap",id="G1 Survivor Space"} -1.0
jvm_memory_max_bytes{area="nonheap",id="CodeHeap 'non-nmethods'"} 5849088.0
jvm_memory_max_bytes{area="nonheap",id="CodeHeap 'non-profiled nmethods'"} 1.22912768E8
jvm_memory_max_bytes{area="nonheap",id="CodeHeap 'profiled nmethods'"} 1.22896384E8
jvm_memory_max_bytes{area="nonheap",id="Compressed Class Space"} 1.073741824E9
jvm_memory_max_bytes{area="nonheap",id="Metaspace"} -1.0
# TYPE jvm_memory_used_bytes gauge
# HELP jvm_memory_used_bytes The amount of used memory
jvm_memory_used_bytes{area="heap",id="G1 Eden Space"} 3.5651584E7
jvm_memory_used_bytes{area="heap",id="G1 Old Gen"} 7.9550064E7
jvm_memory_used_bytes{area="heap",id="G1 Survivor Space"} 9429968.0
jvm_memory_used_bytes{area="nonheap",id="CodeHeap 'non-nmethods'"} 1627392.0
jvm_memory_used_bytes{area="nonheap",id="CodeHeap 'non-profiled nmethods'"} 5966720.0
jvm_memory_used_bytes{area="nonheap",id="CodeHeap 'profiled nmethods'"} 2.9393664E7
jvm_memory_used_bytes{area="nonheap",id="Compressed Class Space"} 1.1203024E7
jvm_memory_used_bytes{area="nonheap",id="Metaspace"} 8.4101232E7
# EOF

查询参数

该端点使用查询参数来限制返回的样本。 下表展示了支持的查询参数:

Parameter Description

includedNames

Restricts the samples to those that match the names. Optional.

获取过滤后的指标

要获取匹配特定名称的指标,请使用 includedNames 查询参数向 /actuator/prometheus 发起 GET 请求,如下基于 curl 的示例:

$ curl 'http://localhost:8080/actuator/prometheus?includedNames=jvm_memory_used_bytes%2Cjvm_memory_committed_bytes' -i -X GET

响应结果类似如下:

HTTP/1.1 200 OK
Content-Type: text/plain;version=0.0.4;charset=utf-8
Content-Length: 1461

# HELP jvm_memory_committed_bytes The amount of memory in bytes that is committed for the Java virtual machine to use
# TYPE jvm_memory_committed_bytes gauge
jvm_memory_committed_bytes{area="heap",id="G1 Eden Space"} 1.05906176E8
jvm_memory_committed_bytes{area="heap",id="G1 Old Gen"} 9.8566144E7
jvm_memory_committed_bytes{area="heap",id="G1 Survivor Space"} 9437184.0
jvm_memory_committed_bytes{area="nonheap",id="CodeHeap 'non-nmethods'"} 2555904.0
jvm_memory_committed_bytes{area="nonheap",id="CodeHeap 'non-profiled nmethods'"} 6029312.0
jvm_memory_committed_bytes{area="nonheap",id="CodeHeap 'profiled nmethods'"} 2.94912E7
jvm_memory_committed_bytes{area="nonheap",id="Compressed Class Space"} 1.1599872E7
jvm_memory_committed_bytes{area="nonheap",id="Metaspace"} 8.5131264E7
# HELP jvm_memory_used_bytes The amount of used memory
# TYPE jvm_memory_used_bytes gauge
jvm_memory_used_bytes{area="heap",id="G1 Eden Space"} 3.8797312E7
jvm_memory_used_bytes{area="heap",id="G1 Old Gen"} 7.9550064E7
jvm_memory_used_bytes{area="heap",id="G1 Survivor Space"} 9429968.0
jvm_memory_used_bytes{area="nonheap",id="CodeHeap 'non-nmethods'"} 1627392.0
jvm_memory_used_bytes{area="nonheap",id="CodeHeap 'non-profiled nmethods'"} 5971328.0
jvm_memory_used_bytes{area="nonheap",id="CodeHeap 'profiled nmethods'"} 2.9469952E7
jvm_memory_used_bytes{area="nonheap",id="Compressed Class Space"} 1.1215712E7
jvm_memory_used_bytes{area="nonheap",id="Metaspace"} 8.4260656E7