TiDB 集群监控部署

    本文档适用于希望手动部署 TiDB 监控报警系统的用户。TiUP 部署方式,会同时自动部署监控报警系统,无需手动部署。

    假设 TiDB 的拓扑结构如下:

    下载二进制包:

    解压二进制包:

    1. tar -xzf prometheus-2.8.1.linux-amd64.tar.gz
    2. tar -xzf node_exporter-0.17.0.linux-amd64.tar.gz
    3. tar -xzf grafana-6.1.6.linux-amd64.tar.gz

    第 2 步:在 Node1,Node2,Node3,Node4 上启动 node_exporter

    1. cd node_exporter-0.17.0.linux-amd64

    启动 node_exporter 服务:

    编辑 Prometheus 的配置文件:

    1. cd prometheus-2.8.1.linux-amd64 &&
    2. vi prometheus.yml
    1. ...
    2. global:
    3. scrape_interval: 15s
    4. evaluation_interval: 15s
    5. # scrape_timeout 设置为全局默认值 (10s)
    6. external_labels:
    7. cluster: 'test-cluster'
    8. monitor: "prometheus"
    9. scrape_configs:
    10. - job_name: 'overwritten-nodes'
    11. honor_labels: true # 不要覆盖 job 和实例的 label
    12. static_configs:
    13. - targets:
    14. - '192.168.199.113:9100'
    15. - '192.168.199.114:9100'
    16. - '192.168.199.115:9100'
    17. - '192.168.199.116:9100'
    18. - '192.168.199.117:9100'
    19. - '192.168.199.118:9100'
    20. - job_name: 'tidb'
    21. honor_labels: true # 不要覆盖 job 和实例的 label
    22. static_configs:
    23. - '192.168.199.113:10080'
    24. - job_name: 'pd'
    25. honor_labels: true # 不要覆盖 job 和实例的 label
    26. - targets:
    27. - '192.168.199.113:2379'
    28. - '192.168.199.114:2379'
    29. - '192.168.199.115:2379'
    30. - job_name: 'tikv'
    31. honor_labels: true # 不要覆盖 job 和实例的 label
    32. static_configs:
    33. - targets:
    34. - '192.168.199.116:20180'
    35. - '192.168.199.117:20180'
    36. - '192.168.199.118:20180'
    37. ...

    启动 Prometheus 服务:

    第 4 步:在 Node1 上启动 Grafana

    编辑 Grafana 的配置文件:

    1. cd grafana-6.1.6 &&
    2. vi conf/grafana.ini
    1. ...
    2. [paths]
    3. data = ./data
    4. logs = ./data/log
    5. plugins = ./data/plugins
    6. [server]
    7. http_port = 3000
    8. domain = 192.168.199.113
    9. [database]
    10. [session]
    11. check_for_updates = true
    12. [security]
    13. admin_user = admin
    14. admin_password = admin
    15. [snapshots]
    16. [users]
    17. [auth.anonymous]
    18. [auth.basic]
    19. [auth.ldap]
    20. [smtp]
    21. [emails]
    22. [log]
    23. mode = file
    24. [log.console]
    25. [log.file]
    26. level = info
    27. format = text
    28. [event_publisher]
    29. [dashboards.json]
    30. enabled = false
    31. path = ./data/dashboards
    32. [metrics]
    33. [grafana_net]
    34. url = https://grafana.net
    35. ...

    启动 Grafana 服务:

    本小节介绍如何配置 Grafana。

      • 默认地址:http://localhost:3000
      • 默认账户:admin
      • 默认密码:admin

    1. 点击 Grafana 侧边栏菜单 Configuration 中的 Data Source

    2. 点击 Add data source

    3. 指定数据源的相关信息:

      • Name 处,为数据源指定一个名称。
      • Type 处,选择 Prometheus
      • URL 处,指定 Prometheus 的 IP 地址。
      • 根据需求指定其它字段。
    4. 点击 Add 保存新的数据源。

    第 2 步:导入 Grafana 面板

    执行以下步骤,为 PD Server、TiKV Server 和 TiDB Server 分别导入 Grafana 面板:

    1. 点击侧边栏的 Grafana 图标。

    2. 在侧边栏菜单中,依次点击 Dashboards > Import 打开 Import Dashboard 窗口。

    3. 注意:

      TiKV、PD 和 TiDB 面板对应的 JSON 文件分别为 tikv_summary.jsontikv_details.jsontikv_trouble_shooting.jsonpd.json,,tidb_summary.json

    4. 点击 Load

    5. 选择一个 Prometheus 数据源。

    6. 点击 Import,Prometheus 面板即导入成功。

    在顶部菜单中,点击 New dashboard,选择要查看的面板。

    可查看以下集群组件信息:

    • TiDB Server:

      • query 处理时间,可以看到延迟和吞吐
      • ddl 过程监控
      • TiKV client 相关的监控
      • PD client 相关的监控
    • PD Server:

      • 命令执行的总次数
      • 某个命令执行失败的总次数
      • 某个命令执行成功的耗时统计
      • 某个命令执行失败的耗时统计
      • 某个命令执行完成并返回结果的耗时统计
      • GC 监控
      • 执行 KV 命令的总次数
      • Scheduler 执行命令的耗时统计
      • Raft propose 命令的总次数
      • Raft 执行命令的耗时统计
      • Raft 执行命令失败的总次数