Check mysql-table-definition-cache

Overview

Checks the table definition cache size in MySQL/MariaDB. A cache that is too small to hold definitions for all tables causes repeated disk reads. Logic is taken from MySQLTuner script:mysql_stats(), v1.9.8.

Important Notes:

Data Collection:

  • Queries SHOW GLOBAL VARIABLES for table_definition_cache

  • Counts total tables via SELECT COUNT(*) FROM information_schema.tables

Fact Sheet

Fact

Value

Check Plugin Download

https://github.com/Linuxfabrik/monitoring-plugins/tree/main/check-plugins/mysql-table-definition-cache

Nagios/Icinga Check Name

check_mysql_table_definition_cache

Check Interval Recommendation

Every hour

Can be called without parameters

Yes

Runs on

Cross-platform

Compiled for Windows

No

3rd Party Python modules

pymysql

Help

usage: mysql-table-definition-cache [-h] [-V] [--always-ok]
                                    [--defaults-file DEFAULTS_FILE]
                                    [--defaults-group DEFAULTS_GROUP]
                                    [--timeout TIMEOUT]

Checks the table definition cache size in MySQL/MariaDB. Alerts if the cache
is too small to hold definitions for all tables, causing repeated disk reads.

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-definition-cache --defaults-file=/var/spool/icinga2/.my.cnf

Output:

table_definition_cache (400) is lower than number of tables (516) [WARNING]. Set table_definition_cache > 516 or to -1 (autosizing if supported).

States

  • OK if table_definition_cache is large enough to hold all table definitions, or set to -1 (autosizing).

  • WARN if the number of table definitions that can be cached is less than the total number of tables.

  • --always-ok suppresses all alerts and always returns OK.

Perfdata / Metrics

Name

Type

Description

mysql_table_definition_cache

Number

Number of table definitions that can be cached.

mysql_total_tables

Number

Total number of tables.

Credits, License