指标 (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" ]
}

响应结构

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

路径

类型

描述

names

Array

已知指标的名称。

检索指标

要检索某个指标,可以通过 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'" ]
  } ]
}

查询参数

端点使用查询参数通过其标签 深入分析 指标。下表显示了唯一支持的查询参数:

Parameter

Description

tag

用于深入分析的标签,格式为 name:value

响应结构

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

路径

类型

描述

name

String

指标的名称

description

String

指标的描述

baseUnit

String

指标的基本单位

measurements

Array

指标的测量值

measurements[].statistic

String

测量的统计数据。 (TOTAL, TOTAL_TIME, COUNT, MAX, VALUE, UNKNOWN, ACTIVE_TASKS, DURATION).

measurements[].value

Number

测量值。

availableTags

Array

可用于深入分析的标签。

availableTags[].tag

String

标签的名称。

availableTags[].values

Array

标签的可能值。

深入分析

要深入分析某个指标,可以通过 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 标签的值为 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" : [ ]
}