Skip to main content

Mysql Receiver

Status Available in: contrib Maintainers: @antonblock, @ishleenk17 Source: opentelemetry-collector-contrib

Supported Telemetry

Logs Metrics

Overview

This receiver queries MySQL’s global status and InnoDB tables. Some metrics will not appear if their corresponding feature is inactive.
There are also optional metrics that you must specify in your configuration to collect, listed in documentation.md

Prerequisites

This receiver supports MySQL version 8.0 and MariaDB 10.11. Collecting most metrics requires the ability to execute SHOW GLOBAL STATUS. Collecting query samples requires the performance_schema to be enabled:
GRANT SELECT ON performance_schema.* TO <your-user>@'%';

Configuration

The following settings are optional:
  • endpoint: (default = localhost:3306)
  • tls: Defines the TLS configuration to use. If tls is not set, the default is to disable TLS connections.
    • insecure: (default = false) Set this to true to disable TLS connections.
    • insecure_skip_verify: (default = false) Set this to true to enable TLS but not verify the certificate.
    • server_name_override: This sets the ServerName in the TLSConfig.
  • username: (default = root)
  • password: The password to the username.
  • allow_native_passwords: (default = true)
  • database: The database name. If not specified, metrics will be collected for all databases.
  • collection_interval (default = 10s): This receiver collects metrics on an interval. This value must be a string readable by Golang’s time.ParseDuration. Valid time units are ns, us (or Β΅s), ms, s, m, h.
  • initial_delay (default = 1s): defines how long this receiver waits before starting.
  • transport: (default = tcp): Defines the network to use for connecting to the server.
  • statement_events: Additional configuration for query to build mysql.statement_events.count and mysql.statement_events.wait.time metrics:
    • digest_text_limit - maximum length of digest_text. Longer text will be truncated (default=120)
    • time_limit - maximum time from since the statements have been observed last time (default=24h)
    • limit - limit of records, which is maximum number of generated metrics (default=250)
  • query_sample_collection: Additional configuration for query sample collection(db.server.query_sample event):
    • max_rows_per_query - maximum number of rows to collect per scrape (default=100)
  • top_query_collection: Additional configuration for top queries collection (db.server.top_query event):
    • lookback_time (optional, example = 60, default = 2 * collection_interval): The time window (in seconds) in which to query for top queries.
      • Queries that finished execution outside the lookback window are not included in the collection. Increasing the lookback window will be useful for capturing long-running queries.
    • max_query_sample_count (optional, example = 5000, default = 1000): The maximum number of records to fetch in a single run.
    • top_query_count: (optional, example = 100, default = 200): The maximum number of active queries to report (to the next consumer) in a single run.
    • collection_interval: (optional, default = 60s): The interval at which top queries should be emitted by this receiver.
      • This value can only guarantee that the top queries are collected at most once in this interval.
        • For instance, you have global collection_interval set to 10s and top_query_collection.collection_interval set to 60s.
          • In this case, the default receiver scraper will still run every 10 seconds.
          • However, the top queries collection will only run after 60 seconds have passed since the last collection.
        • For instance, you have global collection_interval set to 10s and top_query_collection.collection_interval set to 5s.
          • In this case, top_query_collection.collection_interval will have no impact on the collection frequency, which will run every 10s.
    • query_plan_cache_size: (optional, default = 1000). The query plan cache size. Once we got query plan results from explain queries, we will store them in the cache. This defines the cache’s size for query plan.
    • query_plan_cache_ttl: (optional, example = 1m, default = 1h). How long until a query plan expires in the cache. The receiver will run an explain query to MySQL to get the query plan after it expires.

Example Configuration

receivers:
  mysql:
    endpoint: localhost:3306
    username: otel
    password: ${env:MYSQL_PASSWORD}
    database: otel
    collection_interval: 10s
    initial_delay: 1s
    statement_events:
      digest_text_limit: 120
      time_limit: 24h
      limit: 250
The full list of settings exposed for this receiver are documented in config.go with detailed sample configurations in testdata/config.yaml.

Metrics

Details about the metrics produced by this receiver can be found in metadata.yaml

Logs

Details about the logs produced by this receiver can be found in documentation.md Trace propagation: Query sample log records carry a TraceID and SpanID only when a MySQL session sets the @traceparent user variable (W3C TraceContext format, lowercase name). The collector extracts the TraceID and SpanID from that value and stamps the application’s trace context onto the corresponding log record. Log records without a @traceparent will have empty TraceID and SpanID fields. This allows application transactions to be correlated with query samples collected by this receiver.
Note: MySQL stores user variable names in lowercase in performance_schema.user_variables_by_thread regardless of how the client spelled them. The JOIN condition VARIABLE_NAME = 'traceparent' therefore matches any case variation the client used (e.g. SET @TraceParent = '...' works identically to SET @traceparent = '...').

MySQL Requirements to enable log collection

ParameterValueDescription
performance_schemaEnabled (Required)Enable performance schema
max_digest_length4096 (Recommended)Maximum length of digest text
performance_schema_max_digest_length4096 (Recommended)Maximum length of digest text on performance schema
performance_schema_max_sql_text_length4096 (Recommended)Maximum length of sql text

Metrics

Metric NameDescriptionUnitTypeAttributes
βœ… mysql.buffer_pool.data_pagesThe number of data pages in the InnoDB buffer pool.1UpDownCounterbuffer_pool_data
βœ… mysql.buffer_pool.limitThe configured size of the InnoDB buffer pool.ByUpDownCounter
βœ… mysql.buffer_pool.operationsThe number of operations on the InnoDB buffer pool.1Counterbuffer_pool_operations
βœ… mysql.buffer_pool.page_flushesThe number of requests to flush pages from the InnoDB buffer pool.1Counter
βœ… mysql.buffer_pool.pagesThe number of pages in the InnoDB buffer pool.1UpDownCounterbuffer_pool_pages
βœ… mysql.buffer_pool.usageThe number of bytes in the InnoDB buffer pool.ByUpDownCounterbuffer_pool_data
❌ mysql.client.network.ioThe number of transmitted bytes between server and clients.ByCounterdirection
❌ mysql.commandsThe number of times each type of command has been executed.1Countercommand
❌ mysql.connection.countThe number of connection attempts (successful or not) to the MySQL server.1Counter
❌ mysql.connection.errorsErrors that occur during the client connection process.1Counterconnection_error
βœ… mysql.double_writesThe number of writes to the InnoDB doublewrite buffer.1Counterdouble_writes
βœ… mysql.handlersThe number of requests to various MySQL handlers.1Counterhandler
βœ… mysql.index.io.wait.countThe total count of I/O wait events for an index.1Counterio_waits_operations, table_name, schema, index_name
βœ… mysql.index.io.wait.timeThe total time of I/O wait events for an index.nsCounterio_waits_operations, table_name, schema, index_name
❌ mysql.joinsThe number of joins that perform table scans.1Counterjoin_kind
βœ… mysql.locksThe number of MySQL locks.1Counterlocks
βœ… mysql.log_operationsThe number of InnoDB log operations.1Counterlog_operations
❌ mysql.max_used_connectionsMaximum number of connections used simultaneously since the server started.1UpDownCounter
βœ… mysql.mysqlx_connectionsThe number of mysqlx connections.1Counterconnection_status
❌ mysql.mysqlx_worker_threadsThe number of worker threads available.1UpDownCountermysqlx_threads
βœ… mysql.opened_resourcesThe number of opened resources.1Counteropened_resources
βœ… mysql.operationsThe number of InnoDB operations.1Counteroperations
βœ… mysql.page_operationsThe number of InnoDB page operations.1Counterpage_operations
❌ mysql.page_sizeInnoDB page size.ByUpDownCounter
βœ… mysql.prepared_statementsThe number of times each type of prepared statement command has been issued.1Counterprepared_statements_command
❌ mysql.query.client.countThe number of statements executed by the server. This includes only statements sent to the server by clients.1Counter
❌ mysql.query.countThe number of statements executed by the server.1Counter
❌ mysql.query.slow.countThe number of slow queries.1Counter
❌ mysql.replica.sql_delayThe number of seconds that the replica must lag the source.sUpDownCounter
❌ mysql.replica.time_behind_sourceThis field is an indication of how β€œlate” the replica is.sUpDownCounter
βœ… mysql.row_locksThe number of InnoDB row locks.1Counterrow_locks
βœ… mysql.row_operationsThe number of InnoDB row operations.1Counterrow_operations
βœ… mysql.sortsThe number of MySQL sorts.1Countersorts
❌ mysql.statement_event.countSummary of current and recent statement events.1UpDownCounterschema, digest, digest_text, event_state
❌ mysql.statement_event.wait.timeThe total wait time of the summarized timed events.nsUpDownCounterschema, digest, digest_text
❌ mysql.table.average_row_lengthThe average row length in bytes for a given table.ByUpDownCountertable_name, schema
βœ… mysql.table.io.wait.countThe total count of I/O wait events for a table.1Counterio_waits_operations, table_name, schema
βœ… mysql.table.io.wait.timeThe total time of I/O wait events for a table.nsCounterio_waits_operations, table_name, schema
❌ mysql.table.lock_wait.read.countThe total table lock wait read events.1UpDownCounterschema, table_name, read_lock_type
❌ mysql.table.lock_wait.read.timeThe total table lock wait read events times.nsUpDownCounterschema, table_name, read_lock_type
❌ mysql.table.lock_wait.write.countThe total table lock wait write events.1UpDownCounterschema, table_name, write_lock_type
❌ mysql.table.lock_wait.write.timeThe total table lock wait write events times.nsUpDownCounterschema, table_name, write_lock_type
❌ mysql.table.rowsThe number of rows for a given table.1UpDownCountertable_name, schema
❌ mysql.table.sizeThe table size in bytes for a given table.ByUpDownCountertable_name, schema, table_size_type
❌ mysql.table_open_cacheThe number of hits, misses or overflows for open tables cache lookups.1Countercache_status
βœ… mysql.threadsThe state of MySQL threads.1UpDownCounterthreads
βœ… mysql.tmp_resourcesThe number of created temporary resources.1Countertmp_resource
βœ… mysql.uptimeThe number of seconds that the server has been up.sCounter

Attributes

Attribute NameDescriptionTypeValues
statusThe status of buffer pool data.stringdirty, clean
operationThe buffer pool operations types.stringread_ahead_rnd, read_ahead, read_ahead_evicted, read_requests, reads, wait_free, write_requests
kindThe buffer pool pages types.stringdata, free, misc, total
statusThe status of cache access.stringhit, miss, overflow
client.addressHostname or address of the client.string
client.portTCP port used by the client.int
commandThe command types.stringdelete, delete_multi, insert, select, update, update_multi
errorThe connection error type.stringaccept, internal, max_connections, peer_address, select, tcpwrap, aborted, aborted_clients, locked
statusThe connection status.stringaccepted, closed, rejected
db.namespaceThe default database for the thread, or empty if none has been selected (originally processlist_db).string
db.query.textThe SQL statement text for the event.string
db.system.nameThe name of the database system.stringmysql
digestDigest.string
digest_textText before digestion.string
kindThe name of the transmission direction.stringreceived, sent
kindThe doublewrite types.stringpages_written, writes
kindPossible event states.stringerrors, warnings, rows_affected, rows_sent, rows_examined, created_tmp_disk_tables, created_tmp_tables, sort_merge_passes, sort_rows, no_index_used
kindThe handler types.stringcommit, delete, discover, external_lock, mrr_init, prepare, read_first, read_key, read_last, read_next, read_prev, read_rnd, read_rnd_next, rollback, savepoint, savepoint_rollback, update, write
indexThe name of the index.string
operationThe io_waits operation type.stringdelete, fetch, insert, update
kindThe kind of join.stringfull, full_range, range, range_check, scan
kindThe table locks type.stringimmediate, waited
operationThe log operation types. β€˜fsyncs’ aren’t available in MariaDB 10.8 or later.stringwaits, write_requests, writes, fsyncs
mysql.event_idThe thread associated with the event and the thread current event number when the event starts.int
mysql.events_statements_current.digestThe statement digest SHA-256 value as a string of 64 hexadecimal characters, or empty if the statements_digest consumer is no.string
mysql.events_statements_summary_by_digest.count_starThe number of times the statement was executed, report in delta value.int
mysql.events_statements_summary_by_digest.digestThe statement digest SHA-256 value as a string of 64 hexadecimal characters, or empty if the statements_digest consumer is no.string
mysql.events_statements_summary_by_digest.sum_timer_waitThe total time spent executing the statement, report in delta seconds.double
mysql.events_waits_current.timer_waitTiming information for the event, indicating elapsed time the event waited in seconds.double
mysql.query_planThe query plan for the statement, if available.string
mysql.query_plan.hashThis attribute is set to the same value as mysql.events_statements_summary_by_digest.digest (query digest) by design.string
mysql.session.idThe unique identifier for the session associated with the event.int
mysql.session.statusSimplified session status, either β€˜waiting’, β€˜running’ or β€˜other’.string
mysql.threads.processlist_commandThe type of command the thread is executing on behalf of the client for foreground threads, or Sleep if the session is idle.string
mysql.threads.processlist_stateAn action, event, or state that indicates what the thread is doing.string
mysql.threads.thread_idThe unique identifier for the thread executing the statement.int
mysql.wait_typeThe name of the instrument that produced the event.string
kindThe worker thread count kind.stringavailable, active
network.peer.addressIP address of the peer client.string
network.peer.portTCP port used by the peer client.int
kindThe kind of the resource.stringfile, table_definition, table
operationThe operation types.stringfsyncs, reads, writes
operationThe page operation types.stringcreated, read, written
commandThe prepare statement command types.stringexecute, close, fetch, prepare, reset, send_long_data
kindRead operation types.stringnormal, with_shared_locks, high_priority, no_insert, external
kindThe row lock type.stringwaits, time
operationThe row operation type.stringdeleted, inserted, read, updated
schemaThe schema of the object.string
kindThe sort count type.stringmerge_passes, range, rows, scan
tableTable name for event or process.string
kindThe table size types.stringdata, index
kindThe thread count type.stringcached, connected, created, running
resourceThe kind of temporary resources.stringdisk_tables, files, tables
user.nameThe user associated with a foreground thread, empty for a background thread (originally processlist_user).string
kindWrite operation types.stringallow_write, concurrent_insert, low_priority, normal, external

Resource Attributes

Attribute NameDescriptionTypeEnabled
mysql.instance.endpointEndpoint of the MySQL instance.stringβœ…

Configuration

Example Configuration

mysql:
  endpoint: localhost:3306
  username: otel
  password: ${env:MYSQL_PASSWORD}
  database: otel
  collection_interval: 10s
mysql/default_tls:
  endpoint: localhost:3306
  username: otel
  password: ${env:MYSQL_PASSWORD}
  database: otel
  collection_interval: 10s
  tls: # specified, but use default values
    server_name_override: localhost

Last generated: 2026-04-13