Monitor your MySQL instances remotely, collect key KPIs, and slow query details.
Remotely monitor MySQL databases where you can't install OneAgent.
Designate an ActiveGate group or groups that will remotely connect to your MySQL Database server to pull data. All ActiveGates in each group must connect to your MySQL database.
Create a dedicated database user in your database instance with necessary permissions. Dynatrace uses this user to run monitoring queries against your MySQL database.
Configure a user with permissions
Create a user that is identified by a native password, and customize the username and password.
CREATE USER 'dynatrace'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
Give the user the following permissions:
GRANT SELECT ON performance_schema.* TO 'dynatrace'@'%';
GRANT PROCESS ON *.* TO 'dynatrace'@'%';
GRANT SHOW DATABASES ON *.* TO 'dynatrace'@'%';
GRANT SELECT ON mysql.slow_log TO 'dynatrace'@'%';
GRANT SELECT ON sys.x$memory_global_by_current_bytes TO 'dynatrace'@'%';
Due to a MySQL limitation, to calculate database sizes, you need to grant SELECT permissions on the individual databases from which you want to collect the size.
MySQL version 8.0 or higher is required.
.
Databases. This opens the Add DB Instance wizard.Select a hosting type from the options. This choice determines which script generates the necessary database objects later in the process.
Set up the connection to your database instance. Provide the required credentials directly in the wizard or use secure alternatives:
dynatrace monitoring user you have created directly or use secure alternatives.
Collect infrastructure metrics
To enable CPU metrics collection, run this query in the MySQL instance:
SET GLOBAL innodb_monitor_enable='cpu%';
Collect memory metrics
To enable memory metrics collection, run this query in the MySQL instance:
SET GLOBAL innodb_monitor_enable='memory%';
Collect table statistics
To enable table statistics collection, run this query in the MySQL instance:
UPDATE performance_schema.setup_instrumentsSET ENABLED = 'YES', TIMED = 'YES'WHERE NAME LIKE 'wait/io/table/%';
To enable index statistics collection, run this query in the MySQL instance:
GRANT SELECT ON mysql.innodb_index_stats TO 'dynatrace'@'%';
Collect waits metrics
To enable waits instrumentation:
UPDATE performance_schema.setup_instrumentsSET ENABLED = 'YES', TIMED = 'YES'WHERE NAME LIKE 'wait/%';
To enable waits consumers:
UPDATE performance_schema.setup_consumersSET ENABLED='YES'WHERE NAME IN ('events_waits_current','events_waits_history','events_waits_history_long');
Collect top slow queries
The following steps apply to the slow_queries feature set, which retrieves data from mysql.slow_log.
This approach will be deprecated in a future release.
Enable slow queries logging to a table by executing:
SET GLOBAL log_output = 'TABLE';SET GLOBAL slow_query_log = 'ON';
The default slow query threshold is 10 seconds.
Optionally, choose the threshold of what is a "slow query" by executing:
SET GLOBAL long_query_time = 2;
This sets the slow queries threshold to 2 seconds.
The following steps apply to the top_queries feature set, which retrieves data from performance_schema.events_statements_summary_by_digest.
UPDATE performance_schema.setup_instrumentsSET ENABLED = 'YES', TIMED = 'YES'WHERE NAME LIKE 'statement/%';
UPDATE performance_schema.setup_consumersSET ENABLED = 'YES'WHERE NAME IN ('events_statements_history', 'events_statements_summary_by_digest');
The recommended way to enable this on RDS is to create a custom parameter group. In the group, set performance_schema to 1 and enable the required consumer settings. This configuration persists across restarts and instance changes.
For more details, see Turn on the Performance Schema for Amazon RDS for MariaDB or MySQL.
Fetch execution plans
To fetch execution plans:
dynatrace user:CREATE SCHEMA IF NOT EXISTS dynatrace;
DELIMITER $$CREATE PROCEDURE dynatrace.dynatrace_execution_plan(IN query TEXT)SQL SECURITY DEFINERBEGINSET @explain := CONCAT('EXPLAIN FORMAT=JSON ', query);PREPARE stmt FROM @explain;EXECUTE stmt;DEALLOCATE PREPARE stmt;END $$DELIMITER ;
dynatrace user:GRANT EXECUTE ON PROCEDURE dynatrace.dynatrace_execution_plan TO 'dynatrace'@'%';
When activating your extension using a monitoring configuration, you can limit monitoring to one of the feature sets. To work properly, the extension has to collect at least one metric after the activation.
In highly segmented networks, feature sets can reflect the segments of your environment. Then, when you create a monitoring configuration, you can select a feature set and a corresponding ActiveGate group that can connect to this particular segment.
All metrics that aren't categorized into any feature set are considered to be the default and are always reported.
A metric inherits the feature set of a subgroup, which in turn inherits the feature set of a group. Also, the feature set defined on the metric level overrides the feature set defined on the subgroup level, which in turn overrides the feature set defined on the group level.
| Metric name | Metric key | Description |
|---|
| Metric name | Metric key | Description |
|---|
| Metric name | Metric key | Description |
|---|---|---|
| CPU User | mysql.infrastructure.cpu.user | The percentage of CPU time spent in user mode. |
| CPU System | mysql.infrastructure.cpu.system | The percentage of CPU time spent in system mode. |
| Memory | mysql.infrastructure.memory | The amount of memory used per each code area. |
| Metric name | Metric key | Description |
|---|---|---|
| Queries | mysql.global_status.queries.count | The total number of queries executed by the server. This includes statements executed within stored procedures, unlike the Questions variable. |
| Slow Queries | mysql.global_status.slow_queries.count | The number of queries that have taken more than long_query_time seconds. This counter increments regardless of whether the slow query log is enabled. For information about that log, see Section 5.4.5, The Slow Query Log. |
| Table Locks Waited | mysql.global_status.table_locks_waited.count | The number of times that a request for a table lock could not be granted immediately and a wait was needed. If this is high and you have performance problems, you should first optimize your queries, and then either split your table or tables or use replication. |
| Table Locks Immediate | mysql.global_status.table_locks_immediate.count | The number of times that a request for a table lock could be granted immediately. |
| Current Connections | mysql.global_status.current_connections | The number of currently open connections. |
| Threads Running | mysql.global_status.threads_running | The number of threads that are not sleeping. |
| Innodb Buffer Pool Pages Data | mysql.global_status.innodb_buffer_pool_pages_data | The number of pages in the InnoDB buffer pool containing data. The number includes both dirty and clean pages. When using compressed tables, the reported Innodb_buffer_pool_pages_data value may be larger than Innodb_buffer_pool_pages_total |
| Innodb Buffer Pool Pages Dirty | mysql.global_status.innodb_buffer_pool_pages_dirty | The current number of dirty pages in the InnoDB buffer pool. |
| Innodb Buffer Pool Pages Free | mysql.global_status.innodb_buffer_pool_pages_free | The number of free pages in the InnoDB buffer pool. |
| Innodb Buffer Pool Pages Total | mysql.global_status.innodb_buffer_pool_pages_total | The total size of the InnoDB buffer pool, in pages. When using compressed tables, the reported Innodb_buffer_pool_pages_data value may be larger than Innodb_buffer_pool_pages_total |
| Innodb Data Reads | mysql.global_status.innodb_data_reads.count | The total number of data reads (OS file reads). |
| Innodb Data Writes | mysql.global_status.innodb_data_writes.count | The total number of data writes. |
| Innodb Data Read | mysql.global_status.innodb_data_read.count | The total amount of data read from files. |
| Innodb Data Written | mysql.global_status.innodb_data_written.count | The total amount of data written. |
| Innodb Buffer Pool Reads | mysql.global_status.innodb_buffer_pool_reads | The number of logical reads that InnoDB could not satisfy from the buffer pool, and had to read directly from disk. |
| Innodb Buffer Pool Read Requests | mysql.global_status.innodb_buffer_pool_read_requests | The number of logical read requests. |
| Availability | mysql.global_status.availability | Whether or not a connection can be made to the database |
| Status | mysql.global_status.status | A status of AVAILABLE is returned if we can query the database |
| Uptime | mysql.global_status.uptime | The time in seconds that the MySQL server has been running since it was started. |
| Metric name | Metric key | Description |
|---|---|---|
| Table Data Size | mysql.tables.data_size | For MyISAM, DATA_LENGTH is the length of the data file, in bytes. For InnoDB, DATA_LENGTH is the approximate amount of space allocated for the clustered index, in bytes. Specifically, it is the clustered index size, in pages, multiplied by the InnoDB page size. |
| Table Index Size | mysql.tables.index_size | For MyISAM, INDEX_LENGTH is the length of the index file, in bytes. For InnoDB, INDEX_LENGTH is the approximate amount of space allocated for non-clustered indexes, in bytes. Specifically, it is the sum of non-clustered index sizes, in pages, multiplied by the InnoDB page size. |
| Table Total Size | mysql.tables.total_size | The total size of the table, in bytes. This is the sum of data and index size. |
| Table Estimated Rows | mysql.tables.estimated_rows | The number of rows in the table. For InnoDB, this is an approximation. For MyISAM, this is an exact count. |
| Table Free Space | mysql.tables.free_space | The number of allocated but unused bytes. |
| Table IO Events | mysql.tables.io_events.count | Number of summarized events and the sum of the x_READ and x_WRITE columns. |
| Table IO Wait Time | mysql.tables.io_wait_time.count | Total wait time of the summarized events that are timed. |
| Table IO Read | mysql.tables.io_read.count | Number of all read operations, and the sum of the equivalent x_FETCH columns. |
| Table IO Read Wait Time | mysql.tables.io_read_wait_time.count | Total wait time of all read operations that are timed. |
| Table IO Write | mysql.tables.io_write.count | Number of all write operations, and the sum of the equivalent x_INSERT, x_UPDATE, and x_DELETE columns. |
| Table IO Write Wait Time | mysql.tables.io_write_wait_time.count | Total wait time of all write operations that are timed. |
| Table IO Fetch | mysql.tables.io_fetch.count | Number of all fetch operations. |
| Table IO Fetch Wait Time | mysql.tables.io_fetch_wait_time.count | Total wait time of all fetch operations that are timed. |
| Table IO Insert | mysql.tables.io_insert.count | Number of all insert operations. |
| Table IO Insert Wait Time | mysql.tables.io_insert_wait_time.count | Total wait time of all insert operations that are timed. |
| Table IO Update | mysql.tables.io_update.count | Number of all update operations. |
| Table IO Update Wait Time | mysql.tables.io_update_wait_time.count | Total wait time of all update operations that are timed. |
| Table IO Delete | mysql.tables.io_delete.count | Number of all delete operations. |
| Table IO Delete Wait Time | mysql.tables.io_delete_wait_time.count | Total wait time of all delete operations that are timed. |
| Index Size | mysql.indexes.index_size | The calculated size of the index in bytes. Derived by multiplying the number of 16KB pages by 16384. |
| Index Scans | mysql.indexes.scans.count | The total number of times this specific index was accessed or scanned by queries. |
| Index Rows Read | mysql.indexes.rows_read.count | The number of read operations on the index structure itself. High values indicate heavy index traversal. |
| Index Rows Fetched | mysql.indexes.rows_fetched.count | The number of actual table rows retrieved using this index. |
| Index Rows Inserted | mysql.indexes.rows_inserted.count | The number of rows inserted using this index. |
| Index Rows Updated | mysql.indexes.rows_updated.count | The number of rows updated using this index. |
| Index Rows Deleted | mysql.indexes.rows_deleted.count | The number of rows deleted using this index. |
| Metric name | Metric key | Description |
|---|---|---|
| Database Size | mysql.databases.size | The size of the Database. |
| Database Queries | mysql.databases.queries.count | Number of queries executed for the database. |
| Database Rows Read | mysql.databases.rows_read.count | Number of rows examined by queries executed for the database. |
| Database Rows Written | mysql.databases.rows_written.count | Number of rows affected by queries executed for the database. |
| Metric name | Metric key | Description |
|---|---|---|
| Commits | mysql.statements.commit.count | The number of COMMIT statements executed by this server |
| Deletes | mysql.statements.delete.count | The number of DELETE statements executed by this server |
| Multi-Table Deletes | mysql.statements.delete_multi.count | The number of multi-table DELETE statements executed by this server |
| Inserts | mysql.statements.insert.count | The number of INSERT statements executed by this server |
| Insert Selects | mysql.statements.insert_select.count | The number of INSERT ... SELECT statements executed by this server |
| Selects | mysql.statements.select.count | The number of SELECT statements executed by this server |
| Updates | mysql.statements.update.count | The number of UPDATE statements executed by this server |
| Executes | mysql.statements.execute.count | The number of EXECUTE statements executed by this server |
| Multi-Table Updates | mysql.statements.update_multi.count | The number of multi-table UPDATE statements executed by this server |
| Bytes Sent | mysql.statements.bytes_sent.count | The number of bytes sent to all clients |
| Bytes Received | mysql.statements.bytes_received.count | The number of bytes received from all clients |
| Rollbacks | mysql.statements.rollback.count | The number of ROLLBACK statements executed by this server |
| Replace Selects | mysql.statements.replace_select.count | The number of REPLACE ... SELECT statements executed by this server |
| Metric name | Metric key | Description |
|---|
| Metric name | Metric key | Description |
|---|---|---|
| Waits IO | mysql.waits.waits_io.count | The number of times that the server has waited for an I/O operation to complete. |
| Waits IO Time | mysql.waits.waits_io_time.count | The total time the server has waited for I/O operations to complete. |
| Waits Sync | mysql.waits.waits_sync.count | The number of times that the server has waited for a synchronization operation to complete. |
| Waits Sync Time | mysql.waits.waits_sync_time.count | The total time the server has waited for synchronization operations to complete. |
Data collection must be allowed for the MySQL instance to gather wait metrics. For more details, see Performance Schema Wait Event Tables.
This extension was tested only with MySQL instances. MariaDB is not officially supported.
This error means the username is not identified by a native password. For more details, see the Activation and setup section.
Ensure that data collection is enabled for your instance.
SET GLOBAL innodb_monitor_enable='cpu%';.To test that you can query the data, run:
SELECT * FROM information_schema.INNODB_METRICS WHERE name IN ('cpu_utime_pct', 'cpu_stime_pct');
And:
SELECT SUBSTRING_INDEX(event_name,'/',2) AS code_area,SUM(current_alloc) AS current_allocFROM sys.x$memory_global_by_current_bytesGROUP BY SUBSTRING_INDEX(event_name,'/',2)ORDER BY SUM(current_alloc) DESC;
See the Collect top slow queries section in Add monitoring configurations.
On Managed tenants, log records can be retrieved by filtering logs using 2 attributes:
dt.extension.name: com.dynatrace.extension.mysql.event.group: top_queries (versions 2.1.6+) or event.group: query_performance (versions <2.1.6).