diff --git a/charts/prometheus-mysql-exporter/Chart.yaml b/charts/prometheus-mysql-exporter/Chart.yaml index 8c9e6462af5e..fdbb4bba85dd 100644 --- a/charts/prometheus-mysql-exporter/Chart.yaml +++ b/charts/prometheus-mysql-exporter/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v1 description: A Helm chart for prometheus mysql exporter with cloudsqlproxy name: prometheus-mysql-exporter -version: 2.1.1 +version: 2.2.0 home: https://github.com/prometheus/mysqld_exporter appVersion: v0.15.0 sources: diff --git a/charts/prometheus-mysql-exporter/README.md b/charts/prometheus-mysql-exporter/README.md index 2023ad9642de..8eca2387d276 100644 --- a/charts/prometheus-mysql-exporter/README.md +++ b/charts/prometheus-mysql-exporter/README.md @@ -41,6 +41,41 @@ _See [helm upgrade](https://helm.sh/docs/helm/helm_upgrade/) for command documen 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 `serviecMonitor.multipleTarget.enabled` to `true` and define your targets in `serviceMonitor.multipleTarget.targets`. +Credentials for each target should be referenced in the associate config file. Target name should match the entry in the config file. +As an example, for a config file with two targets: + +```yaml +serviceMonitor: + multipleTarget: + enabled: true + targets: + - name: localhost + endpoint: 127.0.0.1 + - name: remote + endpoint: 8.8.8.8 + port: 3307 +``` + +Config file should have the following entries: + +```cnf +[client] +user=NOT_USED +password=NOT_USED +[client.localhost] +user=localhost_user +password=localhost_password +[client.remote] +user=remote_user +password=remote_password +``` + +The configuration file can be referenced using `mysql.existingConfigSecret`. +If all your target use the same credentials, you can set `serviceMonitor.sharedSecret.enabled` to `true` and define the key name in `serviceMonitor.sharedSecret.name`. + ### From 1.x to 2.x mysqld_exporter has been updated to [v0.15.0](https://github.com/prometheus/mysqld_exporter/releases/tag/v0.15.0), removing support for `DATA_SOURCE_NAME`. Configuration for exporter use `--config.my-cnf` with a custom cnf file (secret). diff --git a/charts/prometheus-mysql-exporter/templates/servicemonitor.yaml b/charts/prometheus-mysql-exporter/templates/servicemonitor.yaml index dba2bfdd6359..f241c4c514e2 100644 --- a/charts/prometheus-mysql-exporter/templates/servicemonitor.yaml +++ b/charts/prometheus-mysql-exporter/templates/servicemonitor.yaml @@ -30,6 +30,43 @@ spec: {{ toYaml . | trim | indent 4 -}} {{- end }} endpoints: + {{- if .Values.serviceMonitor.multipleTarget.enabled }} + {{- range .Values.serviceMonitor.multipleTarget.targets }} + - path: /probe + port: {{ $.Values.service.name }} + {{- if $.Values.serviceMonitor.interval }} + interval: {{ $.Values.serviceMonitor.interval }} + {{- end }} + {{- if $.Values.serviceMonitor.scrapeTimeout }} + scrapeTimeout: {{ $.Values.serviceMonitor.scrapeTimeout }} + {{- end }} + metricRelabelings: + - action: replace + replacement: {{ .endpoint }} + sourceLabels: [instance] + targetLabel: instance + - action: replace + replacement: {{ .name }} + sourceLabels: [target] + targetLabel: target + {{- if $.Values.serviceMonitor.metricRelabelings -}} + {{ toYaml $.Values.serviceMonitor.metricRelabelings | nindent 8 }} + {{- end }} + {{- if $.Values.serviceMonitor.relabelings }} + relabelings: {{ toYaml $.Values.serviceMonitor.relabelings | nindent 8 }} + {{- end }} + params: + target: + - {{ .endpoint }}:{{ .port | default 3306 }} + {{- if $.Values.serviceMonitor.multipleTarget.sharedSecret.enabled }} + auth_module: + - client.{{ $.Values.serviceMonitor.multipleTarget.sharedSecret.name }} + {{- else }} + auth_module: + - client.{{ .name }} + {{- end }} + {{- end }} + {{- else }} - path: /metrics port: {{ .Values.service.name }} {{- if .Values.serviceMonitor.interval }} @@ -44,4 +81,5 @@ spec: {{- if .Values.serviceMonitor.relabelings }} relabelings: {{ toYaml .Values.serviceMonitor.relabelings | nindent 8 }} {{- end }} + {{- end }} {{- end }} diff --git a/charts/prometheus-mysql-exporter/values.yaml b/charts/prometheus-mysql-exporter/values.yaml index b0011bf47b18..a9eb18074489 100644 --- a/charts/prometheus-mysql-exporter/values.yaml +++ b/charts/prometheus-mysql-exporter/values.yaml @@ -45,6 +45,21 @@ serviceMonitor: metricRelabelings: [] # Set relabel_configs as per https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config relabelings: [] + # Enable multi target scraping. + multipleTarget: + enabled: false + targets: [] + # target connection information with name (required), endpoint (required) and port (optionnal) + # if sharedSecret is not enabled the name must match an entry client.{{ name }} existing in the secret + # - endpoint: mysql1.dns.local + # name: mysql1 + # port: 3307 + # - endpoint: mysql2.dns.local + # name: mysql2 + # Enable shared credentials for all targets + sharedSecret: + enabled: false + name: "" serviceAccount: # Specifies whether a ServiceAccount should be created