For AI agents: this documentation is indexed for you in llms.txt, and all of it in /llms.txt. Every page is also available as markdown: append .md to its address.

Enable metrics collector

You can use Prometheus mysqld exporterOpens in a new tab to gather metrics from the deployed MySQL database instances. The Cennso Database extension provides the mysqld-exporter deployment per MySQL instance.

Note

Do not mix the MySQL instance with DBInstance. The MySQL instance refers to a single MySQL database server deployed within the MySQL cluster described by the DBInstance.

You can enable mysqld-exporter using the following configuration option:

yaml

If spec.metricsExporter.enabled is set to true, a mysqld-exporter instance is deployed for each MySQL server instance as a separate pod on the same node as the corresponding MySQL instance. The node of each MySQL instance depends on its storage configuration, as described in the Storage configuration section of the Cennso Database Instance document.

The following example shows how you can deploy a mysqld-exporter instance for your MySQL cluster:

yaml

Note

For more information about all the configuration options except the spec.metricsExporter, see the Deploy Cennso Database Instance document.

Using the example above, you can deploy the MySQL cluster, which consists of two MySQL instances deployed on the nodes specified by {NODE-0-NAME} and {NODE-1-NAME}. Together with the MySQL server instances, two mysql-exporter instances are deployed on the same nodes to collect metrics from the MySQL servers.

Relabeling rules

By default, each mysql-exporter instance provides the following relabelingOpens in a new tab rules:

yaml

Using the relabeling rules described above, you can use the mysql_instance or instance label to refer to a MySQL server instance name. In addition, you can specify your relabeling rules using the spec.metricsExporter.additionalRelabelings configuration options.

Metric collectors

The following metric collectors settings are set by default:

  • global_status
  • global_variables
  • engine_innodb_status
  • slave_status
  • binlog_size

To enable a different set of collectors, use the spec.metricsExporter.collectors configuration option. For more information about the available collectors, see the official documentationOpens in a new tab.

Prometheus rules

To configure additional Prometheus rulesOpens in a new tab, use the spec.metricsExporter.prometheusRules configuration option. To do that, set the spec.metricsExporter.prometheusRules.enabled to true and fill the spec.metricsExporter.prometheusRules.rules with your custom Prometheus rules. The rules are created as one PrometheusRule named mysqld-exporter-{DATABASE-CLUSTER-NAME} in the namespace set by spec.namespace. For examples, see the Custom alert rules section.

Metrics based on custom queries

Note

Each mysqld-exporter instance runs custom queries against its own MySQL instance and exposes the results as metrics that Prometheus can scrape. The results are reported per MySQL instance and are not aggregated across the cluster.

In addition to the built-in collectorsOpens in a new tab, you can expose Prometheus metrics for arbitrary SQL statements using the spec.metricsExporter.customQueries configuration option.

By default, custom queries are disabled (the spec.metricsExporter.customQueries configuration option is set to the empty string - ""). When the value of this configuration option is set, the mysqld-exporter is launched with the --collect.custom_query.hr flag and reads the YAML definitions from a Kubernetes ConfigMap mounted at /etc/mysqld-exporter/custom-queries/hr. The ConfigMap is created and reconciled automatically for each MySQL instance.

The value is an inline YAML document. Each top-level key defines a metric namespace used as the metric name prefix. Each namespace must contain a query and a metrics key. The query key specifies an SQL query that is executed to build data points for the metrics. The metrics key is a YAML array which contains the column name from the SQL query result and specifies how the value of this column is used. The usage of the value should be under the usage key. The possible values of the usage key are:

The following example exposes five custom metrics:

yaml

The example above produces the following metrics:

  • mysql_slow_queries_total_value{Variable_name="Slow_queries"} value
  • mysql_table_size_bytes_data_length{table_schema="...", table_name="...", engine="..."} value
  • mysql_table_size_bytes_index_length{table_schema="...", table_name="...", engine="..."} value
  • mysql_table_size_bytes_total_size{table_schema="...", table_name="...", engine="..."} value
  • mysql_connections_by_user_connections{user="...", host="..."} value

The emitted metric name follows the pattern {namespace}_{column} for every non-LABEL and non-DISCARD value column, and {namespace}_{column}_milliseconds for DURATION columns.

Note

Every custom query is executed on every Prometheus scrape, so avoid statements that are expensive to run or that lock tables. Use spec.metricsExporter.scrapeInterval to reduce the load if needed.

For more examples of the YAML schema, see the queries-mysqld.ymlOpens in a new tab.