diff --git a/TOC.md b/TOC.md index f43a907fc6fb..d70f837fd403 100644 --- a/TOC.md +++ b/TOC.md @@ -46,9 +46,6 @@ + AWS + GCP + Alibaba Cloud - + 监控与告警设置 - + [监控框架概述](/tidb-monitoring-framework.md) @李宋高 - + [监控 API](/tidb-monitoring-api.md) @李宋高 + [测试验证](/post-installation-check.md) @李仲舒 + 性能测试报告及重现指南 + [如何用 Sysbench 测试 TiDB](/benchmark/benchmark-tidb-using-sysbench.md) @周跃跃 @@ -77,11 +74,16 @@ + 使用 BR 工具 + [使用 BR 进行备份与恢复](/br/backup-and-restore-tool.md) @栾成 + [BR 备份与恢复场景示例](/br/backup-and-restore-use-cases.md) @栾成 - + [告警处理](/handle-alerts.md) @李宋高 + [日常巡检](/daily-inspection.md) @王军 + [TiCDC 任务管理](/ticdc/manage-ticdc.md) @沈泰宁 + [TiUP 常用运维操作](/maintain-tidb-using-tiup.md) @王贤净 + [TiFlash 常用运维操作](/tiflash/maintain-tiflash.md) @雷宇 ++ 监控与告警 + + [监控框架概述](/tidb-monitoring-framework.md) @李宋高 + + [监控 API](/tidb-monitoring-api.md) @李宋高 + + [手动部署监控](/deploy-monitoring-services.md) @李宋高 + + [TiDB 集群报警规则与处理方法](/alert-rules.md) @李宋高 + + [TiFlash 报警规则与处理方法](/tiflash/tiflash-alert-rules.md) @孙若曦 + 故障诊断 + 硬件故障 @周强 + [整机](/troubleshoot-machine-issues.md) @@ -215,9 +217,6 @@ + [PD 面板](/grafana-pd-dashboard.md) @PD Team/陈书宁 + [TiKV 面板](/grafana-tikv-dashboard.md) @刘新韬 + [TiFlash 监控指标](/tiflash/monitor-tiflash.md) @孙若曦 - + 告警信息 - + [TiDB 集群报警规则与处理方法](/alert-rules.md) - + [TiFlash 报警规则与处理方法](/tiflash/tiflash-alert-rules.md) @孙若曦 + 安全加固 + [使用 TLS 加密连接](/encrypted-connections-with-tls-protocols.md) @苏立 + [为 TiDB 组件间开启 TLS 和数据加密存储](/enable-tls-between-components.md) @苏立 diff --git a/monitor-a-tidb-cluster.md b/deploy-monitoring-services.md similarity index 62% rename from monitor-a-tidb-cluster.md rename to deploy-monitoring-services.md index 749718d50308..1643c554b369 100644 --- a/monitor-a-tidb-cluster.md +++ b/deploy-monitoring-services.md @@ -1,97 +1,13 @@ --- -title: TiDB 集群监控 +title: 集群监控部署 category: how-to -aliases: ['/docs-cn/dev/how-to/monitor/monitor-a-cluster/'] --- -# TiDB 集群监控 +# TiDB 集群监控部署 -TiDB 提供了以下两种接口来监控集群状态: +本文档适用于希望手动部署 TiDB 监控报警系统的用户。TiUP 部署方式,会同时自动部署监控报警系统,无需手动部署。 -- [状态接口](#使用状态接口):通过 HTTP 接口对外汇报组件的信息。 -- [Metrics 接口](#使用-metrics-接口):使用 Prometheus 记录组件中各种操作的详细信息,使用 Grafana 进行可视化展示。 - -## 使用状态接口 - -状态接口用于监控组件的一些基本信息,并且可以作为 keepalive 的监测接口。另外,通过 PD 的状态接口可以看到整个 TiKV 集群的详细信息。 - -### TiDB Server - -- TiDB API 地址:`http://${host}:${port}` -- 默认端口:10080 -- 各类 `api_name` 详细信息:参见 [TiDB API 文档](https://github.com/pingcap/tidb/blob/master/docs/tidb_http_api.md) - -以下示例中,通过访问 `http://${host}:${port}/status` 获取当前 TiDB Server 的状态,并判断该 TiDB Server 是否存活。结果以 **JSON** 格式返回: - -{{< copyable "shell-regular" >}} - -```bash -curl http://127.0.0.1:10080/status -``` - -``` -{ - connections: 0, # 当前 TiDB Server 上的客户端连接数 - version: "5.7.25-TiDB-v3.0.0-beta-250-g778c3f4a5", # TiDB 版本号 - git_hash: "778c3f4a5a716880bcd1d71b257c8165685f0d70" # TiDB 当前代码的 Git Hash -} -``` - -### PD Server - -- PD API 地址:`http://${host}:${port}/pd/api/v1/${api_name}` -- 默认端口:2379 -- 各类 `api_name` 详细信息:参见 [PD API Doc](https://download.pingcap.com/pd-api-doc.html) - -通过该接口可以获取当前所有 TiKV 节点的状态以及负载均衡信息。下面以一个单节点的 TiKV 集群为例,说明用户需要了解的信息: - -{{< copyable "shell-regular" >}} - -```bash -curl http://127.0.0.1:2379/pd/api/v1/stores -``` - -``` -{ - "count": 1, # TiKV 节点数量 - "stores": [ # TiKV 节点的列表 - # 集群中单个 TiKV 节点的信息 - { - "store": { - "id": 1, - "address": "127.0.0.1:20160", - "version": "3.0.0-beta", - "state_name": "Up" - }, - "status": { - "capacity": "20 GiB", # 存储总容量 - "available": "16 GiB", # 存储剩余容量 - "leader_count": 17, - "leader_weight": 1, - "leader_score": 17, - "leader_size": 17, - "region_count": 17, - "region_weight": 1, - "region_score": 17, - "region_size": 17, - "start_ts": "2019-03-21T14:09:32+08:00", # 启动时间 - "last_heartbeat_ts": "2019-03-21T14:14:22.961171958+08:00", # 最后一次心跳的时间 - "uptime": "4m50.961171958s" - } - } - ] -``` - -## 使用 metrics 接口 - -Metrics 接口用于监控整个集群的状态和性能。 - -- 如果使用 TiDB Ansible 部署 TiDB 集群,监控系统(Prometheus 和 Grafana)会同时部署。 -- 如果使用其他方式部署 TiDB 集群,在使用 metrics 接口前,需先[部署 Prometheus 和 Grafana](#部署-prometheus-和-grafana)。 - -成功部署 Prometheus 和 Grafana 之后,[配置 Grafana](#配置-grafana)。 - -### 部署 Prometheus 和 Grafana +## 部署 Prometheus 和 Grafana 假设 TiDB 的拓扑结构如下: @@ -104,7 +20,7 @@ Metrics 接口用于监控整个集群的状态和性能。 | Node5 | 192.168.199.117| TiKV2, node_export | | Node6 | 192.168.199.118| TiKV3, node_export | -#### 第 1 步:下载二进制包 +### 第 1 步:下载二进制包 下载二进制包: @@ -126,7 +42,7 @@ tar -xzf node_exporter-0.17.0.linux-amd64.tar.gz tar -xzf grafana-6.1.6.linux-amd64.tar.gz ``` -#### 第 2 步:在 Node1,Node2,Node3,Node4 上启动 `node_exporter` +### 第 2 步:在 Node1,Node2,Node3,Node4 上启动 `node_exporter` {{< copyable "shell-regular" >}} @@ -143,7 +59,7 @@ cd node_exporter-0.17.0.linux-amd64 --log.level="info" & ``` -#### 第 3 步:在 Node1 上启动 Prometheus +### 第 3 步:在 Node1 上启动 Prometheus 编辑 Prometheus 的配置文件: @@ -217,7 +133,7 @@ scrape_configs: --storage.tsdb.retention="15d" & ``` -#### 第 4 步:在 Node1 上启动 Grafana +### 第 4 步:在 Node1 上启动 Grafana 编辑 Grafana 的配置文件: @@ -278,11 +194,11 @@ url = https://grafana.net --config="./conf/grafana.ini" & ``` -### 配置 Grafana +## 配置 Grafana 本小节介绍如何配置 Grafana。 -#### 第 1 步:添加 Prometheus 数据源 +### 第 1 步:添加 Prometheus 数据源 1. 登录 Grafana 界面。 @@ -307,7 +223,7 @@ url = https://grafana.net 5. 点击 **Add** 保存新的数据源。 -#### 第 2 步:导入 Grafana 面板 +### 第 2 步:导入 Grafana 面板 执行以下步骤,为 PD Server、TiKV Server 和 TiDB Server 分别导入 Grafana 面板: @@ -327,7 +243,7 @@ url = https://grafana.net 6. 点击 **Import**,Prometheus 面板即导入成功。 -### 查看组件 metrics +## 查看组件 metrics 在顶部菜单中,点击 **New dashboard**,选择要查看的面板。 diff --git a/mysql-compatibility.md b/mysql-compatibility.md index cba05121e01c..d8c997148ba9 100644 --- a/mysql-compatibility.md +++ b/mysql-compatibility.md @@ -47,7 +47,7 @@ TiDB 中,对于自增列隐式分配的值,只保证单节点的自增和全 ### Performance schema -Performance schema 表在 TiDB 中返回结果为空。TiDB 使用 [Prometheus 和 Grafana](/monitor-a-tidb-cluster.md) 来监测性能指标。 +Performance schema 表在 TiDB 中返回结果为空。TiDB 使用 [Prometheus 和 Grafana](/tidb-monitoring-api.md) 来监测性能指标。 针对 SQL 性能相关的问题,从 TiDB 4.0.0-rc.1 版本开始,TiDB 支持 `statements_summary`(和 MySQL 中的 `events_statements_summary_by_digest` 功能相似),用于监控和统计 SQL 语句。参见 [Statement Summary Table](/statement-summary-tables.md)。 diff --git a/tidb-monitoring-api.md b/tidb-monitoring-api.md index e69de29bb2d1..ffde5cfc6222 100644 --- a/tidb-monitoring-api.md +++ b/tidb-monitoring-api.md @@ -0,0 +1,97 @@ +--- +title: TiDB 集群监控 API +category: how-to +aliases: ['/docs-cn/dev/monitor-a-tidb-cluster/','/docs-cn/dev/how-to/monitor/monitor-a-cluster/'] +--- + +# TiDB 集群监控 API + +TiDB 提供了以下两种接口来监控集群状态: + +- [状态接口](#使用状态接口):通过 HTTP 接口对外汇报组件的信息。 +- [Metrics 接口](#使用-metrics-接口):使用 Prometheus 记录组件中各种操作的详细信息,使用 Grafana 进行可视化展示。 + +## 使用状态接口 + +状态接口用于监控组件的一些基本信息,并且可以作为 keepalive 的监测接口。另外,通过 PD 的状态接口可以看到整个 TiKV 集群的详细信息。 + +### TiDB Server + +- TiDB API 地址:`http://${host}:${port}` +- 默认端口:10080 + +以下示例中,通过访问 `http://${host}:${port}/status` 获取当前 TiDB Server 的状态,并判断该 TiDB Server 是否存活。结果以 **JSON** 格式返回: + +{{< copyable "shell-regular" >}} + +```bash +curl http://127.0.0.1:10080/status +``` + +``` +{ + connections: 0, # 当前 TiDB Server 上的客户端连接数 + version: "5.7.25-TiDB-v4.0.0-rc-141-g7267747ae", # TiDB 版本号 + git_hash: "7267747ae0ec624dffc3fdedb00f1ed36e10284b" # TiDB 当前代码的 Git Hash +} +``` + +### PD Server + +- PD API 地址:`http://${host}:${port}/pd/api/v1/${api_name}` +- 默认端口:2379 +- 各类 `api_name` 详细信息:参见 [PD API Doc](https://download.pingcap.com/pd-api-doc.html) + +通过该接口可以获取当前所有 TiKV 节点的状态以及负载均衡信息。下面以一个单节点的 TiKV 集群为例,说明用户需要了解的信息: + +{{< copyable "shell-regular" >}} + +```bash +curl http://127.0.0.1:2379/pd/api/v1/stores +``` + +``` +{ + "count": 1, # TiKV 节点数量 + "stores": [ # TiKV 节点的列表 + # 集群中单个 TiKV 节点的信息 + { + "store": { + "id": 1, + "address": "127.0.0.1:20160", + "version": "4.0.0-rc.2", + "status_address": "172.16.5.90:20382", + "git_hash": "2fdb2804bf8ffaab4b18c4996970e19906296497", + "start_timestamp": 1590029618, + "deploy_path": "/data2/tidb_test/v4.0.rc.2/tikv-20372/bin", + "last_heartbeat": 1590030038949235439, + "state_name": "Up" + }, + "status": { + "capacity": "3.581TiB", # 存储总容量 + "available": "3.552TiB", # 存储剩余容量 + "used_size": "31.77MiB", + "leader_count": 174, + "leader_weight": 1, + "leader_score": 174, + "leader_size": 174, + "region_count": 531, + "region_weight": 1, + "region_score": 531, + "region_size": 531, + "start_ts": "2020-05-21T10:53:38+08:00", + "last_heartbeat_ts": "2020-05-21T11:00:38.949235439+08:00", + "uptime": "7m0.949235439s" + } + } + ] +``` + +## 使用 metrics 接口 + +Metrics 接口用于监控整个集群的状态和性能。 + +- 如果使用 TiDB Ansible 部署 TiDB 集群,监控系统(Prometheus 和 Grafana)会同时部署。 +- 如果使用其他方式部署 TiDB 集群,在使用 metrics 接口前,需先[部署 Prometheus 和 Grafana](/deploy-monitoring-services.md)。 + +成功部署 Prometheus 和 Grafana 之后,[配置 Grafana](/deploy-monitoring-services.md)。