Is it possible to obtain the current database thread information through SQL?

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

Original topic: 能否通过sql拿到当前数据库的线程信息?

| username: TiDBer_UfzQKQ1w

【 TiDB Version】5.7.25-TiDB-v6.0.0
Question: Can we get the current database thread information through SQL?
Using SQL SHOW GLOBAL STATUS
WHERE
Variable_name LIKE ‘thread%’
OR Variable_name = ‘com_commit’
OR Variable_name = ‘com_rollback’
OR Variable_name = ‘questions’
OR Variable_name = ‘uptime’
MySQL:


TiDB:
image

| username: TiDBer_UfzQKQ1w | Original post link

Or is it possible to use SQL to monitor the current database status and obtain some values? Is there such an SQL? I haven’t found such documentation yet.

| username: WalterWj | Original post link

Can’t we use metrics? TiDB itself uses Prometheus, which I understand should be sufficient.

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

Directly using this won’t work?

| username: TiDBer_UfzQKQ1w | Original post link

Thank you, I just found the monitoring data in the METRICS related tables.

| username: TiDBer_UfzQKQ1w | Original post link

For integrating with internal company projects, only SQL methods can be used.

| username: WalterWj | Original post link

Well, each component of TiDB has a metrics API on the status port. If your company has specific format requirements, you can write a script in Python to fetch it :thinking:

However, I still recommend using the official monitoring and alerting tools provided, as they are generally sufficient.

| username: system | Original post link

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