Where to Find Monitoring Items Related to Idle & Active Connections in TiDB

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: TIDB 空闲&活跃链接数相关的监控项哪里能获取

| username: residentevil

[TiDB Usage Environment] Production Environment
[TiDB Version] v6.1.7
[Encountered Problem: Problem Phenomenon and Impact] How to obtain monitoring items for thread_connected idle connections and thread_running active connections in TiDB, as shown in the following image:

| username: WalterWj | Original post link

Performance Overview 面板重要监控指标详解 | PingCAP 文档中心 matches active

| username: tidb菜鸟一只 | Original post link

I guess you want to see SELECT * FROM METRICS_SCHEMA.tikv_threads_state;
This is a record of the state of TiKV threads.

| username: residentevil | Original post link

I want to see data related to threads in the TIDBServer layer.

| username: residentevil | Original post link

sum(rate(tidb_server_handle_query_duration_seconds_sum{k8s_cluster=“$k8s_cluster”,tidb_cluster=“$tidb_cluster”, sql_type!=“internal”}[1m])) I see that the formula for calculating active connections in the monitoring is like this, but I don’t understand why it’s calculated this way :sweat_smile:

| username: tidb菜鸟一只 | Original post link

tidb-server generally looks at connection-related metrics, not thread-related ones, right?
SELECT * FROM METRICS_SCHEMA.tidb_connection_count;

| username: zhanggame1 | Original post link

Take a look at INFORMATION_SCHEMA.PROCESSLIST

| username: residentevil | Original post link

It’s a good method, you can retrieve it using SQL.

| username: DBRE | Original post link

The implementation of threads_connected for tidb-server can refer to the answer above, and the implementation of threads_running can refer to this article:

| username: residentevil | Original post link

It seems that by using

select count(*) count from information_schema.processlist where Command !='Sleep';

you can get the monitoring of thread_running. :+1:

| username: Fly-bird | Original post link

Just write a script yourself to check it periodically.

| username: DBRE | Original post link

threads_connected:
SELECT instance, SUBSTRING_INDEX(group_concat(value ORDER BY time DESC), ‘,’, 1) AS value FROM METRICS_SCHEMA.tidb_connection_count GROUP BY instance;

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.