TiDB中查看数据库级别的QPS方法

网友投稿 426 2024-03-06



本文演示如何在grafana中配置database级别的 QPS,其他监控图表的添加或者修改也可以当做参考。

在TiDB中查看数据库级别的QPS方法

在官方文档中可以看到有相关参数,默认关闭。

record-db-qps

输出与 database 相关的 QPS metrics 到 Prometheus 的开关。

默认值:false

1.开启record-db-qps 参数

tiup cluster edit-config tidb-test

添加status.record-db-qps: true

server_configs: tidb: log.slow-threshold: 300 new_collations_enabled_on_first_bootstrap: true status.record-db-qps: true

tiup cluster reload tidb-test

注意:开启该参数可能会导致一定的性能下降

2.验证参数生效

访问 prometheus

地址:http://xx.xx.xx.xx:9090/graph

在prometheus界面可以看到数据已经正常采集到了。

或者通过http 接口curl http://__tidb_ip__:10080/metrics |grep tidb_executor_statement_total 也可以看到。

[root@test1 ~]# curl http://10.0.0.1:10080/metrics |grep tidb_executor_statement_db_total % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0# HELP tidb_executor_statement_db_total Counter of StmtNode by Database. TYPE tidb_executor_statement_db_total counter tidb_executor_statement_db_total{db="sbtest",type="Delete"} 19 tidb_executor_statement_db_total{db="sbtest",type="Select"} 11 100 426k 0 426k 0 0 55.8M 0 --:--:-- --:--:-- --:--:-- 59.5M

通过命令 grep -r "tidb_executor_statement_db_total" /tidb-deploy/grafana-3000/dashboards

发现现有的 .json 文件里没有相关的信息,说明 grafana 中并没有相关的图表,只能自己添加。

3.在grafana上添加图表

grafana 的 UI 编辑保存功能没有开启,无法直接修改或者添加图表,同时为了 reload 时不将修改的监控页面覆盖,直接修改 .json 文件。

首先确定图表想加的位置,例如想加到 Overview 中 TiDB 下的第一个图。

vim /tidb-deploy/grafana-3000/bin/overview.json

"id": 2 (Statement OPS对应的内容)之前添加如下内容。其中 id 可以为不和现有重复的任意值。title 为图表标题,这里取为 QPS for Databases 。targets 后为对应表达式,可以根据需要修改。其余部分拷贝其他监控项的即可。

"id": 111, "legend": { "alignAsTable": true, "avg": true, "current": true, "hideEmpty": true, "hideZero": true, "max": true, "min": false, "rightSide": true, "show": true, "sideWidth": null, "sort": "max", "sortDesc": true, "total": false, "values": true }, "lines": true, "linewidth": 1, "links": [], "maxPerRow": 1, "nullPointMode": "null as zero", "percentage": false, "pointradius": 5, "points": false, "renderer": "flot", "seriesOverrides": [], "spaceLength": 10, "stack": false, "steppedLine": false, "targets": [ { "expr": "sum(rate(tidb_executor_statement_db_total{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\"}[1m])) by (db,type)", "format": "time_series", "intervalFactor": 2, "legendFormat": "{{db}}-{{type}}", "refId": "A", "step": 10 } ], "thresholds": [], "timeFrom": null, "timeRegions": [], "timeShift": null, "title": "QPS for Databases", "tooltip": { "msResolution": true, "shared": true, "sort": 0, "value_type": "individual" }, "type": "graph", "xaxis": { "buckets": null, "mode": "time", "name": null, "show": true, "values": [] }, "yaxes": [ { "format": "short", "label": null, "logBase": 2, "max": null, "min": "0", "show": true }, { "format": "short", "label": null, "logBase": 1, "max": null, "min": null, "show": true } ], "yaxis": { "align": false, "alignLevel": null } }, { "aliasColors": {}, "bars": false, "dashLength": 10, "dashes": false, "datasource": "${DS_TEST-CLUSTER}", "fill": 1, "gridPos": { "h": 7, "w": 12, "x": 12, "y": 3 },

执行 tiup cluster reload tidb-test -R grafana 使配置生效并重启 grafana。

4.验证

对应 grafana 页面中出现了QPS for Databases的图表。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:在Rocky 9下生成PDF格式TiDB文档的简易方法
下一篇:分布式数据库特点并发可用
相关文章