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+

  • See additional notes for all mysql monitoring plugins

  • Table_open_cache_overflows is 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 than table_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 existing table_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 VARIABLES for open_files_limit and table_open_cache

  • Queries SHOW GLOBAL STATUS for Open_tables, Opened_tables, Table_open_cache_hits, and Table_open_cache_misses

  • If Table_open_cache_hits is available, the hit rate is calculated as Table_open_cache_hits / (Table_open_cache_hits + Table_open_cache_misses) * 100. Otherwise falls back to Open_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_mysql_table_cache

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 127.0.0.1 - for example monitoring\@127.0.0.1. Usernames in MySQL/MariaDB are limited to 16 chars in specific versions.

3rd Party Python modules

pymysql

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-ok suppresses 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