Skip to content

Commit

Permalink
[prometheus-mysql-exporter] Support multiple target (prometheus-commu…
Browse files Browse the repository at this point in the history
…nity#3751)

* [prometheus-mysql-exporter]: multi-target probe support

Signed-off-by: Remy Mollandin <[email protected]>

* [prometheus-mysql-exporter]: updating value comments for targets structure

Signed-off-by: Remy Mollandin <[email protected]>

* [prometheus-mysql-exporter]: add default relabeling for multiple target

Signed-off-by: Remy Mollandin <[email protected]>

* feat(prometheus-mysql-exporter): modify values structure and now support shared credentials pattern

Signed-off-by: Remy Mollandin <[email protected]>

* [prometheus-mysql-exporter]: modify values comment

Signed-off-by: Remy Mollandin <[email protected]>

* chore: bump chart version to 2.2.0

Signed-off-by: Remy Mollandin <[email protected]>

* docs: indent targets doc string

Signed-off-by: Remy Mollandin <[email protected]>

* Update charts/prometheus-mysql-exporter/values.yaml

Signed-off-by: André Bauer <[email protected]>

* Update charts/prometheus-mysql-exporter/values.yaml

Signed-off-by: André Bauer <[email protected]>

---------

Signed-off-by: Remy Mollandin <[email protected]>
Signed-off-by: André Bauer <[email protected]>
Co-authored-by: André Bauer <[email protected]>
  • Loading branch information
2 people authored and Matiasmct committed Mar 20, 2024
1 parent d1bfbba commit 6a33bd5
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
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:
```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
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 }}
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

0 comments on commit 6a33bd5

Please sign in to comment.