Menu
Grafana Cloud

MySQL integration for Grafana Cloud

MySQL is a managed, open source relational database that is a widely used for both small and large applications.

This integration includes 8 useful alerts and 2 pre-built dashboards to help monitor and visualize MySQL metrics and logs.

Before you begin

A running MySQL instance, user and password are required for the integration.

Supported versions:

  • MySQL >= 5.6
  • MariaDB >= 10.2

We recommend that you configure a separate user for the Agent, and give it only the strictly mandatory security privileges necessary for monitoring your node, as per the official documentation.

Install MySQL integration for Grafana Cloud

  1. In your Grafana Cloud stack, click Connections in the left-hand menu.
  2. Find MySQL and click its tile to open the integration.
  3. Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send MySQL metrics and logs to your Grafana Cloud instance.
  4. Click Install to add this integration’s pre-built dashboards and alerts to your Grafana Cloud instance, and you can start monitoring your MySQL setup.

Post-install configuration for the MySQL integration

This integration is configured to work with the mysqld_exporter, which is embedded in Grafana Agent.

Enable the integration by manually adding the provided snippets to your agent configuration file.

This integration supports metrics and logs from MySQL. In order to see those signals correlated on your dashboard, as a single pane of glass, ensure the following:

  • job and instance labels must match for mysql_integration(metrics) and logs in the Agent configuration file.
  • job label must be set to integrations/mysql (already configured in the snippets).
  • instance label must be set to a value that uniquely identifies your MySQL Node. Replace it manually, according to your environment. Note that if you use localhost for multiple nodes, the dashboards will not be able to filter correctly by instance.

Please note that the value under data_source_name snippet parameter must follow the URI patterns defined in go-sql-driver README, which is [username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN].

If you set the MYSQL_ALLOW_EMPTY_PASSWORD flag on your MySQL Node configuration, you can omit the password in the URI.

For a full description of configuration options see how to configure the mysqld_exporter_config block in the agent documentation.

Configuration snippets for Grafana Agent

Below integrations, insert the following lines and change the URLs according to your environment:

yaml
  mysqld_exporter:
    enabled: true
    instance: '<your-instance-name>' # must match instance used in logs
    data_source_name: 'root:password@(localhost:3306)/' # replace with your connection string
    relabel_configs:
      - target_label: job
        replacement: 'integrations/mysql' # must match job used in logs

Below logs.configs.scrape_configs, insert the following lines according to your environment.

yaml
    - job_name: integrations/mysql 
      static_configs:
        - labels:
            instance: '<your-instance-name>' # must match instance used in mysqld_exporter
            job: integrations/mysql # must match job used in mysqld_exporter
            __path__: /var/log/mysql/*.log
      pipeline_stages:
        - regex:
              expression: '(?P<timestamp>.+) (?P<thread>[\d]+) \[(?P<label>.+?)\]( \[(?P<err_code>.+?)\] \[(?P<subsystem>.+?)\])? (?P<msg>.+)'
        - labels:
            level: label
            err_code:
            subsystem:
        - drop:
            expression: "^ *$"
            drop_counter_reason: "drop empty lines"

Full example configuration for Grafana Agent

Refer to the following Grafana Agent configuration for a complete example that contains all the snippets used for the MySQL integration. This example also includes metrics that are sent to monitor your Grafana Agent instance.

yaml
integrations:
  prometheus_remote_write:
  - basic_auth:
      password: <your_prom_pass>
      username: <your_prom_user>
    url: <your_prom_url>
  agent:
    enabled: true
    relabel_configs:
    - action: replace
      source_labels:
      - agent_hostname
      target_label: instance
    - action: replace
      target_label: job
      replacement: "integrations/agent-check"
    metric_relabel_configs:
    - action: keep
      regex: (prometheus_target_sync_length_seconds_sum|prometheus_target_scrapes_.*|prometheus_target_interval.*|prometheus_sd_discovered_targets|agent_build.*|agent_wal_samples_appended_total|process_start_time_seconds)
      source_labels:
      - __name__
  # Add here any snippet that belongs to the `integrations` section.
  # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
  mysqld_exporter:
    enabled: true
    instance: '<your-instance-name>' # must match instance used in logs
    data_source_name: 'root:password@(localhost:3306)/' # replace with your connection string
    relabel_configs:
      - target_label: job
        replacement: 'integrations/mysql' # must match job used in logs
logs:
  configs:
  - clients:
    - basic_auth:
        password: <your_loki_pass>
        username: <your_loki_user>
      url: <your_loki_url>
    name: integrations
    positions:
      filename: /tmp/positions.yaml
    scrape_configs:
      # Add here any snippet that belongs to the `logs.configs.scrape_configs` section.
      # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
    - job_name: integrations/mysql 
      static_configs:
        - labels:
            instance: '<your-instance-name>' # must match instance used in mysqld_exporter
            job: integrations/mysql # must match job used in mysqld_exporter
            __path__: /var/log/mysql/*.log
      pipeline_stages:
        - regex:
              expression: '(?P<timestamp>.+) (?P<thread>[\d]+) \[(?P<label>.+?)\]( \[(?P<err_code>.+?)\] \[(?P<subsystem>.+?)\])? (?P<msg>.+)'
        - labels:
            level: label
            err_code:
            subsystem:
        - drop:
            expression: "^ *$"
            drop_counter_reason: "drop empty lines"
metrics:
  configs:
  - name: integrations
    remote_write:
    - basic_auth:
        password: <your_prom_pass>
        username: <your_prom_user>
      url: <your_prom_url>
    scrape_configs:
      # Add here any snippet that belongs to the `metrics.configs.scrape_configs` section.
      # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
  global:
    scrape_interval: 60s
  wal_directory: /tmp/grafana-agent-wal

Dashboards

The MySQL integration installs the following dashboards in your Grafana Cloud instance to help monitor your system.

  • MySQL
  • MySQL logs

MySQL overview

MySQL overview

MySQL logs

MySQL logs

Alerts

The MySQL integration includes the following useful alerts:

MySQLdAlerts

AlertDescription
MySQLDownCritical: MySQL not up.

GaleraAlerts

AlertDescription
MySQLGaleraNotReadyWarning: Galera cluster node not ready.
MySQLGaleraOutOfSyncWarning: Galera cluster node out of sync.
MySQLGaleraDonorFallingBehindWarning: XtraDB cluster donor node falling behind.
MySQLReplicationNotRunningCritical: Replication is not running.
MySQLReplicationLagCritical: MySQL slave replication is lagging.
MySQLHeartbeatLagCritical: MySQL heartbeat is lagging.
MySQLInnoDBLogWaitsWarning: MySQL innodb log writes stalling.

Metrics

The most important metrics provided by the MySQL integration, which are used on the pre-built dashboards and Prometheus alerts, are as follows:

  • instance:mysql_heartbeat_lag_seconds
  • instance:mysql_slave_lag_seconds
  • mysql_global_status_aborted_clients
  • mysql_global_status_aborted_connects
  • mysql_global_status_buffer_pool_pages
  • mysql_global_status_bytes_received
  • mysql_global_status_bytes_sent
  • mysql_global_status_commands_total
  • mysql_global_status_created_tmp_disk_tables
  • mysql_global_status_created_tmp_files
  • mysql_global_status_created_tmp_tables
  • mysql_global_status_handlers_total
  • mysql_global_status_innodb_log_waits
  • mysql_global_status_innodb_mem_adaptive_hash
  • mysql_global_status_innodb_mem_dictionary
  • mysql_global_status_innodb_num_open_files
  • mysql_global_status_innodb_page_size
  • mysql_global_status_max_used_connections
  • mysql_global_status_open_files
  • mysql_global_status_open_table_definitions
  • mysql_global_status_open_tables
  • mysql_global_status_opened_files
  • mysql_global_status_opened_table_definitions
  • mysql_global_status_opened_tables
  • mysql_global_status_qcache_free_memory
  • mysql_global_status_qcache_hits
  • mysql_global_status_qcache_inserts
  • mysql_global_status_qcache_lowmem_prunes
  • mysql_global_status_qcache_not_cached
  • mysql_global_status_qcache_queries_in_cache
  • mysql_global_status_queries
  • mysql_global_status_questions
  • mysql_global_status_select_full_join
  • mysql_global_status_select_full_range_join
  • mysql_global_status_select_range
  • mysql_global_status_select_range_check
  • mysql_global_status_select_scan
  • mysql_global_status_slow_queries
  • mysql_global_status_sort_merge_passes
  • mysql_global_status_sort_range
  • mysql_global_status_sort_rows
  • mysql_global_status_sort_scan
  • mysql_global_status_table_locks_immediate
  • mysql_global_status_table_locks_waited
  • mysql_global_status_table_open_cache_hits
  • mysql_global_status_table_open_cache_misses
  • mysql_global_status_table_open_cache_overflows
  • mysql_global_status_threads_cached
  • mysql_global_status_threads_connected
  • mysql_global_status_threads_created
  • mysql_global_status_threads_running
  • mysql_global_status_uptime
  • mysql_global_status_wsrep_local_recv_queue
  • mysql_global_status_wsrep_local_state
  • mysql_global_status_wsrep_ready
  • mysql_global_variables_innodb_additional_mem_pool_size
  • mysql_global_variables_innodb_buffer_pool_size
  • mysql_global_variables_innodb_log_buffer_size
  • mysql_global_variables_key_buffer_size
  • mysql_global_variables_max_connections
  • mysql_global_variables_open_files_limit
  • mysql_global_variables_query_cache_size
  • mysql_global_variables_table_definition_cache
  • mysql_global_variables_table_open_cache
  • mysql_global_variables_thread_cache_size
  • mysql_global_variables_tokudb_cache_size
  • mysql_global_variables_wsrep_desync
  • mysql_heartbeat_now_timestamp_seconds
  • mysql_heartbeat_stored_timestamp_seconds
  • mysql_info_schema_processlist_threads
  • mysql_slave_status_seconds_behind_master
  • mysql_slave_status_slave_io_running
  • mysql_slave_status_slave_sql_running
  • mysql_slave_status_sql_delay
  • mysql_up

Changelog

md
# 1.0.2 - January 2024

* Allow selection of "all" clusters on MySQL overview dashboard, allowing the display of metrics which do not have the cluster tag.

# 1.0.1 - August 2023

* Add regex filter for logs datasource

# 1.0.0 - August 2023

* Add Kubernetes instructions
* Switch panels to timeseries type
* Fix stat panels to use 'last' aggegation instead of 'mean'
* Chain job and instance variables

# 0.1.1 - July 2023

* New Filter Metrics option for configuring the Grafana Agent, which saves on metrics cost by dropping any metric not used by this integration. Beware that anything custom built using metrics that are not on the snippet will stop working.
* New hostname relabel option, which applies the instance name you write on the text box to the Grafana Agent configuration snippets, making it easier and less error prone to configure this mandatory label.

# 0.1.0 - July 2023

* Updated logs dashboard
* Updated alerts annotations

# 0.0.5 - November 2022

* Add integration status panel

# 0.0.4 - April 2022

* Updated documentation and agent config snippets

# 0.0.3 - February 2022

* Added logs support from Loki datasource

# 0.0.2 - October 2021

* Update all rate queries to use `$__rate_interval`

# 0.0.1 - October 2020

* Initial release

Cost

By connecting your MySQL instance to Grafana Cloud, you might incur charges. To view information on the number of active series that your Grafana Cloud account uses for metrics included in each Cloud tier, see Active series and dpm usage and Cloud tier pricing.