Check mysql-joins

Overview

Checks the rate of joins executed without indexes in MySQL/MariaDB. A high number of joins without indexes per day indicates missing indexes, which can severely impact query performance.

Important Notes:

Data Collection:

  • Queries SHOW GLOBAL VARIABLES for join_buffer_size

  • Queries SHOW GLOBAL STATUS for Select_full_join, Select_range_check, and Uptime

  • Calculates the total number of joins without indexes and the daily rate

  • Logic is taken from MySQLTuner script:mysql_stats(), v1.9.8

Fact Sheet

Fact

Value

Check Plugin Download

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

Nagios/Icinga Check Name

check_mysql_joins

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

Checks the rate of joins executed without indexes in MySQL/MariaDB. A high
rate of full joins indicates missing indexes and can severely impact query
performance. Alerts when the rate of joins without indexes 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 user, host and password
                        from. Example: `--defaults-
                        file=/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-joins --defaults-file=/var/spool/icinga2/.my.cnf

Output:

143.9K JOINs without indexes while MySQL/MariaDB is 1W 6D up (approx. 10.9K joins without indexes per day) 

Recommendations:
* Use JOIN with indexes
* Otherwise set join_buffer_size > 4.0MiB

States

  • WARN if there are more than 250 joins without indexes per day.

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

Perfdata / Metrics

Name

Type

Description

mysql_join_buffer_size

Bytes

Minimum size in bytes of the buffer used for queries that cannot use an index. Increase to get faster full joins when adding indexes is not possible.

mysql_joins_without_indexes

Continuous Counter

Select_range_check + Select_full_join

mysql_joins_without_indexes_per_day

Number

joins_without_indexes / Uptime in days

mysql_select_full_join

Continuous Counter

Number of joins which did not use an index. If not zero, you may need to check table indexes.

mysql_select_range_check

Continuous Counter

Number of joins without keys that check for key usage after each row. If not zero, you may need to check table indexes.

mysql_uptime

Seconds

Number of seconds the server has been running.

Credits, License