指标(metrics

metrics 端点提供对应用程序指标的访问,用于诊断应用程序所记录的指标。 该端点不应在生产环境中被“抓取”或用作指标后端。 其目的是展示当前已注册的指标,以便用户可以查看有哪些指标可用、它们当前的值是多少,以及触发某些操作是否会导致特定值发生变化。 如果您希望通过收集的指标来诊断您的应用程序,应使用外部指标后端。 在这种情况下,metrics 端点仍然可能有用。spring-doc.cadn.net.cn

检索指标名称

要获取可用指标的名称,请向 GET 发起一个 /actuator/metrics 请求,如下列基于 curl 的示例所示:spring-doc.cadn.net.cn

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

生成的响应类似于以下内容:spring-doc.cadn.net.cn

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

响应结构

响应包含指标名称的详细信息。 下表描述了响应的结构:spring-doc.cadn.net.cn

路径 类型 <description> </description>

namesspring-doc.cadn.net.cn

Arrayspring-doc.cadn.net.cn

已知指标的名称。spring-doc.cadn.net.cn

检索指标

要获取某个指标,请向 GET 发起一个 /actuator/metrics/{metric.name} 请求,如下列基于 curl 的示例所示:spring-doc.cadn.net.cn

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

前面的示例检索了名为 jvm.memory.max 的指标的相关信息。 返回的响应类似于以下内容:spring-doc.cadn.net.cn

HTTP/1.1 200 OK
Content-Disposition: inline;filename=f.txt
Content-Type: application/vnd.spring-boot.actuator.v3+json
Content-Length: 555

{
  "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'" ]
  } ],
  "baseUnit" : "bytes",
  "description" : "The maximum amount of memory in bytes that can be used for memory management",
  "measurements" : [ {
    "statistic" : "VALUE",
    "value" : 2.936012797E9
  } ],
  "name" : "jvm.memory.max"
}

查询参数

该端点使用查询参数通过指标的标签来深入查看某个指标。 下表显示了唯一支持的查询参数:spring-doc.cadn.net.cn

参数 <description> </description>

tagspring-doc.cadn.net.cn

用于向下钻取的标签,格式为 name:valuespring-doc.cadn.net.cn

响应结构

响应包含该指标的详细信息。 下表描述了响应的结构:spring-doc.cadn.net.cn

路径 类型 <description> </description>

namespring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

指标名称spring-doc.cadn.net.cn

descriptionspring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

指标的描述spring-doc.cadn.net.cn

baseUnitspring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

指标的基本单位spring-doc.cadn.net.cn

measurementsspring-doc.cadn.net.cn

Arrayspring-doc.cadn.net.cn

指标的测量值spring-doc.cadn.net.cn

measurements[].statisticspring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

测量的统计信息。(TOTALTOTAL_TIMECOUNTMAXVALUEUNKNOWNACTIVE_TASKSDURATION)。spring-doc.cadn.net.cn

measurements[].valuespring-doc.cadn.net.cn

Numberspring-doc.cadn.net.cn

测量值。spring-doc.cadn.net.cn

availableTagsspring-doc.cadn.net.cn

Arrayspring-doc.cadn.net.cn

可用于向下钻取的标签。spring-doc.cadn.net.cn

availableTags[].tagspring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

标签的名称。spring-doc.cadn.net.cn

availableTags[].valuesspring-doc.cadn.net.cn

Arrayspring-doc.cadn.net.cn

标签的可能取值。spring-doc.cadn.net.cn

深入探究

要深入查看某个指标的详细信息,请向 GET 发起一个 /actuator/metrics/{metric.name} 请求,并使用 tag 查询参数,如下列基于 curl 的示例所示:spring-doc.cadn.net.cn

$ 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。 返回的结果类似于以下内容:spring-doc.cadn.net.cn

HTTP/1.1 200 OK
Content-Disposition: inline;filename=f.txt
Content-Type: application/vnd.spring-boot.actuator.v3+json
Content-Length: 263

{
  "availableTags" : [ ],
  "baseUnit" : "bytes",
  "description" : "The maximum amount of memory in bytes that can be used for memory management",
  "measurements" : [ {
    "statistic" : "VALUE",
    "value" : 1.073741824E9
  } ],
  "name" : "jvm.memory.max"
}