Check mysql-thread-cache¶
Overview¶
Checks how effectively MySQL/MariaDB caches threads for re-use. A low cache hit rate means the server frequently creates new threads, which is expensive. Logic is taken from MySQLTuner script:mysql_stats(), v1.9.8.
Important Notes:
When the thread pool is enabled (Percona or MariaDB), the value of
thread_cache_sizeis ignored andThreads_cachedshows 0
Data Collection:
Queries
SHOW GLOBAL VARIABLESforhave_threadpoolandthread_cache_sizeQueries
SHOW GLOBAL STATUSforConnections,Threads_created, andUptimeCalculates the hit rate as
100 - (Threads_created / Connections * 100)
Fact Sheet¶
Fact |
Value |
|---|---|
Check Plugin Download |
https://github.com/Linuxfabrik/monitoring-plugins/tree/main/check-plugins/mysql-thread-cache |
Nagios/Icinga Check Name |
|
Check Interval Recommendation |
Every hour |
Can be called without parameters |
Yes |
Runs on |
Cross-platform |
Compiled for Windows |
No |
Requirements |
User with no privileges, locked down to |
3rd Party Python modules |
|
Help¶
usage: mysql-thread-cache [-h] [-V] [--always-ok]
[--defaults-file DEFAULTS_FILE]
[--defaults-group DEFAULTS_GROUP]
[--timeout TIMEOUT]
Checks how effectively MySQL/MariaDB caches threads for re-use. A low cache
hit rate means the server frequently creates new threads, which is expensive.
Alerts when the cache hit rate is too low.
options:
-h, --help show this help message and exit
-V, --version show program's version number and exit
--always-ok Always returns OK.
--defaults-file DEFAULTS_FILE
MySQL/MariaDB cnf file to read parameters like user,
host and password from (instead of specifying them on
the command line). Example:
`/var/spool/icinga2/.my.cnf`. Default:
/var/spool/icinga2/.my.cnf
--defaults-group DEFAULTS_GROUP
Group/section to read from in the cnf file. Default:
client
--timeout TIMEOUT Network timeout in seconds. Default: 3 (seconds)
Usage Examples¶
./mysql-thread-cache --defaults-file=/var/spool/icinga2/.my.cnf
Output:
100.0% thread cache hit rate (910.0 threads created / 8.7M connections).
States¶
OK if the thread cache hit rate is above 50% (after at least one hour of uptime) or if the thread pool is active.
WARN if
thread_cache_sizeis 0.WARN if thread cache hit rate is 50% or lower.
--always-oksuppresses all alerts and always returns OK.
Perfdata / Metrics¶
Name |
Type |
Description |
|---|---|---|
mysql_connections |
Continuous Counter |
Number of connection attempts (both successful and unsuccessful). |
mysql_thread_cache_hit_rate |
Percentage |
100 - Threads_created / Connections * 100 |
mysql_thread_cache_size |
Bytes |
Number of threads server caches for re-use. |
mysql_threads_created |
Continuous Counter |
Number of threads created to respond to client connections. If too large, look at increasing thread_cache_size. |
Credits, License¶
Authors: Linuxfabrik GmbH, Zurich
License: The Unlicense, see LICENSE file.
Credits:
heavily inspired by MySQLTuner (https://github.com/major/MySQLTuner-perl)