Check mysql-slow-queries

Overview

Checks the slow query log, which is a record of SQL queries that took a long time to perform on MySQL/MariaDB. Logic is taken from MySQLTuner script:mysql_stats(), v1.9.8.

Fact Sheet

Check Plugin Download

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

Check Interval Recommendation

Every 5 minutes

Can be called without parameters

Yes

Available for

Python 3, Windows

Requirements

Python module mysql.connector; User with no privileges, locked down to 127.0.0.1 - for example mon-log@127.0.0.1. Usernames in MySQL/MariaDB are limited to 16 chars in specific versions.

Help

usage: mysql-slow-queries [-h] [-V] [--always-ok] [-H HOSTNAME] [-p PASSWORD]
                          [--port PORT] [-u USERNAME]

Checks the slow query log, which is a record of SQL queries that took a long
time to perform on MySQL/MariaDB.

options:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  --always-ok           Always returns OK.
  -H HOSTNAME, --hostname HOSTNAME
                        MySQL/MariaDB hostname. Default: 127.0.0.1
  -p PASSWORD, --password PASSWORD
                        Use the indicated password to authenticate the
                        connection. Default:
  --port PORT           MySQL/MariaDB port. Default: 3306
  -u USERNAME, --username USERNAME
                        MySQL/MariaDB username. Default: root

Usage Examples

./mysql-slow-queries --hostname localhost --username root --password mypassword

Output:

Slow queries: 7.0% (7.0 slow queries/100.0 questions) [WARNING]. Set long_query_time <= 10. Enable the slow_query_log to troubleshoot bad queries.

States

  • WARN if the number of slow queries is more than 5% of all queries.

Perfdata / Metrics

Name

Type

Description

mysql_long_query_time

Seconds

If a query takes longer than this many seconds to execute, the Slow_queries status variable is incremented and, if enabled, the query is logged to the slow query log.

mysql_questions

Continous Counter

Number of statements executed by the server, excluding COM_PING, COM_STATISTICS, COM_STMT_PREPARE, COM_STMT_CLOSE, and COM_STMT_RESET statements. Doesn’t count statements executed within stored programs.

mysql_slow_queries

Continous Counter

Number of queries which took longer than long_query_time to run. The slow query log does not need to be active for this to be recorded.

mysql_pct_slow_queries

Percentage

Slow_queries / Questions * 100

Credits, License