ใช้ SHOW STATUS ตัวแปร Threads_connected และ SHOW PROCESSLIST
ดู Active Connections
mysql> SHOW STATUS WHERE Variable_name = 'Threads_connected';
+-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | Threads_connected | 1 | +-------------------+-------+
ดู Process List รายละเอียด
mysql> SHOW PROCESSLIST;
+----+-----------------+-----------------+----------+---------+--------+------------------------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+-----------------+-----------------+----------+---------+--------+------------------------+------------------+ | 4 | event_scheduler | localhost | NULL | Daemon | 349012 | Waiting on empty queue | NULL | | 11 | root | localhost:54746 | business | Query | 1 | starting | show processlist | +----+-----------------+-----------------+----------+---------+--------+------------------------+------------------+
ตัวแปร Status ที่เกี่ยวข้อง
| Variable | ความหมาย |
|---|---|
Threads_connected | Connection ที่เปิดอยู่ตอนนี้ (Active) |
Threads_running | Connection ที่กำลัง Execute Query (ไม่รวม Sleep) |
Connections | Connection ทั้งหมดนับตั้งแต่ Start Server (Cumulative) |
Max_used_connections | Peak Concurrent Connections |
Aborted_connects | Connection ที่พยายามเชื่อมแต่ Failed |
Query ดูทั้งหมดพร้อมกัน
SHOW GLOBAL STATUS WHERE Variable_name IN
('Threads_connected', 'Threads_running', 'Connections', 'Max_used_connections', 'Aborted_connects');
Monitoring: ตั้ง Alert เมื่อ Threads_connected ใกล้ max_connections (Default 151) และดู Threads_running สำหรับ Load จริง