Please sign up at support.zabbix.com to log into Zabbix Bitbucket dashboard
README.md

MySQL by Zabbix agent

Overview

This template is designed for the effortless deployment of MySQL monitoring by Zabbix via Zabbix agent and doesn't require any external scripts.

Requirements

Zabbix version: 7.0 and higher.

Tested versions

This template has been tested on:

  • MySQL 5.7, 8.0
  • Percona 8.0
  • MariaDB 10.4, 10.6.8

Configuration

Zabbix should be configured according to the instructions in the Templates out of the box section.

Setup

  1. Install Zabbix agent and MySQL client. If necessary, add the path to the mysql and mysqladmin utilities to the global environment variable PATH.
  2. Copy template_db_mysql.conf into the folder with Zabbix agent configuration (/etc/zabbix/zabbix_agentd.d/ by default). Don't forget to restart Zabbix agent.
  3. Create a MySQL user for monitoring (<password> at your discretion):
CREATE USER 'zbx_monitor'@'%' IDENTIFIED BY '<password>';
GRANT REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@'%';

For more information, please see MySQL documentation https://dev.mysql.com/doc/refman/8.0/en/grant.html

  1. Create .my.cnf in the home directory of Zabbix agent for Linux (/var/lib/zabbix by default ) or my.cnf in c:\ for Windows. The file must have three strings:
[client]
user='zbx_monitor'
password='<password>'

NOTE: Use systemd to start Zabbix agent on Linux OS. For example, in Centos use "systemctl edit zabbix-agent.service" to set the required user to start the Zabbix agent.

Add the rule to the SELinux policy (example for Centos):

# cat <<EOF > zabbix_home.te
module zabbix_home 1.0;

require {
        type zabbix_agent_t;
        type zabbix_var_lib_t;
        type mysqld_etc_t;
        type mysqld_port_t;
        type mysqld_var_run_t;
        class file { open read };
        class tcp_socket name_connect;
        class sock_file write;
}

#============= zabbix_agent_t ==============

allow zabbix_agent_t zabbix_var_lib_t:file read;
allow zabbix_agent_t zabbix_var_lib_t:file open;
allow zabbix_agent_t mysqld_etc_t:file read;
allow zabbix_agent_t mysqld_port_t:tcp_socket name_connect;
allow zabbix_agent_t mysqld_var_run_t:sock_file write;
EOF
# checkmodule -M -m -o zabbix_home.mod zabbix_home.te
# semodule_package -o zabbix_home.pp -m zabbix_home.mod
# semodule -i zabbix_home.pp
# restorecon -R /var/lib/zabbix

Macros used

NameDescriptionDefault
{$MYSQL.ABORTED_CONN.MAX.WARN}

The number of failed attempts to connect to the MySQL server for trigger expression.

3
{$MYSQL.HOST}

Hostname or IP of MySQL host or container.

127.0.0.1
{$MYSQL.PORT}

MySQL service port.

3306
{$MYSQL.REPL_LAG.MAX.WARN}

The lag of slave from master for trigger expression.

30m
{$MYSQL.SLOW_QUERIES.MAX.WARN}

The number of slow queries for trigger expression.

3
{$MYSQL.BUFF_UTIL.MIN.WARN}

The minimum buffer pool utilization in percentage for trigger expression.

50
{$MYSQL.CREATED_TMP_TABLES.MAX.WARN}

The maximum number of created tmp tables in memory per second for trigger expressions.

30
{$MYSQL.CREATED_TMP_DISK_TABLES.MAX.WARN}

The maximum number of created tmp tables on a disk per second for trigger expressions.

10
{$MYSQL.CREATED_TMP_FILES.MAX.WARN}

The maximum number of created tmp files on a disk per second for trigger expressions.

10
{$MYSQL.INNODB_LOG_FILES}

Number of physical files in the InnoDB redo log for calculating innodb_log_file_size.

2

Items

NameDescriptionTypeKey and additional info
MySQL: Get status variables

The item gets server global status information.

Zabbix agentmysql.get_status_variables["{$MYSQL.HOST}","{$MYSQL.PORT}"]
MySQL: StatusZabbix agentmysql.ping["{$MYSQL.HOST}","{$MYSQL.PORT}"]

Preprocessing

  • JavaScript: return value.indexOf('is alive') !== -1 ? 1 : 0;

  • Discard unchanged with heartbeat: 10m

MySQL: VersionZabbix agentmysql.version["{$MYSQL.HOST}","{$MYSQL.PORT}"]

Preprocessing

  • Regular expression: (Server version)\s+(.+) \2

  • Discard unchanged with heartbeat: 1d

MySQL: Uptime

The amount of seconds that the server has been up.

Dependent itemmysql.uptime

Preprocessing

  • XML XPath: The text is too long. Please see the template.

MySQL: Aborted clients per second

Number of connections that were aborted because the client died without closing the connection properly.

Dependent itemmysql.aborted_clients.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Aborted connections per second

Number of failed attempts to connect to the MySQL server.

Dependent itemmysql.aborted_connects.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Connection errors accept per second

Number of errors that occurred during calls to accept() on the listening port.

Dependent itemmysql.connection_errors_accept.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Connection errors internal per second

Number of refused connections due to internal server errors, for example, out of memory errors, or failed thread starts.

Dependent itemmysql.connection_errors_internal.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Connection errors max connections per second

Number of refused connections due to the max_connections limit being reached.

Dependent itemmysql.connection_errors_max_connections.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Connection errors peer address per second

Number of errors while searching for the connecting client IP address.

Dependent itemmysql.connection_errors_peer_address.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Connection errors select per second

Number of errors during calls to select() or poll() on the listening port. The client would not necessarily have been rejected in these cases.

Dependent itemmysql.connection_errors_select.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Connection errors tcpwrap per second

Number of connections the libwrap library has refused.

Dependent itemmysql.connection_errors_tcpwrap.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Connections per second

Number of connection attempts (successful or not) to the MySQL server.

Dependent itemmysql.connections.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Max used connections

The maximum number of connections that have been in use simultaneously since the server start.

Dependent itemmysql.max_used_connections

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Discard unchanged with heartbeat: 1h

MySQL: Threads cached

Number of threads in the thread cache.

Dependent itemmysql.threads_cached

Preprocessing

  • XML XPath: The text is too long. Please see the template.

MySQL: Threads connected

Number of currently open connections.

Dependent itemmysql.threads_connected

Preprocessing

  • XML XPath: The text is too long. Please see the template.

MySQL: Threads created per second

Number of threads created to handle connections. If Threads_created is big, you may want to increase the thread_cache_size value. The cache miss rate can be calculated as Threads_created/Connections.

Dependent itemmysql.threads_created.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Threads running

Number of threads which are not sleeping.

Dependent itemmysql.threads_running

Preprocessing

  • XML XPath: The text is too long. Please see the template.

MySQL: Buffer pool efficiency

The item shows how effectively the buffer pool is serving reads.

Calculatedmysql.buffer_pool_efficiency
MySQL: Buffer pool utilization

Ratio of used to total pages in the buffer pool.

Calculatedmysql.buffer_pool_utilization
MySQL: Created tmp files on disk per second

How many temporary files mysqld has created.

Dependent itemmysql.created_tmp_files.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Created tmp tables on disk per second

Number of internal on-disk temporary tables created by the server while executing statements.

Dependent itemmysql.created_tmp_disk_tables.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Created tmp tables on memory per second

Number of internal temporary tables created by the server while executing statements.

Dependent itemmysql.created_tmp_tables.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: InnoDB buffer pool pages free

The total size of the InnoDB buffer pool, in pages.

Dependent itemmysql.innodb_buffer_pool_pages_free

Preprocessing

  • XML XPath: The text is too long. Please see the template.

MySQL: InnoDB buffer pool pages total

The total size of the InnoDB buffer pool, in pages.

Dependent itemmysql.innodb_buffer_pool_pages_total

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Discard unchanged with heartbeat: 1h

MySQL: InnoDB buffer pool read requests

Number of logical read requests.

Dependent itemmysql.innodb_buffer_pool_read_requests

Preprocessing

  • XML XPath: The text is too long. Please see the template.

MySQL: InnoDB buffer pool read requests per second

Number of logical read requests per second.

Dependent itemmysql.innodb_buffer_pool_read_requests.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: InnoDB buffer pool reads

Number of logical reads that InnoDB could not satisfy from the buffer pool, and had to read directly from the disk.

Dependent itemmysql.innodb_buffer_pool_reads

Preprocessing

  • XML XPath: The text is too long. Please see the template.

MySQL: InnoDB buffer pool reads per second

Number of logical reads per second that InnoDB could not satisfy from the buffer pool, and had to read directly from the disk.

Dependent itemmysql.innodb_buffer_pool_reads.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: InnoDB row lock time

The total time spent in acquiring row locks for InnoDB tables, in milliseconds.

Dependent itemmysql.innodb_row_lock_time

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Custom multiplier: 0.001

  • Discard unchanged with heartbeat: 1h

MySQL: InnoDB row lock time max

The maximum time to acquire a row lock for InnoDB tables, in milliseconds.

Dependent itemmysql.innodb_row_lock_time_max

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Custom multiplier: 0.001

  • Discard unchanged with heartbeat: 1h

MySQL: InnoDB row lock waits

Number of times operations on InnoDB tables had to wait for a row lock.

Dependent itemmysql.innodb_row_lock_waits

Preprocessing

  • XML XPath: The text is too long. Please see the template.

MySQL: Slow queries per second

Number of queries that have taken more than long_query_time seconds.

Dependent itemmysql.slow_queries.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Bytes received

Number of bytes received from all clients.

Dependent itemmysql.bytes_received.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Bytes sent

Number of bytes sent to all clients.

Dependent itemmysql.bytes_sent.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Command Delete per second

The Com_delete counter variable indicates the number of times the delete statement has been executed.

Dependent itemmysql.com_delete.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Command Insert per second

The Com_insert counter variable indicates the number of times the insert statement has been executed.

Dependent itemmysql.com_insert.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Command Select per second

The Com_select counter variable indicates the number of times the select statement has been executed.

Dependent itemmysql.com_select.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Command Update per second

The Com_update counter variable indicates the number of times the update statement has been executed.

Dependent itemmysql.com_update.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Queries per second

Number of statements executed by the server. This variable includes statements executed within stored programs, unlike the Questions variable.

Dependent itemmysql.queries.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Questions per second

Number of statements executed by the server. This includes only statements sent to the server by clients and not statements executed within stored programs, unlike the Queries variable.

Dependent itemmysql.questions.rate

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Change per second
MySQL: Binlog cache disk use

Number of transactions that used a temporary disk cache because they could not fit in the regular binary log cache, being larger than binlog_cache_size.

Dependent itemmysql.binlog_cache_disk_use

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Discard unchanged with heartbeat: 6h

MySQL: Innodb buffer pool wait free

Number of times InnoDB waited for a free page before reading or creating a page. Normally, writes to the InnoDB buffer pool happen in the background. When no clean pages are available, dirty pages are flushed first in order to free some up. This counts the numbers of wait for this operation to finish. If this value is not small, look at the increasing innodb_buffer_pool_size.

Dependent itemmysql.innodb_buffer_pool_wait_free

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Discard unchanged with heartbeat: 6h

MySQL: Innodb number open files

Number of open files held by InnoDB. InnoDB only.

Dependent itemmysql.innodb_num_open_files

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Discard unchanged with heartbeat: 6h

MySQL: Open table definitions

Number of cached table definitions.

Dependent itemmysql.open_table_definitions

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Discard unchanged with heartbeat: 6h

MySQL: Open tables

Number of tables that are open.

Dependent itemmysql.open_tables

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Discard unchanged with heartbeat: 6h

MySQL: Innodb log written

Number of bytes written to the InnoDB log.

Dependent itemmysql.innodb_os_log_written

Preprocessing

  • XML XPath: The text is too long. Please see the template.

MySQL: Calculated value of innodb_log_file_size

Calculated by (innodb_os_log_written-innodb_os_log_written(time shift -1h))/{$MYSQL.INNODB_LOG_FILES} value of the innodb_log_file_size. Innodb_log_file_size is the size in bytes of the each InnoDB redo log file in the log group. The combined size can be no more than 512GB. Larger values mean less disk I/O due to less flushing checkpoint activity, but also slower recovery from a crash.

Calculatedmysql.innodb_log_file_size

Preprocessing

  • Discard unchanged with heartbeat: 6h

Triggers

NameDescriptionExpressionSeverityDependencies and additional info
MySQL: Service is downlast(/MySQL by Zabbix agent/mysql.ping["{$MYSQL.HOST}","{$MYSQL.PORT}"])=0High
MySQL: Version has changed

MySQL version has changed. Acknowledge to close the problem manually.

last(/MySQL by Zabbix agent/mysql.version["{$MYSQL.HOST}","{$MYSQL.PORT}"],#1)<>last(/MySQL by Zabbix agent/mysql.version["{$MYSQL.HOST}","{$MYSQL.PORT}"],#2) and length(last(/MySQL by Zabbix agent/mysql.version["{$MYSQL.HOST}","{$MYSQL.PORT}"]))>0InfoManual close: Yes
MySQL: Service has been restarted

MySQL uptime is less than 10 minutes.

last(/MySQL by Zabbix agent/mysql.uptime)<10mInfo
MySQL: Failed to fetch info data

Zabbix has not received any data for items for the last 30 minutes.

nodata(/MySQL by Zabbix agent/mysql.uptime,30m)=1InfoDepends on:
  • MySQL: Service is down
MySQL: Server has aborted connections

The number of failed attempts to connect to the MySQL server is more than {$MYSQL.ABORTED_CONN.MAX.WARN} in the last 5 minutes.

min(/MySQL by Zabbix agent/mysql.aborted_connects.rate,5m)>{$MYSQL.ABORTED_CONN.MAX.WARN}AverageDepends on:
  • MySQL: Refused connections
MySQL: Refused connections

Number of refused connections due to the max_connections limit being reached.

last(/MySQL by Zabbix agent/mysql.connection_errors_max_connections.rate)>0Average
MySQL: Buffer pool utilization is too low

The buffer pool utilization is less than {$MYSQL.BUFF_UTIL.MIN.WARN}% in the last 5 minutes. This means that there is a lot of unused RAM allocated for the buffer pool, which you can easily reallocate at the moment.

max(/MySQL by Zabbix agent/mysql.buffer_pool_utilization,5m)<{$MYSQL.BUFF_UTIL.MIN.WARN}Warning
MySQL: Number of temporary files created per second is high

Possibly the application using the database is in need of query optimization.

min(/MySQL by Zabbix agent/mysql.created_tmp_files.rate,5m)>{$MYSQL.CREATED_TMP_FILES.MAX.WARN}Warning
MySQL: Number of on-disk temporary tables created per second is high

Possibly the application using the database is in need of query optimization.

min(/MySQL by Zabbix agent/mysql.created_tmp_disk_tables.rate,5m)>{$MYSQL.CREATED_TMP_DISK_TABLES.MAX.WARN}Warning
MySQL: Number of internal temporary tables created per second is high

Possibly the application using the database is in need of query optimization.

min(/MySQL by Zabbix agent/mysql.created_tmp_tables.rate,5m)>{$MYSQL.CREATED_TMP_TABLES.MAX.WARN}Warning
MySQL: Server has slow queries

The number of slow queries is more than {$MYSQL.SLOW_QUERIES.MAX.WARN} in the last 5 minutes.

min(/MySQL by Zabbix agent/mysql.slow_queries.rate,5m)>{$MYSQL.SLOW_QUERIES.MAX.WARN}Warning

LLD rule Database discovery

NameDescriptionTypeKey and additional info
Database discovery

Scanning databases in DBMS.

Zabbix agentmysql.db.discovery["{$MYSQL.HOST}","{$MYSQL.PORT}"]

Preprocessing

  • JavaScript: The text is too long. Please see the template.

  • Discard unchanged with heartbeat: 1d

Item prototypes for Database discovery

NameDescriptionTypeKey and additional info
MySQL: Size of database {#DBNAME}Zabbix agentmysql.dbsize["{$MYSQL.HOST}","{$MYSQL.PORT}","{#DBNAME}"]

Preprocessing

  • Discard unchanged with heartbeat: 1h

LLD rule Replication discovery

NameDescriptionTypeKey and additional info
Replication discovery

If "show slave status" returns Master_Host, "Replication: *" items are created.

Zabbix agentmysql.replication.discovery["{$MYSQL.HOST}","{$MYSQL.PORT}"]

Preprocessing

  • JavaScript: The text is too long. Please see the template.

  • Discard unchanged with heartbeat: 1d

Item prototypes for Replication discovery

NameDescriptionTypeKey and additional info
MySQL: Replication Slave status {#MASTERHOST}

The item gets status information on the essential parameters of the slave threads.

Zabbix agentmysql.slave_status["{$MYSQL.HOST}","{$MYSQL.PORT}","{#MASTERHOST}"]
MySQL: Replication Slave SQL Running State {#MASTER_HOST}

This shows the state of the SQL driver threads.

Dependent itemmysql.slave_sql_running_state["{#MASTER_HOST}"]

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Discard unchanged with heartbeat: 6h

MySQL: Replication Seconds Behind Master {#MASTERHOST}

The number of seconds that the slave SQL thread is behind processing the master binary log.

A high number (or an increasing one) can indicate that the slave is unable to handle events

from the master in a timely fashion.

Dependent itemmysql.seconds_behind_master["{#MASTERHOST}"]

Preprocessing

  • XML XPath: /resultset/row/field[no='Seconds_Behind_Master']/text()

  • Discard unchanged with heartbeat: 1h

  • Does not match regular expression: null

    ⛔️Custom on fail: Set error to: Replication is not performed.

MySQL: Replication Slave IO Running {#MASTERHOST}

Whether the I/O thread for reading the master's binary log is running.

Normally, you want this to be Yes unless you have not yet started replication or have

explicitly stopped it with STOP SLAVE.

Dependent itemmysql.slave_io_running["{#MASTERHOST}"]

Preprocessing

  • XML XPath: /resultset/row/field[no='Slave_IO_Running']/text()

  • Discard unchanged with heartbeat: 1h

MySQL: Replication Slave SQL Running {#MASTERHOST}

Whether the SQL thread for executing events in the relay log is running.

As with the I/O thread, this should normally be Yes.

Dependent itemmysql.slave_sql_running["{#MASTERHOST}"]

Preprocessing

  • XML XPath: /resultset/row/field[no='Slave_SQL_Running']/text()

  • Discard unchanged with heartbeat: 1h

Trigger prototypes for Replication discovery

NameDescriptionExpressionSeverityDependencies and additional info
MySQL: Replication lag is too highmin(/MySQL by Zabbix agent/mysql.seconds_behind_master["{#MASTERHOST}"],5m)>{$MYSQL.REPL_LAG.MAX.WARN}Warning
MySQL: The slave I/O thread is not running

Whether the I/O thread for reading the master's binary log is running.

count(/MySQL by Zabbix agent/mysql.slave_io_running["{#MASTERHOST}"],#1,"eq","No")=1Average
MySQL: The slave I/O thread is not connected to a replication mastercount(/MySQL by Zabbix agent/mysql.slave_io_running["{#MASTERHOST}"],#1,"ne","Yes")=1WarningDepends on:
  • MySQL: The slave I/O thread is not running
MySQL: The SQL thread is not running

Whether the SQL thread for executing events in the relay log is running.

count(/MySQL by Zabbix agent/mysql.slave_sql_running["{#MASTERHOST}"],#1,"eq","No")=1WarningDepends on:
  • MySQL: The slave I/O thread is not running

LLD rule MariaDB discovery

NameDescriptionTypeKey and additional info
MariaDB discovery

Additional metrics if MariaDB is used.

Dependent itemmysql.extra_metric.discovery

Preprocessing

  • JavaScript: The text is too long. Please see the template.

Item prototypes for MariaDB discovery

NameDescriptionTypeKey and additional info
MySQL: Binlog commits

Total number of transactions committed to the binary log.

Dependent itemmysql.binlog_commits[{#SINGLETON}]

Preprocessing

  • XML XPath: The text is too long. Please see the template.

MySQL: Binlog group commits

Total number of group commits done to the binary log.

Dependent itemmysql.binlog_group_commits[{#SINGLETON}]

Preprocessing

  • XML XPath: The text is too long. Please see the template.

MySQL: Master GTID wait count

The number of times MASTER_GTID_WAIT called.

Dependent itemmysql.master_gtid_wait_count[{#SINGLETON}]

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Discard unchanged with heartbeat: 6h

MySQL: Master GTID wait time

Total number of time spent in MASTER_GTID_WAIT.

Dependent itemmysql.master_gtid_wait_time[{#SINGLETON}]

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Discard unchanged with heartbeat: 6h

MySQL: Master GTID wait timeouts

Number of timeouts occurring in MASTER_GTID_WAIT.

Dependent itemmysql.master_gtid_wait_timeouts[{#SINGLETON}]

Preprocessing

  • XML XPath: The text is too long. Please see the template.

  • Discard unchanged with heartbeat: 6h

Feedback

Please report any issues with the template at https://support.zabbix.com

You can also provide feedback, discuss the template, or ask for help at ZABBIX forums

Add shortcut

Everything looks good. We'll let you know here if there's anything you should know about.