Check mysql-temp-tables

Overview

Checks the ratio of on-disk versus in-memory temporary tables in MySQL/MariaDB. A high rate of disk-based temporary tables indicates that tmp_table_size or max_heap_table_size may need to be increased. Logic is taken from MySQLTuner script:mysql_stats(), v1.9.8.

Important Notes:

Data Collection:

  • Queries SHOW GLOBAL VARIABLES for max_heap_table_size and tmp_table_size

  • Queries SHOW GLOBAL STATUS for Created_tmp_disk_tables and Created_tmp_tables

  • Calculates the disk temporary table rate as Created_tmp_disk_tables / Created_tmp_tables * 100

Fact Sheet

Fact

Value

Check Plugin Download

https://github.com/Linuxfabrik/monitoring-plugins/tree/main/check-plugins/mysql-temp-tables

Nagios/Icinga Check Name

check_mysql_temp_tables

Check Interval Recommendation

Every 15 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-temp-tables [-h] [-V] [--always-ok]
                         [--defaults-file DEFAULTS_FILE]
                         [--defaults-group DEFAULTS_GROUP] [--timeout TIMEOUT]

Checks the ratio of on-disk versus in-memory temporary tables in
MySQL/MariaDB. A high rate of disk-based temporary tables indicates that
tmp_table_size or max_heap_table_size may need to be increased. Alerts when
the disk-based temporary table rate is too high.

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

Output:

34.6% temporary tables created on disk (540.0 on disk / 1.6K total) 

Recommendations:
* Set tmp_table_size > 128.0MiB and max_heap_table_size > 128.0MiB
* When making adjustments, make tmp_table_size/max_heap_table_size equal
* Reduce your SELECT DISTINCT queries which have no LIMIT clause

States

  • OK if the disk-based temporary table rate is 25% or lower, or if no temporary tables have been created.

  • WARN if more than 25% of temporary tables are created on disk.

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

Perfdata / Metrics

Name

Type

Description

mysql_created_tmp_disk_tables

Continuous Counter

Number of on-disk temporary tables created.

mysql_created_tmp_tables

Continuous Counter

Number of in-memory temporary tables created.

mysql_max_heap_table_size

Bytes

Maximum size in bytes for user-created MEMORY tables.

mysql_max_tmp_table_size

Bytes

max(max_heap_table_size, tmp_table_size)

mysql_pct_temp_disk

Percentage

Created_tmp_disk_tables / Created_tmp_tables * 100

mysql_tmp_table_size

Bytes

The largest size for temporary tables in memory (not MEMORY tables) although if max_heap_table_size is smaller the lower limit will apply.

Credits, License