MySQL is one of the most popular open-source relational database management systems (RDBMS). Configure this plugin and ensure an efficient database monitoring experience through vital actionable information.
This document details the following:
Failover monitoring
Receive failover alerts each time there is a failover between master and slave. This will help you ensure that your MySQL environment is always monitored and you receive timely alerts.
Performance Metrics
You can monitor various metrics to stay on top of performance, including those related to MySQL connections, queries, aborted clients and connections, query cache items, handler, read-writes, MyISAM key cache, sort, data transferred, tables, replication, and InnoDB.
Connections usage metrics
-
Maximum connection
Max connections
shows the maximum number of connection attempts to the MySQL server. -
Maximum used connections
Max Used Connections
displays the maximum number of connections that have been in use simultaneously, since the server started. -
Connection usage
Connection Usage
denotes the total number of connections with respect to the percentage of maximum connections in the database. This information can be used to tune the database connections for better performance.
Queries and questions metrics
-
Application queries
Application Queries
provides the number of statements executed by the server. This variable includes the statements executed within stored programs. -
Client queries
Client Queries
displays the number of statements executed by the server. This includes only the statements sent to the server by clients and not statements executed within stored programs. -
Slow queries
Slow Queries
provides the number of queries that have taken more time in seconds than thelong_query_time
to execute.
Aborted clients and connections metrics
-
Aborted clients
Aborted Clients
fetches the number of connections that were aborted because the client died without closing the connection properly. -
Aborted connects
Aborted Connects
denotes the number of failed attempts to connect to the MySQL server.
Table locks waited metrics
-
Table locks waited
Table Locks Waited
is the number of times the requests for table locks had to wait.
Query cache items metrics
-
Hits
Hits
denotes the number of query cache hits. -
Free memory
Free Memory
fetches the amount of free memory in bytes for the query cache. -
Not cached
Not Cached
displays the number of non-cached queries. -
In cache
In Cache
denotes the number of queries registered in the query cache. -
Free blocks
Free Blocks
displays the number of free memory blocks in the query cache. -
Inserts
Inserts
fetches the number of queries added to the query cache. -
Low memory prunes
Low Memory
Prunes denotes the number of queries that were deleted from the query cache because of low memory. -
Total blocks
Total Blocks
is the total number of blocks in the query cache.
Handler metrics
-
Handler rollback
Handler Rollback
denotes the rate of requests to perform an internal rollback operation. -
Handler delete
Handler Delete
fetches the number of times the rows in a table have been deleted. -
Handler read first
Handler Read First
displays the number of times the first entry in an index was read. -
Handler read key
Handler Read Key
provides the number of requests to read a row based on a key. -
Handler random next
Handler Random Next
fetches the number of requests to read the next row in the data file. -
Handler read random
Handler Read Random
denotes the number of requests to read a row based on a fixed position. -
Handler update
Handler Update
fetches the number of requests to update a row in a table. -
Handler write
Handler Write
displays the number of requests to insert a row in a table.
Read write metrics
-
Writes
Writes
provides the total number of writes done in a MySQL server. It is the sum of inserted queries, replaced queries, updated queries, and deleted queries. -
Reads
Reads
fetches the total number of reads done in a MySQL server. Technically, it is the number of selected queries and number of query cache hits. -
Transactions
Transactions
denotes the number of transactions.
Read queries metrics
-
Full join
Full Join
denotes the number of joins that perform table scans because they do not use indexes. -
Full range join
Full Range Join
displays the number of joins that used a range search on a reference table. -
Select range
Select Range
shows the number of joins that used ranges on the first table. -
Range check
Range Check
fetches the number of joins without keys that check for key usage after each row. -
Select scan
Select Scan
provides the number of joins that did a full scan of the first table. -
Maximum execution time exceeded
Maximum Execution Time Exceeded
denotes the number of select statements for which the execution timeout exceeded.
Write queries metrics
-
Commit
Commit
provides the number of commit statements executed. -
Commit Select
Commit Select
fetches the number of select statements executed. -
Commit delete
Commit Delete
displays the number of delete statements executed. -
Commit delete multi
Commit Delete Multi
denotes the number of delete statements that use the multiple-table syntax. -
Commit insert
Commit Insert
fetches the number of insert statements executed. -
Commit insert select
Commit Insert Select
displays the number of insert select statements executed. -
Commit replace select
Commit Replace Select
denotes the number of replace select statements executed. -
Commit rollback
Commit Rollback
provides the number of rollback statements executed. -
Commit update
Commit Update
provides the number of update statements executed. -
Commit update multi
Commit Update Multi
shows the number of update statements that use the multiple-table syntax.
MyISAM key cache metrics
-
Blocks not flushed
Blocks Not Flushed
shows the number of key blocks in the MyISAM key cache that have changed but have not yet been flushed to disk. -
Read requests
Read Requests
denotes the number of requests to read a key block from the MyISAM key cache. -
Key reads
Key Reads
displays the number of physical reads of a key block from the disk into the MyISAM key cache. -
Write requests
Write Requests
fetches the number of requests to write a key block to the MyISAM key cache. -
Key writes
Key Writes
shows the number of physical writes of a key block from the MyISAM key cache to disk.
Sort metrics
-
Merge passes
Merge Passes
denote the number of merge passes that the sort algorithm has had to execute. -
Range
Range
displays the number of sorts that were done using ranges. -
Rows
Rows
fetch the number of sorted rows. -
Scan
Scan
displays the number of sorts that were done by scanning the table.
Threads metrics
-
Connected
Connected
shows the number of currently open connections. -
Running
Running
displays the number of threads that are not sleeping. -
Cached
Cached
fetches the number of threads in the thread cache. -
Created
Created
denotes the number of threads created to handle connections.
Bytes received and sent metrics
-
Received
Received
provides the number of bytes received from all clients. -
Sent
Sent
displays the number of bytes sent to all clients.
Table cache metrics
-
Open cache hits
Open Cache Hits
displays the number of hits for open tables cache lookups. -
Open cache misses
Open Cache Misses
fetches the number of misses for open tables cache lookups. -
Open cache overflows
Open Cache overflows
provides the number of overflows for the open tables cache..
Created temporary tables (TAB2) metrics
-
Temporary tables
Temporary Tables
displays the number of internal temporary tables created by the server while executing statements. -
Disk tables
Disk Tables
denotes the number of internal on-disk temporary tables created by the server while executing statements. -
Temporary files
Temporary Files
shows the number of internal temporary tables created by the server while executing statements.
InnoDB metrics
-
Buffer pool pages data
Buffer Pool Pages Data
displays the number of pages in the InnoDB buffer pool containing data. -
Buffer pool pages dirty
Buffer Pool Pages Dirty
denotes the current number of dirty pages in the InnoDB buffer pool. -
Buffer pool pages free
Buffer Pool Pages Free
provides the number of free pages in the InnoDB buffer pool. -
Buffer pool pages total
Buffer Pool Pages Total
fetches the total number of pages in the InnoDB buffer pool. -
Buffer pool wait free
Buffer Pool Wait Free
shows the number of times a read or write to InnoDB had to wait as clean pages were not available in the buffer pool. -
Log waits
Log Waits
displays the number of times the log buffer was too small and a wait was required for it to be flushed before continuing. -
Row lock time average
Row Lock Time Avg
denotes time to acquire a row lock for InnoDB tables, in milliseconds. -
Row lock waits
Row Lock Waits
shows the number of times operations on InnoDB tables had to wait for a row lock. -
Buffer pool pages flushed
Buffer Pool Pages Flushed
fetches the number of requests to flush pages from the InnoDB buffer pool. -
Buffer pool read ahead evicted
Buffer Pool Read Ahead Evicted
denotes the number of pages that read into the InnoDB buffer pool by the read-ahead background thread that were subsequently evicted without having been accessed by queries. -
Buffer pool wait free
Buffer Pool Wait Free
shows the number of times a read or write to InnoDB had to wait as clean pages were not available in the buffer pool. -
Buffer pool read ahead
Buffer Pool Read Ahead
displays the number of pages that read into the InnoDB buffer pool by the read-ahead background thread. -
Buffer pool read ahead random
Buffer Pool Read Ahead Random
denotes the number of random read-aheads that were initiated by InnoDB. -
Buffer pool read requests
Buffer Pool Read Requests
fetches the number of logical read requests. -
Buffer pool reads
Buffer Pool Reads
shows the number of logical reads that InnoDB could not satisfy from the buffer pool, and had to read directly from disk. -
Buffer pool write requests
Buffer Pool Write Requests
fetches the number of writes in the InnoDB buffer pool. -
Data fsync
Data Fsync
displays the number of fsync() operations per second. -
Data pending fsync
Data Pending Fsync
shows the current number of pending fsync() operations. -
Data pending reads
Data Pending Reads
provides the current number of pending reads. -
Data pending writes
Data Pending Writes
denotes the current number of pending writes. -
Data reads
Data Reads
shows the number of data reads. -
Data writes
Data Writes
displays the number of data writes. -
Data write requests
Data Write Requestss
denotes the number of write requests for the InnoDB redo log file. -
Log writess
Log Writes
depicts the number of physical writes to the InnoDB redo log file. -
OS log fsyncs
OS Log Fsyncs
provides the number of fsync() writes done to the InnoDB redo log files. -
OS log pending fsyncs
OS Log Pending Fsyncs
fetches the number of pending fsync() operations for the InnoDB redo log files. -
OS log pending writes
Os Log Pending Writes
shows the number of pending writes to the InnoDB redo log files. -
OS log written
Os Log Written
displays the number of bytes written to the InnoDB redo log files. -
Pages created
Pages Created
denotes the number of pages created by operations on InnoDB tables. -
Pages read
Pages Read
depicts the number pages read from the InnoDB buffer pool by operations on InnoDB tables. -
Pages written
Pages Written
fetches the number of pages written by operations on InnoDB tables. -
Rows deleted
Rows Deleted
provides the number of rows deleted from InnoDB tables. -
Rows inserted
Rows Inserted
shows the number of rows inserted into InnoDB tables. -
Rows read
Rows Read
denotes the number of rows read from InnoDB tables. -
Rows updated
Rows Updated
depicts the number of rows updated in InnoDB tables.
Replication metrics
-
Slave IO state
Slave IO State
shows the state of what a thread is doing, such as trying to connect to the source, waiting for events from the source, reconnecting to the source, and so on. -
Slave IO running
Slave IO Running
displays if the I/O thread has started and connected successfully to the source. -
Slave SQL running
Slave Sql Running
shows if the SQL thread has started.. -
Slave running
Slave Running
denotes if a slave is running or not. -
Connect retry
Connect Retry
provides the time between connect retires, in seconds. -
Last IO error number
Last IO Errno
the error number of the most recent error that caused the I/O thread to stop. -
Last SQL error number
Last Sql Errno
provides the error number of the most recent error that caused the SQL thread to stop. -
Master host
Master Host
is the source host that the replica is connected to. -
Master retry count
Master Retry Count
provides the number of times the replica can attempt to reconnect to the source in the event of a lost connection. -
Master server ID
Master Server ID
is the server ID value from the source. -
Master user
Master User
is the user name of the account used to connect to the source. -
Relay log space
Relay Log Space
is the total combined size of all existing relay log files in bytes. -
Seconds behind master
Seconds Behind Master
is the difference in seconds between the slave’s clock time and the timestamp of the query, when it was recorded in the master’s binary log. -
Skip counter
Skip Counter
denotes the number of events from the source that a replica server should skip.
Prerequisites
- Our Linux/Windows server monitoring agent should be installed in the network or on the specific host where the MySQL instance is running.
- While adding a plugin, the plugin name and its folder name should be identical.
- The MySQL plugin will automatically verify, download, and install the 'pymysql' module required for monitoring your MySQL servers. This can be viewed in the mysql_monitoring.py file. In case the 'pymysql' module is not installed, follow the instructions given below to manually install it.
For Linux:
- Execute the following command in your server to install pymysql
pip install pymysql
Installing pip:
-
Use "pip" to install pymysql module
Note: pip is a package management system that is used to install and manage software packages written in Python.
-
For CentOS, Fedora, RHEL:
yum install python-develyum install python-pip (or)easy_install pip
-
For Debian, Ubuntu:
apt-get -y install python-pip
For Windows:
- Open cmd as administrator.
- Go to the Python path.
cd [python path]
- Execute the following command:
python -m pip install PyMySQL
If pymysql is already installed in your server, follow the steps given in this article to install the MySQL plugin in Windows servers.
Roles and Permissions
SELECT VERSION()
, SHOW GLOBAL STATUS
, and SHOW VARIABLES
are the queries used in the MySQL plugin.
-
To create a MySQL user:
CREATE USER username@hostname IDENTIFIED BY 'password';
-
Select on queries permission is required to execute the queries mentioned above.
GRANT SELECT ON mysql.* TO username@hostname IDENTIFIED BY password;
CREATE USER site24x7@localhost IDENTIFIED BY 'site24x7';
GRANT SELECT ON mysql.* TO site24x7@localhost IDENTIFIED BY 'site24x7';
FLUSH PRIVILEGES;
Plugin Installation
Linux
- Download and install the latest version of the Site24x7 Linux agent in the server where you plan to run the plugin. If it is installed successfully, you will see a Linux server monitor in the Site24x7 Control Panel. This confirms that the agent is able to communicate with our data center.
-
Download the mysql_monitoring.py and mysql_monitoring.cfg file from our GitHub repository.
wget https://raw.githubusercontent.com/site24x7/plugins/master/mysql_monitoring/mysql_monitoring.pywget https://raw.githubusercontent.com/site24x7/plugins/master/mysql_monitoring/mysql_monitoring.cfg
-
Add the configuration in "mysql_monitoring.cfg" as below
[MySQL]host ="hostname"port="port"username="username"password ="password"logs_enabled ="logenabled"log_type_name ="logtypename"log_file_path ="logfilepath"
- Create a folder with the name 'mysql_monitoring', under the Site24x7 Linux agent plugin directory '/opt/site24x7/monagent/plugins/' and place the 'mysql_monitoring.py' and 'mysql_monitoring.cfg' under '/opt/site24x7/monagent/plugins/mysql_monitoring/'
Windows
- Download and install the latest version of the Site24x7 Windows agent in the network where you plan to run the plugin. If it is installed successfully, you will see a Windows server monitor in the Site24x7 Control Panel. This confirms that the agent is able to communicate with our data center.
- Download the mysql_monitoring.py and mysql_monitoring.cfg file from our GitHub repository.
- Follow the steps given in this article to know how to run the python script in Windows server.
- Create a folder with the name 'mysql_monitoring', under the Site24x7 Windows agent plugin directory - C:\Program Files (x86)\Site24x7\WinAgent\monitoring\Plugins\ and place the 'mysql_monitoring.py' file under 'C:\Program Files (x86)\Site24x7\WinAgent\monitoring\Plugins\mysql_monitoring\'
Automatic AppLogs integration
-
To analyze the metrics with MySQL logs and find the exact root cause of issues, you can perform configuration changes in the
mysql_configuration.cfg
file.Example:logs_enabled ="true"log_type_name="MySQL Error"log_file_path="/var/mysql/log/error.txt"
Manually execute the plugin script using the following command and verify its output:
python mysql_monitoring.py --host="host_name" --port="port_number" --username="username" --password="password"
View Data in the Site24x7 Web Client
- Log in to Site24x7 and go to Server > Plugins > click on the plugin monitor.
- You will be able to view the performance charts on the various metrics for your MySQL server.
Plugin Contribution
Feel free to contribute to our existing plugin and come up with suggestions or feedback on our Community.
Other Plugin Integrations
- 100+ Plugin Integrations
- Nagios Integration
- RabbitMQ Monitoring
- MongoDB Monitoring
- Samba Monitoring
- Create custom plugins: Linux and Windows