TiDB Monitoring API

You can use the following types of interfaces to monitor the TiDB cluster status:

  • The status interface: this interface uses the HTTP interface to get the component information. Using this interface, you can get the running status of the current TiDB server and the storage information of a table.
  • The metrics interface: this interface uses Prometheus to record the detailed information of the various operations in components and views these metrics using Grafana.

Use the status interface

The status interface monitors the basic information of a specific component in the TiDB cluster. It can also act as the monitor interface for Keepalive messages. In addition, the status interface for the Placement Driver (PD) can get the details of the entire TiKV cluster.

TiDB server

  • TiDB API address: http://${host}:${port}
  • Default port: 10080

Running status

The following example uses http://${host}:${port}/status to get the current status of the TiDB server and to determine whether the server is alive. The result is returned in JSON format.

  1. curl http://127.0.0.1:10080/status
  2. {
  3. connections: 0, # The current number of clients connected to the TiDB server.
  4. version: "8.0.11-TiDB-v8.1.0", # The TiDB version number.
  5. git_hash: "778c3f4a5a716880bcd1d71b257c8165685f0d70" # The Git Hash of the current TiDB code.
  6. }

Storage information

The following example uses http://${host}:${port}/schema_storage/${db}/${table} to get the storage information of the specific data table. The result is returned in JSON format.

  1. curl http://127.0.0.1:10080/schema_storage/mysql/stats_histograms
  1. {
  2. "table_schema": "mysql",
  3. "table_name": "stats_histograms",
  4. "table_rows": 0,
  5. "avg_row_length": 0,
  6. "data_length": 0,
  7. "max_data_length": 0,
  8. "index_length": 0,
  9. "data_free": 0
  10. }
  1. curl http://127.0.0.1:10080/schema_storage/test
  1. [
  2. {
  3. "table_schema": "test",
  4. "table_name": "test",
  5. "table_rows": 0,
  6. "avg_row_length": 0,
  7. "data_length": 0,
  8. "max_data_length": 0,
  9. "index_length": 0,
  10. "data_free": 0
  11. }
  12. ]

PD server

  • PD API address: http://${host}:${port}/pd/api/v1/${api_name}
  • Default port: 2379
  • Details about API names: see PD API doc

The PD interface provides the status of all the TiKV servers and the information about load balancing. See the following example for the information about a single-node TiKV cluster:

  1. curl http://127.0.0.1:2379/pd/api/v1/stores
  2. {
  3. "count": 1, # The number of TiKV nodes.
  4. "stores": [ # The list of TiKV nodes.
  5. # The details about the single TiKV node.
  6. {
  7. "store": {
  8. "id": 1,
  9. "address": "127.0.0.1:20160",
  10. "version": "3.0.0-beta",
  11. "state_name": "Up"
  12. },
  13. "status": {
  14. "capacity": "20 GiB", # The total capacity.
  15. "available": "16 GiB", # The available capacity.
  16. "leader_count": 17,
  17. "leader_weight": 1,
  18. "leader_score": 17,
  19. "leader_size": 17,
  20. "region_count": 17,
  21. "region_weight": 1,
  22. "region_score": 17,
  23. "region_size": 17,
  24. "start_ts": "2019-03-21T14:09:32+08:00", # The starting timestamp.
  25. "last_heartbeat_ts": "2019-03-21T14:14:22.961171958+08:00", # The timestamp of the last heartbeat.
  26. "uptime": "4m50.961171958s"
  27. }
  28. }
  29. ]

Use the metrics interface

The metrics interface monitors the status and performance of the entire TiDB cluster.

After Prometheus and Grafana are successfully deployed, configure Grafana.