Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[prometheus-mysql-exporter] Support multiple target #3751

Merged
merged 10 commits into from
Nov 16, 2023
2 changes: 1 addition & 1 deletion charts/prometheus-mysql-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
35 changes: 35 additions & 0 deletions charts/prometheus-mysql-exporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Remy-Mollandin-SK5 marked this conversation as resolved.
Show resolved Hide resolved

```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).
Expand Down
38 changes: 38 additions & 0 deletions charts/prometheus-mysql-exporter/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,43 @@ spec:
{{ toYaml . | trim | indent 4 -}}
{{- end }}
endpoints:
{{- if .Values.serviceMonitor.multipleTarget.enabled }}
{{- range .Values.serviceMonitor.multipleTarget.targets }}
- path: /probe
Remy-Mollandin-SK5 marked this conversation as resolved.
Show resolved Hide resolved
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 }}
Remy-Mollandin-SK5 marked this conversation as resolved.
Show resolved Hide resolved
{{- end }}
{{- end }}
{{- else }}
- path: /metrics
port: {{ .Values.service.name }}
{{- if .Values.serviceMonitor.interval }}
Expand All @@ -44,4 +81,5 @@ spec:
{{- if .Values.serviceMonitor.relabelings }}
relabelings: {{ toYaml .Values.serviceMonitor.relabelings | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}
15 changes: 15 additions & 0 deletions charts/prometheus-mysql-exporter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down