이 페이지는 모니터링 해야하는 MySQL metric에 대해 정리한다.
Monitoring Metrics
MySQL provides a few good metrics for monitoring your connections:
Variable | What it represents | Why you should monitor it |
Threads_connected | This variable indicates the total number of clients that have currently open connections to the server. | It provides real-time information on how many clients are currently connected to the server. This can help in traffic analysis or in deciding the best time for a server re-start. |
Threads_running | The number of threads that are not sleeping. | It’s good for isolating which connected threads are actively processing queries at any given time, as opposed to connections that are open but are currently idle. |
Connections | The number of connection attempts (successful or not) to the MySQL server. | It can give you a good idea of how many people and applications are accessing the database. Over time, these numbers reveal busiest times and average usage numbers. |
Connection_errors_internal | The number of connections refused due to internal server errors, such as failure to start a new thread or an out-of-memory condition. | Although MySQL exposes several metrics on connection errors, Connection_errors_internal is probably the most useful, because it is incremented only when the error comes from the server itself. Internal errors can indicate an out-of-memory condition or an inability to start a new thread. |
How to monitor
We can use the MySQL show status command to show MySQL variables and status information. Here are a few examples:
SHOW GLOBAL STATUS LIKE '%Threads_connected%';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_connected | 2 |
+-------------------+-------+
SHOW GLOBAL STATUS LIKE '%Threads_running%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| Threads_running | 1 |
+-----------------+-------+
SHOW GLOBAL STATUS LIKE 'Connections';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Connections | 20 |
+---------------+-------+