指标 (metrics)
metrics
端点提供应用程序指标的访问。
检索指标名称
要检索可用指标的名称,可以通过 GET
请求访问 /actuator/metrics
,以下是基于 curl 的示例:
curl 'http://localhost:8080/actuator/metrics' -i -X GET
返回的响应类似于以下内容:
HTTP/1.1 200 OK Content-Type: application/vnd.spring-boot.actuator.v3+json Content-Length: 154 { "names" : [ "jvm.buffer.count", "jvm.buffer.memory.used", "jvm.buffer.total.capacity", "jvm.memory.committed", "jvm.memory.max", "jvm.memory.used" ] }
检索指标
要检索某个指标,可以通过 GET
请求访问 /actuator/metrics/{metric.name}
,以下是基于 curl 的示例:
curl 'http://localhost:8080/actuator/metrics/jvm.memory.max' -i -X GET
上述示例检索了名为 jvm.memory.max
的指标的信息。返回的响应类似于以下内容:
HTTP/1.1 200 OK Content-Disposition: inline;filename=f.txt Content-Type: application/vnd.spring-boot.actuator.v3+json Content-Length: 555 { "name" : "jvm.memory.max", "description" : "The maximum amount of memory in bytes that can be used for memory management", "baseUnit" : "bytes", "measurements" : [ { "statistic" : "VALUE", "value" : 2.399141885E9 } ], "availableTags" : [ { "tag" : "area", "values" : [ "heap", "nonheap" ] }, { "tag" : "id", "values" : [ "CodeHeap 'profiled nmethods'", "G1 Old Gen", "CodeHeap 'non-profiled nmethods'", "G1 Survivor Space", "Compressed Class Space", "Metaspace", "G1 Eden Space", "CodeHeap 'non-nmethods'" ] } ] }
响应结构
响应包含指标的详细信息。下表描述了响应的结构:
路径 |
类型 |
描述 |
|
|
指标的名称 |
|
|
指标的描述 |
|
|
指标的基本单位 |
|
|
指标的测量值 |
|
|
测量的统计数据。 ( |
|
|
测量值。 |
|
|
可用于深入分析的标签。 |
|
|
标签的名称。 |
|
|
标签的可能值。 |
深入分析
要深入分析某个指标,可以通过 GET
请求访问 /actuator/metrics/{metric.name}
,并使用标签查询参数,以下是基于 curl 的示例:
curl 'http://localhost:8080/actuator/metrics/jvm.memory.max?tag=area%3Anonheap&tag=id%3ACompressed+Class+Space' -i -X GET
上述示例检索了 jvm.memory.max
指标,其中 area
标签的值为 nonheap
,id
属性的值为 Compressed Class Space
。返回的响应类似于以下内容:
HTTP/1.1 200 OK Content-Disposition: inline;filename=f.txt Content-Type: application/vnd.spring-boot.actuator.v3+json Content-Length: 263 { "name" : "jvm.memory.max", "description" : "The maximum amount of memory in bytes that can be used for memory management", "baseUnit" : "bytes", "measurements" : [ { "statistic" : "VALUE", "value" : 1.073741824E9 } ], "availableTags" : [ ] }