跳到主要内容

指标 (metrics)

DeepSeek V3 中英对照 Metrics (metrics)

metrics 端点提供了对应用程序指标的访问。

获取指标名称

要获取可用指标的名称,可以向 /actuator/metrics 发起一个 GET 请求,如下面的基于 curl 的示例所示:

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

生成的响应类似于以下内容:

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" ]
}
http

响应结构

响应中包含指标名称的详细信息。下表描述了响应的结构:

路径类型描述
namesArray已知指标的名称。

获取指标

要检索一个指标,请向 /actuator/metrics/{metric.name} 发送一个 GET 请求,如下面的基于 curl 的示例所示:

$ curl 'http://localhost:8080/actuator/metrics/jvm.memory.max' -i -X GET
bash

前面的示例检索了名为 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'" ]
} ]
}
http

查询参数

该端点通过使用查询参数来深入分析某个指标。下表展示了唯一支持的查询参数:

参数描述
tag用于下钻的标签,格式为 name:value

响应结构

响应中包含指标的详细信息。下表描述了响应的结构:

路径类型描述
nameString指标的名称
descriptionString指标的描述
baseUnitString指标的基础单位
measurementsArray指标的测量值
measurements[].statisticString测量值的统计类型。(TOTAL, TOTAL_TIME, COUNT, MAX, VALUE, UNKNOWN, ACTIVE_TASKS, DURATION).
measurements[].valueNumber测量值的数值。
availableTagsArray可供下钻的标签。
availableTags[].tagString标签的名称。
availableTags[].valuesArray标签的可能值。

深入分析

要深入分析某个指标,可以使用 tag 查询参数向 /actuator/metrics/{metric.name} 发起 GET 请求,如下所示基于 curl 的示例:

$ curl 'http://localhost:8080/actuator/metrics/jvm.memory.max?tag=area%3Anonheap&tag=id%3ACompressed+Class+Space' -i -X GET
bash

前面的示例检索了 jvm.memory.max 指标,其中 area 标签的值为 nonheapid 属性的值为 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" : [ ]
}
http