度量 (metrics)

metrics 端点提供对应用程序指标的访问,以诊断应用程序记录的指标。此端点不应在生产中“抓取”或用作指标后端。其目的是显示当前注册的指标,以便用户可以看到哪些指标可用、它们当前的值是多少,以及触发某些操作是否会导致某些值发生变化。如果您想通过收集的指标诊断您的应用程序,您应该使用外部指标后端。在这种情况下,metrics 端点仍然很有用。

检索指标名称

要检索可用指标的名称,请向 /actuator/metrics 发出 GET 请求,如以下基于 curl 的示例所示

$ curl 'https://: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" ]
}

响应结构

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

路径 类型 描述

名称

数组

已知指标的名称。

检索指标

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

$ curl 'https://: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

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

查询参数

该端点使用查询参数通过其标签向下钻取指标。下表显示了唯一支持的查询参数

参数 描述

标签

用于向下钻取的标签,格式为 name:value

响应结构

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

路径 类型 描述

name

字符串

指标名称

描述

字符串

指标描述

基本单位

字符串

指标的基本单位

测量

数组

指标测量

测量[].统计

字符串

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

测量[].值

数字

测量值。

可用标签

数组

可用于向下钻取的标签。

可用标签[].标签

字符串

标签名称。

可用标签[].值

数组

标签的可能值。

向下钻取

要向下钻取指标,请使用 tag 查询参数向 /actuator/metrics/{metric.name} 发出 GET 请求,如以下基于 curl 的示例所示

$ curl 'https://: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

{
  "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"
}
© . This site is unofficial and not affiliated with VMware.