github.com/netdata/go.d.plugin@v0.58.1/modules/mysql/integrations/mysql.md (about)

     1  <!--startmeta
     2  custom_edit_url: "https://github.com/netdata/go.d.plugin/edit/master/modules/mysql/integrations/mysql.md"
     3  meta_yaml: "https://github.com/netdata/go.d.plugin/edit/master/modules/mysql/metadata.yaml"
     4  sidebar_label: "MySQL"
     5  learn_status: "Published"
     6  learn_rel_path: "Data Collection/Databases"
     7  most_popular: True
     8  message: "DO NOT EDIT THIS FILE DIRECTLY, IT IS GENERATED BY THE COLLECTOR'S metadata.yaml FILE"
     9  endmeta-->
    10  
    11  # MySQL
    12  
    13  
    14  <img src="https://netdata.cloud/img/mysql.svg" width="150"/>
    15  
    16  
    17  Plugin: go.d.plugin
    18  Module: mysql
    19  
    20  <img src="https://img.shields.io/badge/maintained%20by-Netdata-%2300ab44" />
    21  
    22  ## Overview
    23  
    24  This collector monitors the health and performance of MySQL servers and collects general statistics, replication and user metrics.
    25  
    26  
    27  It connects to the MySQL instance via a TCP or UNIX socket and executes the following commands:
    28  
    29  Executed queries:
    30  
    31  - `SELECT VERSION();`
    32  - `SHOW GLOBAL STATUS;`
    33  - `SHOW GLOBAL VARIABLES;`
    34  - `SHOW SLAVE STATUS;` or `SHOW ALL SLAVES STATUS;` (MariaDBv10.2+) or `SHOW REPLICA STATUS;` (MySQL 8.0.22+)
    35  - `SHOW USER_STATISTICS;` (MariaDBv10.1.1+)
    36  - `SELECT TIME,USER FROM INFORMATION_SCHEMA.PROCESSLIST;`
    37  
    38  
    39  This collector is supported on all platforms.
    40  
    41  This collector supports collecting metrics from multiple instances of this integration, including remote instances.
    42  
    43  
    44  ### Default Behavior
    45  
    46  #### Auto-Detection
    47  
    48  By default, it detects instances running on localhost by trying to connect as root and netdata using known MySQL TCP and UNIX sockets:
    49  
    50  - /var/run/mysqld/mysqld.sock
    51  - /var/run/mysqld/mysql.sock
    52  - /var/lib/mysql/mysql.sock
    53  - /tmp/mysql.sock
    54  - 127.0.0.1:3306
    55  - "[::1]:3306"
    56  
    57  
    58  #### Limits
    59  
    60  The default configuration for this integration does not impose any limits on data collection.
    61  
    62  #### Performance Impact
    63  
    64  The default configuration for this integration is not expected to impose a significant performance impact on the system.
    65  
    66  
    67  ## Metrics
    68  
    69  Metrics grouped by *scope*.
    70  
    71  The scope defines the instance that the metric belongs to. An instance is uniquely identified by a set of labels.
    72  
    73  
    74  
    75  ### Per MariaDB instance
    76  
    77  These metrics refer to the entire monitored application.
    78  
    79  This scope has no labels.
    80  
    81  Metrics:
    82  
    83  | Metric | Dimensions | Unit | MySQL | MariaDB | Percona |
    84  |:------|:----------|:----|:---:|:---:|:---:|
    85  | mysql.net | in, out | kilobits/s | • | • | • |
    86  | mysql.queries | queries, questions, slow_queries | queries/s | • | • | • |
    87  | mysql.queries_type | select, delete, update, insert, replace | queries/s | • | • | • |
    88  | mysql.handlers | commit, delete, prepare, read_first, read_key, read_next, read_prev, read_rnd, read_rnd_next, rollback, savepoint, savepointrollback, update, write | handlers/s | • | • | • |
    89  | mysql.table_open_cache_overflows | open_cache | overflows/s | • | • | • |
    90  | mysql.table_locks | immediate, waited | locks/s | • | • | • |
    91  | mysql.join_issues | full_join, full_range_join, range, range_check, scan | joins/s | • | • | • |
    92  | mysql.sort_issues | merge_passes, range, scan | issues/s | • | • | • |
    93  | mysql.tmp | disk_tables, files, tables | events/s | • | • | • |
    94  | mysql.connections | all, aborted | connections/s | • | • | • |
    95  | mysql.connections_active | active, limit, max_active | connections | • | • | • |
    96  | mysql.threads | connected, cached, running | threads | • | • | • |
    97  | mysql.threads_created | created | threads/s | • | • | • |
    98  | mysql.thread_cache_misses | misses | misses | • | • | • |
    99  | mysql.innodb_io | read, write | KiB/s | • | • | • |
   100  | mysql.innodb_io_ops | reads, writes, fsyncs | operations/s | • | • | • |
   101  | mysql.innodb_io_pending_ops | reads, writes, fsyncs | operations | • | • | • |
   102  | mysql.innodb_log | waits, write_requests, writes | operations/s | • | • | • |
   103  | mysql.innodb_cur_row_lock | current waits | operations | • | • | • |
   104  | mysql.innodb_rows | inserted, read, updated, deleted | operations/s | • | • | • |
   105  | mysql.innodb_buffer_pool_pages | data, dirty, free, misc, total | pages | • | • | • |
   106  | mysql.innodb_buffer_pool_pages_flushed | flush_pages | requests/s | • | • | • |
   107  | mysql.innodb_buffer_pool_bytes | data, dirty | MiB | • | • | • |
   108  | mysql.innodb_buffer_pool_read_ahead | all, evicted | pages/s | • | • | • |
   109  | mysql.innodb_buffer_pool_read_ahead_rnd | read-ahead | operations/s | • | • | • |
   110  | mysql.innodb_buffer_pool_ops | disk_reads, wait_free | operations/s | • | • | • |
   111  | mysql.innodb_os_log | fsyncs, writes | operations | • | • | • |
   112  | mysql.innodb_os_log_fsync_writes | fsyncs | operations/s | • | • | • |
   113  | mysql.innodb_os_log_io | write | KiB/s | • | • | • |
   114  | mysql.innodb_deadlocks | deadlocks | operations/s | • | • | • |
   115  | mysql.files | files | files | • | • | • |
   116  | mysql.files_rate | files | files/s | • | • | • |
   117  | mysql.connection_errors | accept, internal, max, peer_addr, select, tcpwrap | errors/s | • | • | • |
   118  | mysql.opened_tables | tables | tables/s | • | • | • |
   119  | mysql.open_tables | cache, tables | tables | • | • | • |
   120  | mysql.process_list_fetch_query_duration | duration | milliseconds | • | • | • |
   121  | mysql.process_list_queries_count | system, user | queries | • | • | • |
   122  | mysql.process_list_longest_query_duration | duration | seconds | • | • | • |
   123  | mysql.qcache_ops | hits, lowmem_prunes, inserts, not_cached | queries/s | • | • | • |
   124  | mysql.qcache | queries | queries | • | • | • |
   125  | mysql.qcache_freemem | free | MiB | • | • | • |
   126  | mysql.qcache_memblocks | free, total | blocks | • | • | • |
   127  | mysql.galera_writesets | rx, tx | writesets/s | • | • | • |
   128  | mysql.galera_bytes | rx, tx | KiB/s | • | • | • |
   129  | mysql.galera_queue | rx, tx | writesets | • | • | • |
   130  | mysql.galera_conflicts | bf_aborts, cert_fails | transactions | • | • | • |
   131  | mysql.galera_flow_control | paused | ms | • | • | • |
   132  | mysql.galera_cluster_status | primary, non_primary, disconnected | status | • | • | • |
   133  | mysql.galera_cluster_state | undefined, joining, donor, joined, synced, error | state | • | • | • |
   134  | mysql.galera_cluster_size | nodes | nodes | • | • | • |
   135  | mysql.galera_cluster_weight | weight | weight | • | • | • |
   136  | mysql.galera_connected | connected | boolean | • | • | • |
   137  | mysql.galera_ready | ready | boolean | • | • | • |
   138  | mysql.galera_open_transactions | open | transactions | • | • | • |
   139  | mysql.galera_thread_count | threads | threads | • | • | • |
   140  | mysql.key_blocks | unused, used, not_flushed | blocks | • | • | • |
   141  | mysql.key_requests | reads, writes | requests/s | • | • | • |
   142  | mysql.key_disk_ops | reads, writes | operations/s | • | • | • |
   143  | mysql.binlog_cache | disk, all | transactions/s | • | • | • |
   144  | mysql.binlog_stmt_cache | disk, all | statements/s | • | • | • |
   145  
   146  ### Per connection
   147  
   148  These metrics refer to the replication connection.
   149  
   150  This scope has no labels.
   151  
   152  Metrics:
   153  
   154  | Metric | Dimensions | Unit | MySQL | MariaDB | Percona |
   155  |:------|:----------|:----|:---:|:---:|:---:|
   156  | mysql.slave_behind | seconds | seconds | • | • | • |
   157  | mysql.slave_status | sql_running, io_running | boolean | • | • | • |
   158  
   159  ### Per user
   160  
   161  These metrics refer to the MySQL user.
   162  
   163  Labels:
   164  
   165  | Label      | Description     |
   166  |:-----------|:----------------|
   167  | user | username |
   168  
   169  Metrics:
   170  
   171  | Metric | Dimensions | Unit | MySQL | MariaDB | Percona |
   172  |:------|:----------|:----|:---:|:---:|:---:|
   173  | mysql.userstats_cpu | used | percentage |   | • | • |
   174  | mysql.userstats_rows | read, sent, updated, inserted, deleted | operations/s |   | • | • |
   175  | mysql.userstats_commands | select, update, other | commands/s |   | • | • |
   176  | mysql.userstats_denied_commands | denied | commands/s |   | • | • |
   177  | mysql.userstats_created_transactions | commit, rollback | transactions/s |   | • | • |
   178  | mysql.userstats_binlog_written | written | B/s |   | • | • |
   179  | mysql.userstats_empty_queries | empty | queries/s |   | • | • |
   180  | mysql.userstats_connections | created | connections/s |   | • | • |
   181  | mysql.userstats_lost_connections | lost | connections/s |   | • | • |
   182  | mysql.userstats_denied_connections | denied | connections/s |   | • | • |
   183  
   184  
   185  
   186  ## Alerts
   187  
   188  
   189  The following alerts are available:
   190  
   191  | Alert name  | On metric | Description |
   192  |:------------|:----------|:------------|
   193  | [ mysql_10s_slow_queries ](https://github.com/netdata/netdata/blob/master/health/health.d/mysql.conf) | mysql.queries | number of slow queries in the last 10 seconds |
   194  | [ mysql_10s_table_locks_immediate ](https://github.com/netdata/netdata/blob/master/health/health.d/mysql.conf) | mysql.table_locks | number of table immediate locks in the last 10 seconds |
   195  | [ mysql_10s_table_locks_waited ](https://github.com/netdata/netdata/blob/master/health/health.d/mysql.conf) | mysql.table_locks | number of table waited locks in the last 10 seconds |
   196  | [ mysql_10s_waited_locks_ratio ](https://github.com/netdata/netdata/blob/master/health/health.d/mysql.conf) | mysql.table_locks | ratio of waited table locks over the last 10 seconds |
   197  | [ mysql_connections ](https://github.com/netdata/netdata/blob/master/health/health.d/mysql.conf) | mysql.connections_active | client connections utilization |
   198  | [ mysql_replication ](https://github.com/netdata/netdata/blob/master/health/health.d/mysql.conf) | mysql.slave_status | replication status (0: stopped, 1: working) |
   199  | [ mysql_replication_lag ](https://github.com/netdata/netdata/blob/master/health/health.d/mysql.conf) | mysql.slave_behind | difference between the timestamp of the latest transaction processed by the SQL thread and the timestamp of the same transaction when it was processed on the master |
   200  | [ mysql_galera_cluster_size_max_2m ](https://github.com/netdata/netdata/blob/master/health/health.d/mysql.conf) | mysql.galera_cluster_size | maximum galera cluster size in the last 2 minutes starting one minute ago |
   201  | [ mysql_galera_cluster_size ](https://github.com/netdata/netdata/blob/master/health/health.d/mysql.conf) | mysql.galera_cluster_size | current galera cluster size, compared to the maximum size in the last 2 minutes |
   202  | [ mysql_galera_cluster_state_warn ](https://github.com/netdata/netdata/blob/master/health/health.d/mysql.conf) | mysql.galera_cluster_state | galera node state is either Donor/Desynced or Joined |
   203  | [ mysql_galera_cluster_state_crit ](https://github.com/netdata/netdata/blob/master/health/health.d/mysql.conf) | mysql.galera_cluster_state | galera node state is either Undefined or Joining or Error |
   204  | [ mysql_galera_cluster_status ](https://github.com/netdata/netdata/blob/master/health/health.d/mysql.conf) | mysql.galera_cluster_status | galera node is part of a nonoperational component. This occurs in cases of multiple membership changes that result in a loss of Quorum or in cases of split-brain situations. |
   205  
   206  
   207  ## Setup
   208  
   209  ### Prerequisites
   210  
   211  #### Create netdata user
   212  
   213  A user account should have the
   214  following [permissions](https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html):
   215  
   216  - [`USAGE`](https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_usage)
   217  - [`REPLICATION CLIENT`](https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_replication-client)
   218  - [`PROCESS`](https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_process)
   219  
   220  To create the `netdata` user with these permissions, execute the following in the MySQL shell:
   221  
   222  ```mysql
   223  CREATE USER 'netdata'@'localhost';
   224  GRANT USAGE, REPLICATION CLIENT, PROCESS ON *.* TO 'netdata'@'localhost';
   225  FLUSH PRIVILEGES;
   226  ```
   227  
   228  The `netdata` user will have the ability to connect to the MySQL server on localhost without a password. It will only
   229  be able to gather statistics without being able to alter or affect operations in any way.
   230  
   231  
   232  
   233  ### Configuration
   234  
   235  #### File
   236  
   237  The configuration file name for this integration is `go.d/mysql.conf`.
   238  
   239  
   240  You can edit the configuration file using the `edit-config` script from the
   241  Netdata [config directory](https://github.com/netdata/netdata/blob/master/docs/configure/nodes.md#the-netdata-config-directory).
   242  
   243  ```bash
   244  cd /etc/netdata 2>/dev/null || cd /opt/netdata/etc/netdata
   245  sudo ./edit-config go.d/mysql.conf
   246  ```
   247  #### Options
   248  
   249  The following options can be defined globally: update_every, autodetection_retry.
   250  
   251  
   252  <details><summary>Config options</summary>
   253  
   254  | Name | Description | Default | Required |
   255  |:----|:-----------|:-------|:--------:|
   256  | update_every | Data collection frequency. | 5 | no |
   257  | autodetection_retry | Recheck interval in seconds. Zero means no recheck will be scheduled. | 0 | no |
   258  | dsn | MySQL server DSN (Data Source Name). See [DSN syntax](https://github.com/go-sql-driver/mysql#dsn-data-source-name). | root@tcp(localhost:3306)/ | yes |
   259  | my.cnf | Specifies the my.cnf file to read the connection settings from the [client] section. |  | no |
   260  | timeout | Query timeout in seconds. | 1 | no |
   261  
   262  </details>
   263  
   264  #### Examples
   265  
   266  ##### TCP socket
   267  
   268  An example configuration.
   269  
   270  <details><summary>Config</summary>
   271  
   272  ```yaml
   273  jobs:
   274    - name: local
   275      dsn: netdata@tcp(127.0.0.1:3306)/
   276  
   277  ```
   278  </details>
   279  
   280  ##### Unix socket
   281  
   282  An example configuration.
   283  
   284  <details><summary>Config</summary>
   285  
   286  ```yaml
   287  jobs:
   288    - name: local
   289      dsn: netdata@unix(/var/lib/mysql/mysql.sock)/
   290  
   291  ```
   292  </details>
   293  
   294  ##### Connection with password
   295  
   296  An example configuration.
   297  
   298  <details><summary>Config</summary>
   299  
   300  ```yaml
   301  jobs:
   302    - name: local
   303      dsn: netconfig:password@tcp(127.0.0.1:3306)/
   304  
   305  ```
   306  </details>
   307  
   308  ##### my.cnf
   309  
   310  An example configuration.
   311  
   312  <details><summary>Config</summary>
   313  
   314  ```yaml
   315  jobs:
   316    - name: local
   317      my.cnf: '/etc/my.cnf'
   318  
   319  ```
   320  </details>
   321  
   322  ##### Multi-instance
   323  
   324  > **Note**: When you define multiple jobs, their names must be unique.
   325  
   326  Local and remote instances.
   327  
   328  
   329  <details><summary>Config</summary>
   330  
   331  ```yaml
   332  jobs:
   333    - name: local
   334      dsn: netdata@tcp(127.0.0.1:3306)/
   335  
   336    - name: remote
   337      dsn: netconfig:password@tcp(203.0.113.0:3306)/
   338  
   339  ```
   340  </details>
   341  
   342  
   343  
   344  ## Troubleshooting
   345  
   346  ### Debug Mode
   347  
   348  To troubleshoot issues with the `mysql` collector, run the `go.d.plugin` with the debug option enabled. The output
   349  should give you clues as to why the collector isn't working.
   350  
   351  - Navigate to the `plugins.d` directory, usually at `/usr/libexec/netdata/plugins.d/`. If that's not the case on
   352    your system, open `netdata.conf` and look for the `plugins` setting under `[directories]`.
   353  
   354    ```bash
   355    cd /usr/libexec/netdata/plugins.d/
   356    ```
   357  
   358  - Switch to the `netdata` user.
   359  
   360    ```bash
   361    sudo -u netdata -s
   362    ```
   363  
   364  - Run the `go.d.plugin` to debug the collector:
   365  
   366    ```bash
   367    ./go.d.plugin -d -m mysql
   368    ```
   369  
   370