prometheus-mysql-exporter
by Prometheus
A Helm chart for prometheus mysql exporter with cloudsqlproxy
About this chart
Prometheus MySQL Exporter
A Prometheus exporter for MySQL metrics.
This chart bootstraps a Prometheus MySQL Exporter deployment on a Kubernetes cluster using the Helm package manager.
Usage
The chart is distributed as an OCI Artifact as well as via a traditional Helm Repository.
- OCI Artifact:
oci://ghcr.io/prometheus-community/charts/prometheus-mysql-exporter - Helm Repository:
https://prometheus-community.github.io/helm-chartswith chartprometheus-mysql-exporter
The installation instructions use the OCI registry. Refer to the [helm repo](helm repo) command documentation for information on installing charts via the traditional repository.
Install Chart
helm install [RELEASE_NAME] oci://ghcr.io/prometheus-community/charts/prometheus-mysql-exporter
See configuration below.
See helm install for command documentation.
Uninstall Chart
helm uninstall [RELEASE_NAME]
This removes all the Kubernetes components associated with the chart and deletes the release.
See helm uninstall for command documentation.
See helm upgrade for command documentation.
Upgrading Chart
helm upgrade [RELEASE_NAME] [CHART] --install
Multiple-target probes
mysql_exporter now support multi-target probes using the /probe route. To enable this feature, set serviceMonitor.multipleTarget.enabled to true and define your targets in serviceMonitor.multipleTarget.targets.
Credentials for each target should be referenced either in targets section or in the associated config file.
As an example, for a config file with two targets:
serviceMonitor:
multipleTarget:
enabled: true
targets:
- endpoint: mysql1.dns.local
name: mysql1
port: 3307
user: user1
password: password1
- endpoint: mysql2.dns.local
name: mysql2
user: user2
password: password2
In case of Config file Target name should match the entry in the config file. Config file example for the above targets:
[client]
user=NOT_USED
password=NOT_USED
[client.mysql1]
user=user1
password=password1
[client.mysql2]
user=user2
password=password2
The configuration file can be:
- referenced using
mysql.existingConfigSecret; - created automatically in case user and password are specified for the target.
If all your target use the same credentials, you can set
serviceMonitor.sharedSecret.enabledtotrueand define the key name inserviceMonitor.sharedSecret.name.
From 1.x to 2.x
mysqld_exporter has been updated to v0.15.0, removing support for DATA_SOURCE_NAME. Configuration for exporter use --config.my-cnf with a custom cnf file (secret).
If you use mysql.existingSecret to set full DATA_SOURCE_NAME, please set mysql.existingConfigSecret.name & mysql.existingConfigSecret.key to reference the secret config.
mysql:
existingSecret: "my-data-source"
to:
mysql:
existingConfigSecret:
name: "config"
key: "my.cnf"
If you use mysql.param to extend DATA_SOURCE_NAME, please set mysql.additionalConfig with extra params to extend my.cnf file.
mysql:
param: "debug&connect-timeout=5"
to:
mysql:
additionalConfig:
- connect-timeout=5
- debug
This version uses cloud-sql-proxy v2.
If you use cloudsqlproxy.ipAddressTypes to set private connections, please set cloudsqlproxy.privateIp.
cloudsqlproxy:
ipAddressTypes: PRIVATE,PUBLIC
to:
cloudsqlproxy:
privateIp: true
To =< 1.0.0
Version 1.0.0 is a major update.
- The chart now follows the new Kubernetes label recommendations: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
The simplest way to update is to do a force upgrade, which recreates the resources by doing a delete and an install.
helm upgrade prometheus-mysql-exporter prometheus-community/prometheus-mysql-exporter --force
Configuration
See Customizing the Chart Before Installing. To see all configurable options with detailed comments, visit the chart's values.yaml, or run these configuration commands:
helm show values oci://ghcr.io/prometheus-community/charts/prometheus-mysql-exporter
MySQL Connection
The exporter can connect to MySQL directly or using the Cloud SQL Proxy.
- To configure direct MySQL connection by value, set
mysql.user,mysql.pass,mysql.hostandmysql.port(see additional options in themysqlconfiguration block) - To configure direct MySQL connection by secret, you must store a connection string in a secret, and set
mysql.existingSecretto[SECRET_NAME]
Exporter Documentation and Params
Documentation for the MySQL Exporter can be found here: (https://github.com/prometheus/mysqld_exporter) A MySQL params overview can be found here: (https://github.com/go-sql-driver/mysql#dsn-data-source-name)
Collector Flags
Available collector flags can be found in the values.yaml and a description of each flag can be found in the mysqld_exporter repository.
CloudSql Proxy Workload Identity
Enable it with flag cloudsqlproxy.workloadIdentity
To more details about Workload Identity visit Use Workload Identity
Extra Manifests
This chart supports deploying extra Kubernetes manifests alongside the MySQL exporter. This can be useful for creating additional resources like ConfigMaps, Secrets, or other Kubernetes objects.
The extraManifests value supports two formats and is evaluated as a template, allowing you to use Helm template functions and access values like .Release.Name, .Release.Namespace, .Chart.Name, etc.
Object Format (Recommended)
Provides better IDE support, validation, and readability:
extraManifests:
- apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ .Release.Name }}-extra-config"
namespace: "{{ .Release.Namespace }}"
labels:
app: "{{ .Chart.Name }}"
data:
extra-data: "value"
- apiVersion: v1
kind: Secret
metadata:
name: "{{ .Release.Name }}-extra-secret"
type: Opaque
stringData:
key: "secret-value"
String Format (Alternative)
Uses YAML multiline strings with pipe |:
extraManifests:
- |
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-exporter-extra
data:
key: value
- |
apiVersion: v1
kind: Secret
metadata:
name: mysql-exporter-secret
type: Opaque
stringData:
password: "{{ .Values.mysql.pass }}"
Both formats can be mixed in the same extraManifests array if needed.
Deploy prometheus-mysql-exporter with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has prometheus-mysql-exporter on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartprometheus-mysql-exporter is pinned at v2.17.1 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply