度量 (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"
}
向下鑽取
要向下鑽取指標,請使用 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 標籤的值為 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
{
"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"
}