指标 (metrics
)
metrics
)
metrics
端点提供了对应用程序指标的访问。
获取指标名称
要获取可用指标的名称,可以向 /actuator/metrics
发起一个 GET
请求,如下面的基于 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 | 已知指标的名称。 |
获取指标
要检索一个指标,请向 /actuator/metrics/{metric.name}
发送一个 GET
请求,如下面的基于 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'" ]
} ]
}
查询参数
该端点通过使用查询参数来深入分析某个指标。下表展示了唯一支持的查询参数:
参数 | 描述 |
---|---|
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 | 标签的可能值。 |
深入分析
要深入分析某个指标,可以使用 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
前面的示例检索了 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" : [ ]
}