Check mysql-table-cache¶
Overview¶
Checks the hit rate for open table cache lookups in MySQL/MariaDB. A low hit rate indicates that table_open_cache may need to be increased. Logic is taken from MySQLTuner:mysql_stats() and has been verified in sync with MySQLTuner v2.8.38.
Important Notes:
Requires MySQL/MariaDB v5.1+
Table_open_cache_overflowsis intentionally not tracked. The MySQL reference manual describes it as „the number of times, after a table is opened or closed, a cache instance has an unused entry and the size of the instance is larger thantable_open_cache / table_open_cache_instances“ (MySQL Server Status Variables). In other words, it is a routine cache-housekeeping counter that increments whenever MySQL temporarily extends a per-instance cache bucket above its allocated share, so a non-zero value is not by itself a problem. A MySQL 5.6 benchmark by Dimitri Kravtchuk shows healthy servers running with non-zero overflows for hours. The existingtable_cache_hit_rate < 20%warn threshold already covers the „table_open_cache is too small“ signal and matches the same heuristic MySQLTuner v2.8.38 still uses. See MariaDB KB: Optimizing table_open_cache for further tuning guidance.
Data Collection:
Queries
SHOW GLOBAL VARIABLESforopen_files_limitandtable_open_cacheQueries
SHOW GLOBAL STATUSforOpen_tables,Opened_tables,Table_open_cache_hits, andTable_open_cache_missesIf
Table_open_cache_hitsis available, the hit rate is calculated asTable_open_cache_hits / (Table_open_cache_hits + Table_open_cache_misses) * 100. Otherwise falls back toOpen_tables / Opened_tables * 100.
Fact Sheet¶
Fact |
Value |
|---|---|
Check Plugin Download |
https://github.com/Linuxfabrik/monitoring-plugins/tree/main/check-plugins/mysql-table-cache |
Nagios/Icinga Check Name |
|
Check Interval Recommendation |
Every 5 minutes |
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-table-cache [-h] [-V] [--always-ok]
[--defaults-file DEFAULTS_FILE]
[--defaults-group DEFAULTS_GROUP] [--timeout TIMEOUT]
Checks the hit rate for open table cache lookups in MySQL/MariaDB. A low hit
rate indicates that table_open_cache may need to be increased. Alerts when the
hit rate drops below acceptable levels.
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-table-cache --defaults-file=/var/spool/icinga2/.my.cnf
Output:
100.0% table cache hit rate (2.3M hits / 2.3M requests)
States¶
OK if the table cache hit rate is 20% or higher.
WARN if the table cache hit rate is below 20%.
--always-oksuppresses all alerts and always returns OK.
Perfdata / Metrics¶
Name |
Type |
Description |
|---|---|---|
mysql_open_files_limit |
Number |
The number of file descriptors available to MariaDB. |
mysql_open_tables |
Number |
Number of currently opened tables, excluding temporary tables. |
mysql_opened_tables |
Continuous Counter |
Number of tables the server has opened. |
mysql_table_cache_hit_rate |
Percentage |
Table cache hit rate. |
mysql_table_open_cache |
Number |
Maximum number of open tables cached in one table cache instance. |
mysql_table_open_cache_hits |
Continuous Counter |
Number of hits for open tables cache lookups. |
mysql_table_open_cache_misses |
Continuous Counter |
Number of misses for open tables cache lookups. |
Credits, License¶
Authors: Linuxfabrik GmbH, Zurich
License: The Unlicense, see LICENSE file.
Credits:
heavily inspired by MySQLTuner (https://github.com/jmrenouard/MySQLTuner-perl)