度量 (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.