MySQL Router 9.0  /  MySQL Router REST API  /  MySQL Router REST API 參考

6.2 MySQL Router REST API 參考

假設已知 basePath 前綴。basePath 包含 API 版本,例如 "/api/20190715"。例如,如果端點是 "/metadata",則 URL 類似於 "https://127.0.0.1:8443/api/20190715/metadata"。請參閱 第 6.1 節,〈簡單的 MySQL Router REST API 指南〉 以取得相關資訊。

表 6.1:MySQL Router REST API 端點

端點 描述 外掛程式 方法
/metadata 取得元數據實例名稱 rest_metadata_cache GET
/metadata/{metadataName}/config 取得元數據組態詳細資訊 rest_metadata_cache GET
/metadata/{metadataName}/status 檢查元數據狀態 rest_metadata_cache GET
/router/status 檢查路由器狀態 rest_router GET
/routes 取得路由清單 rest_routing GET
/routes/{routeName}/blockedHosts 取得封鎖 IP 清單 rest_routing GET
/routes/{routeName}/config 取得路由組態詳細資訊 rest_routing GET
/routes/{routeName}/connections 取得路由連線 rest_routing GET
/routes/{routeName}/destinations 取得路由目的地 rest_routing GET
/routes/{routeName}/health 檢查路由健全狀況 rest_routing GET
/routes/{routeName}/status 檢查路由狀態 rest_routing GET
/connection_pool/{name}/config 檢查 connection_pool 組態 rest_connection_pool GET
/connection_pool/{name}/status 檢查 connection_pool 狀態 rest_connection_pool GET
swagger.json 取得包含可用路徑和資訊的 swagger 檔案 rest_api GET

metadata

GET /metadata

取得元數據快取實例的清單

可用的回應

200

描述:元數據快取實例的清單

回應架構

項目

陣列

包含 'name' 欄位;元數據實例的名稱

範例 200 回應資料

{
  "items": [
    {
      "name": "myCluster"
    }
  ]
}

GET /metadata/{metadataName}/config

取得叢集複寫集的元數據快取組態

可用的回應

200

描述:元數據快取的組態

回應架構

clusterName

字串

選用,複寫群組的名稱

timeRefreshInMs

整數

TTL 數字

groupReplicationId

字串

選用

nodes

陣列

陣列;項目包含主機名稱 (字串) 和連接埠 (整數) 屬性

404

描述:找不到快取

路徑參數

metadataName (必要)

字串

叢集的名稱

範例 200 回應資料

{
  "clusterName": "myCluster",
  "timeRefreshInMs": 500,
  "groupReplicationId": "e57e9c11-abfe-11ea-b747-0800278566cb",
  "nodes": [
    {
      "hostname": "127.0.0.1",
      "port": 3310
    },
    {
      "hostname": "127.0.0.1",
      "port": 3320
    },
    {
      "hostname": "127.0.0.1",
      "port": 3330
    }
  ]
}

GET /metadata/{metadataName}/status

取得叢集複寫集的元數據快取狀態

可用的回應

200

描述:元數據快取的狀態

回應架構

lastRefreshHostname

字串

lastRefreshPort

整數

timeLastRefreshFailed

字串

timeLastRefreshSucceeded

字串

refreshSucceeded

整數

refreshFailed

整數

404

描述:找不到快取

路徑參數

metadataName (必要)

字串

叢集的名稱

範例 200 回應資料

{
  "refreshFailed": 0,
  "refreshSucceeded": 798,
  "timeLastRefreshSucceeded": "2020-06-11T21:17:37.270303Z",
  "lastRefreshHostname": "127.0.0.1",
  "lastRefreshPort": 3310
}

router

GET /router/status

取得路由器的狀態

可用的回應

200

描述:路由器的狀態

回應內容類型:application/json

回應架構

hostname

字串

執行應用程式的主機名稱;如果未設定主機,則可能為空白

processId

整數

應用程式的處理程序 ID

productEdition

字串

產品版本,例如「MySQL Community - GPL」

timeStarted

字串

應用程式啟動的日期時間字串,例如「2020-06-11T22:08:30.978640Z」

version

字串

應用程式的版本,例如「8.0.22」

範例 200 回應資料

{
  "processId": 6435,
  "productEdition": "MySQL Community - GPL",
  "timeStarted": "2020-06-11T21:10:49.420619Z",
  "version": "8.0.20",
  "hostname": "boat"
}

routes

GET /routes

取得 MySQL Router 支援的路由清單 (名稱)

可用的回應

200

描述:支援的路由清單

回應架構

項目

陣列

路由清單

範例 200 回應資料

{
  "items": [
    {
      "name": "myCluster_ro"
    },
    {
      "name": "myCluster_rw"
    },
    {
      "name": "myCluster_x_ro"
    },
    {
      "name": "myCluster_x_rw"
    }
  ]
}

GET /routes/{routeName}/config

取得路由的組態

可用的回應

200

描述:路由的組態

回應架構

bindAddress

字串

路由正在監聽的位址

bindPort

整數

路由器正在監聽的 TCP 連接埠

clientConnectTimeoutInMs

整數

傳入連線的連線逾時

destinationConnectTimeoutInMs

整數

傳出連線的連線逾時

maxActiveConnections

整數

作用中連線的最大數量

maxConnectErrors

整數

在用戶端被封鎖之前,相鄰連線錯誤的最大數量

protocol

字串

通訊協定,可以是 'classic' 或 'x'

socket

字串

監聽通訊端或具名管道

routingStrategy

字串

使用的路由策略;如 Router 的策略組態選項所定義的「round-robin」、「round-robin-with-fallback」、「first-available」或「next-available」

404

描述:找不到路由

路徑參數

routeName (必要)

字串

路由的名稱

範例 200 回應資料

{
  "bindAddress": "0.0.0.0",
  "bindPort": 6446,
  "clientConnectTimeoutInMs": 9000,
  "destinationConnectTimeoutInMs": 15000,
  "maxActiveConnections": 512,
  "maxConnectErrors": 100,
  "protocol": "classic",
  "routingStrategy": "first-available"
}

GET /routes/{routeName}/status

取得路由的狀態

可用的回應

200

描述:路由的狀態

回應架構

activeConnections

整數

路由上的作用中連線數量

totalConnections

整數

路由處理的連線數量

blockedHosts

整數

已封鎖的主機數量

404

描述:找不到路由

範例 200 回應資料

{
  "activeConnections": 1,
  "totalConnections": 1,
  "blockedHosts": 0
}

路徑參數

routeName (必要)

字串

路由的名稱

GET /routes/{routeName}/health

取得路由的健全狀況

可用的回應

200

描述:路由的健全狀況

回應架構

isAlive

布林值

404

描述:找不到路由

路徑參數

routeName (必要)

字串

路由的名稱

範例 200 回應資料

{
  "isAlive": true
}

GET /routes/{routeName}/destinations

取得路由的目的地

可用的回應

200

描述:路由的目的地

回應架構

項目

陣列

包含 'address' (字串,目的地節點的 IP 位址) 和 'port' (整數,目的地節點的連接埠)

404

描述:找不到路由

路徑參數

routeName (必要)

字串

路由的名稱

範例 200 回應資料

{
  "items": [
    {
      "address": "127.0.0.1",
      "port": 3320
    },
    {
      "address": "127.0.0.1",
      "port": 3330
    }
  ]
}

GET /routes/{routeName}/connections

取得路由的連線

可用的回應

200

描述:路由的連線

回應架構

項目

陣列

每個項目條目都包含下列內容

  • bytesFromServer:整數,在指定連線上從伺服器傳送到用戶端的位元組數

  • BytesToServer:整數,在指定連線上從用戶端傳送到伺服器的位元組數

  • sourceAddress:字串,連線來源 (用戶端) 的位址:連接埠配對

  • destinationAddress:字串,連線目的地 (伺服器) 的位址:連接埠配對

  • timeStarted:字串,連線初始化的時間點

  • timeConnectedToServer:字串,連線成功建立的時間點

  • timeLastSentToServer:字串,在指定連線上,上次從用戶端傳送資料到伺服器的時間點

  • timeLastReceivedFromServer:字串,在指定連線上,上次從伺服器傳送資料到用戶端的時間點

404

描述:找不到路由

路徑參數

routeName (必要)

字串

路由的名稱

範例 200 回應資料

{
  "items": [
    {
      "bytesFromServer": 2952,
      "bytesToServer": 743,
      "sourceAddress": "127.0.0.1:54098",
      "destinationAddress": "127.0.0.1:3310",
      "timeStarted": "2020-06-11T21:28:20.882204Z",
      "timeConnectedToServer": "2020-06-11T21:28:20.882513Z",
      "timeLastSentToServer": "2020-06-11T21:28:20.886969Z",
      "timeLastReceivedFromServer": "2020-06-11T21:28:20.886968Z"
    }
  ]
}

GET /routes/{routeName}/blockedHosts

取得路由的封鎖主機清單

可用的回應

200

描述:路由的封鎖主機清單

回應架構

項目

陣列

目前由路由核心封鎖的 IP 位址

404

描述:找不到路由

路徑參數

routeName (必要)

字串

路由的名稱

範例 200 回應資料

{
  "items": []
}

connection_pool

GET /connection_pool/{name}/config

顯示 maxIdleServerConnections,如 max_idle_server_connection 組態選項所定義。這是連線集區中閒置伺服器連線的最大數量 (整數)。

顯示 idleTimeout,如 idle_timeout 組態選項所定義。這是連線集區中連線關閉前的逾時秒數 (整數)。

GET /connection_pool/{name}/status

顯示 reusedConnections,作為應用程式啟動後重複使用伺服器連線的用戶端連線計數 (整數)。

顯示 idleServerConnections,作為目前在連線集區中的閒置伺服器連線計數 (整數)。

swagger.json

GET /swagger.json

取得本地 REST API 實例的 Swagger (OpenAPI) 檔案。存取此檔案不需要身份驗證;任何有權存取 REST API 的人都可以產生並檢視它。OpenAPI 內容取決於啟用的 REST API 外掛程式。

範例 200 回應資料

{
  "swagger": "2.0",
  "info": {
    "title": "MySQL Router",
    "description": "API of MySQL Router",
    "version": "20190715"
  },
  "basePath": "/api/20190715",
  "tags": [
    {
      "name": "connectionpool",
      "description": "Connection Pool"
    },
    {
      "name": "cluster",
      "description": "InnoDB Cluster"
    },
    {
      "name": "app",
      "description": "Application"
    },
    {
      "name": "routes",
      "description": "Routes"
    }
  ],
  "paths": {
    "/connection_pool/{connectionPoolName}/status": {
      "get": {
        "tags": [
          "connectionpool"
        ],
        "description": "Get status of a route",
        "responses": {
          "200": {
            "description": "status of a route",
            "schema": {
              "$ref": "#/definitions/ConnectionPoolStatus"
            }
          },
          "404": {
            "description": "route not found"
          }
        }
      },
      "parameters": [
        {
          "$ref": "#/parameters/connectionPoolNameParam"
        }
      ]
    },
    "/connection_pool/{connectionPoolName}/config": {
      "get": {
        "tags": [
          "connectionpool"
        ],
        "description": "Get config of a route",
        "responses": {
          "200": {
            "description": "config of a route",
            "schema": {
              "$ref": "#/definitions/ConnectionPoolConfig"
            }
          },
          "404": {
            "description": "route not found"
          }
        }
      },
      "parameters": [
        {
          "$ref": "#/parameters/connectionPoolNameParam"
        }
      ]
    },
    "/connection_pool": {
      "get": {
        "tags": [
          "connectionpool"
        ],
        "description": "Get list of the connection pools",
        "responses": {
          "200": {
            "description": "list of the connection pools",
            "schema": {
              "$ref": "#/definitions/ConnectionPoolList"
            }
          }
        }
      }
    },
    "/metadata/{metadataName}/config": {
      "get": {
        "tags": [
          "cluster"
        ],
        "description": "Get config of the metadata cache of a replicaset of a cluster",
        "responses": {
          "200": {
            "description": "config of metadata cache",
            "schema": {
              "$ref": "#/definitions/MetadataConfig"
            }
          },
          "404": {
            "description": "cache not found"
          }
        }
      },
      "parameters": [
        {
          "$ref": "#/parameters/metadataNameParam"
        }
      ]
    },
    "/metadata/{metadataName}/status": {
      "get": {
        "tags": [
          "cluster"
        ],
        "description": "Get status of the metadata cache of a replicaset of a cluster",
        "responses": {
          "200": {
            "description": "status of metadata cache",
            "schema": {
              "$ref": "#/definitions/MetadataStatus"
            }
          },
          "404": {
            "description": "cache not found"
          }
        }
      },
      "parameters": [
        {
          "$ref": "#/parameters/metadataNameParam"
        }
      ]
    },
    "/metadata": {
      "get": {
        "tags": [
          "cluster"
        ],
        "description": "Get list of the metadata cache instances",
        "responses": {
          "200": {
            "description": "list of the metadata cache instances",
            "schema": {
              "$ref": "#/definitions/MetadataList"
            }
          }
        }
      }
    },
    "/router/status": {
      "get": {
        "tags": [
          "app"
        ],
        "description": "Get status of the application",
        "responses": {
          "200": {
            "description": "status of application",
            "schema": {
              "$ref": "#/definitions/RouterStatus"
            }
          }
        }
      }
    },
    "/routing/status": {
      "get": {
        "tags": [
          "routing"
        ],
        "description": "Get status of the routing plugin",
        "responses": {
          "200": {
            "description": "status of the routing plugin",
            "schema": {
              "$ref": "#/definitions/RoutingGlobalStatus"
            }
          }
        }
      }
    },
    "/routes/{routeName}/config": {
      "get": {
        "tags": [
          "routes"
        ],
        "description": "Get config of a route",
        "responses": {
          "200": {
            "description": "config of a route",
            "schema": {
              "$ref": "#/definitions/RouteConfig"
            }
          },
          "404": {
            "description": "route not found"
          }
        }
      },
      "parameters": [
        {
          "$ref": "#/parameters/routeNameParam"
        }
      ]
    },
    "/routes/{routeName}/status": {
      "get": {
        "tags": [
          "routes"
        ],
        "description": "Get status of a route",
        "responses": {
          "200": {
            "description": "status of a route",
            "schema": {
              "$ref": "#/definitions/RouteStatus"
            }
          },
          "404": {
            "description": "route not found"
          }
        }
      },
      "parameters": [
        {
          "$ref": "#/parameters/routeNameParam"
        }
      ]
    },
    "/routes/{routeName}/health": {
      "get": {
        "tags": [
          "routes"
        ],
        "description": "Get health of a route",
        "responses": {
          "200": {
            "description": "health of a route",
            "schema": {
              "$ref": "#/definitions/RouteHealth"
            }
          },
          "404": {
            "description": "route not found"
          }
        }
      },
      "parameters": [
        {
          "$ref": "#/parameters/routeNameParam"
        }
      ]
    },
    "/routes/{routeName}/destinations": {
      "get": {
        "tags": [
          "routes"
        ],
        "description": "Get destinations of a route",
        "responses": {
          "200": {
            "description": "destinations of a route",
            "schema": {
              "$ref": "#/definitions/RouteDestinationList"
            }
          },
          "404": {
            "description": "route not found"
          }
        }
      },
      "parameters": [
        {
          "$ref": "#/parameters/routeNameParam"
        }
      ]
    },
    "/routes/{routeName}/connections": {
      "get": {
        "tags": [
          "routes"
        ],
        "description": "Get connections of a route",
        "responses": {
          "200": {
            "description": "connections of a route",
            "schema": {
              "$ref": "#/definitions/RouteConnectionsList"
            }
          },
          "404": {
            "description": "route not found"
          }
        }
      },
      "parameters": [
        {
          "$ref": "#/parameters/routeNameParam"
        }
      ]
    },
    "/routes/{routeName}/blockedHosts": {
      "get": {
        "tags": [
          "routes"
        ],
        "description": "Get blocked host list for a route",
        "responses": {
          "200": {
            "description": "blocked host list for a route",
            "schema": {
              "$ref": "#/definitions/RouteBlockedHostList"
            }
          },
          "404": {
            "description": "route not found"
          }
        }
      },
      "parameters": [
        {
          "$ref": "#/parameters/routeNameParam"
        }
      ]
    },
    "/routes": {
      "get": {
        "tags": [
          "routes"
        ],
        "description": "Get list of the routes",
        "responses": {
          "200": {
            "description": "list of the routes",
            "schema": {
              "$ref": "#/definitions/RouteList"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "ConnectionPoolStatus": {
      "type": "object",
      "properties": {
        "reusedServerConnections": {
          "type": "integer"
        },
        "idleServerConnections": {
          "type": "integer"
        }
      }
    },
    "ConnectionPoolConfig": {
      "type": "object",
      "properties": {
        "idleTimeoutInMs": {
          "type": "integer"
        },
        "maxIdleServerConnections": {
          "type": "integer"
        }
      }
    },
    "ConnectionPoolSummary": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        }
      }
    },
    "ConnectionPoolList": {
      "type": "object",
      "properties": {
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/ConnectionPoolSummary"
          }
        }
      }
    },
    "MetadataStatus": {
      "type": "object",
      "properties": {
        "lastRefreshHostname": {
          "type": "string"
        },
        "lastRefreshPort": {
          "type": "integer"
        },
        "timeLastRefreshFailed": {
          "type": "string",
          "format": "data-time"
        },
        "timeLastRefreshSucceeded": {
          "type": "string",
          "format": "data-time"
        },
        "refreshSucceeded": {
          "type": "integer"
        },
        "refreshFailed": {
          "type": "integer"
        }
      }
    },
    "MetadataConfig": {
      "type": "object",
      "properties": {
        "clusterName": {
          "type": "string"
        },
        "timeRefreshInMs": {
          "type": "integer"
        },
        "groupReplicationId": {
          "type": "string"
        },
        "nodes": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "hostname": {
                "type": "string"
              },
              "port": {
                "type": "integer"
              }
            }
          }
        }
      }
    },
    "MetadataSummary": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        }
      }
    },
    "MetadataList": {
      "type": "object",
      "properties": {
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/MetadataSummary"
          }
        }
      }
    },
    "ClusterNodeSummary": {
      "type": "object",
      "properties": {
        "groupUuid": {
          "type": "string"
        },
        "serverUuid": {
          "type": "string"
        }
      }
    },
    "ClusterNodeList": {
      "type": "object",
      "properties": {
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/ClusterNodeSummary"
          }
        }
      }
    },
    "ClusterSummary": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        }
      }
    },
    "ClusterList": {
      "type": "object",
      "properties": {
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/ClusterSummary"
          }
        }
      }
    },
    "RouterStatus": {
      "type": "object",
      "properties": {
        "timeStarted": {
          "type": "string",
          "format": "data-time"
        },
        "processId": {
          "type": "integer"
        },
        "version": {
          "type": "string"
        },
        "hostname": {
          "type": "string"
        },
        "productEdition": {
          "type": "string"
        }
      }
    },
    "RoutingGlobalStatus": {
      "totalMaxConnections": "number of total connections allowed",
      "currentMaxConnections": "number of current total connections"
    },
    "RouteHealth": {
      "type": "object",
      "properties": {
        "isAlive": {
          "type": "boolean"
        }
      }
    },
    "RouteStatus": {
      "type": "object",
      "properties": {
        "activeConnections": {
          "type": "integer"
        },
        "totalConnections": {
          "type": "integer"
        },
        "blockedHosts": {
          "type": "integer"
        }
      }
    },
    "RouteConfig": {
      "type": "object",
      "properties": {
        "bindAddress": {
          "type": "string"
        },
        "bindPort": {
          "type": "integer"
        },
        "clientConnectTimeoutInMs": {
          "type": "integer"
        },
        "destinationConnectTimeoutInMs": {
          "type": "integer"
        },
        "maxActiveConnections": {
          "type": "integer"
        },
        "maxConnectErrors": {
          "type": "integer"
        },
        "protocol": {
          "type": "string"
        },
        "socket": {
          "type": "string"
        },
        "routingStrategy": {
          "type": "string"
        },
      }
    },
    "RouteSummary": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        }
      }
    },
    "RouteList": {
      "type": "object",
      "properties": {
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/RouteSummary"
          }
        }
      }
    },
    "RouteDestinationSummary": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        }
      }
    },
    "RouteDestinationList": {
      "type": "object",
      "properties": {
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/RouteDestinationSummary"
          }
        }
      }
    },
    "RouteBlockedHostSummary": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        }
      }
    },
    "RouteBlockedHostList": {
      "type": "object",
      "properties": {
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/RouteBlockedHostSummary"
          }
        }
      }
    },
    "RouteConnectionsSummary": {
      "type": "object",
      "properties": {
        "timeStarted": {
          "type": "string",
          "format": "date-time",
          "description": "timepoint when connection to server was initiated"
        },
        "timeConnectedToServer": {
          "type": "string",
          "format": "date-time",
          "description": "timepoint when connection to server succeeded"
        },
        "timeLastSentToServer": {
          "type": "string",
          "format": "date-time",
          "description": "timepoint when there was last data sent from client to server"
        },
        "timeLastReceivedFromServer": {
          "type": "string",
          "format": "date-time",
          "description": "timepoint when there was last data sent from server to client"
        },
        "bytesFromServer": {
          "type": "integer",
          "description": "bytes sent to destination"
        },
        "bytesToServer": {
          "type": "integer",
          "description": "bytes received from destination"
        },
        "destinationAddress": {
          "type": "string",
          "description": "address of the destination of the connection"
        },
        "sourceAddress": {
          "type": "string",
          "description": "address of the source of the connection"
        }
      }
    },
    "RouteConnectionsList": {
      "type": "object",
      "properties": {
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/RouteConnectionsSummary"
          }
        }
      }
    }
  },
  "parameters": {
    "connectionPoolNameParam": {
      "name": "connectionPoolName",
      "in": "path",
      "description": "name of a connection pool",
      "required": true,
      "type": "string"
    },
    "metadataNameParam": {
      "name": "metadataName",
      "in": "path",
      "description": "name of cluster",
      "required": true,
      "type": "string"
    },
    "clusterNameParam": {
      "name": "clusterName",
      "in": "path",
      "description": "name of cluster",
      "required": true,
      "type": "string"
    },
    "routeNameParam": {
      "name": "routeName",
      "in": "path",
      "description": "name of a route",
      "required": true,
      "type": "string"
    }
  }
}