Skip to content

Commit aaa91c9

Browse files
festeveirazanhsieh
andauthored
[prometheus-postgres-exporter] Implement multiple target in service monitor (#5012)
* [prometheus-postgres-exporter] Implement multiple target with /probe endpoint Signed-off-by: festeveira <[email protected]> * Replace multipleTargets with multipleTarget Signed-off-by: festeveira <[email protected]> * Improve values.yaml documentation Signed-off-by: festeveira <[email protected]> * Remove /postgres path from target param in ServiceMonitor Signed-off-by: festeveira <[email protected]> --------- Signed-off-by: festeveira <[email protected]> Signed-off-by: Francisco Esteveira <[email protected]> Co-authored-by: MH <[email protected]>
1 parent d53ec4d commit aaa91c9

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

charts/prometheus-postgres-exporter/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
appVersion: "v0.16.0"
33
description: A Helm chart for prometheus postgres-exporter
44
name: prometheus-postgres-exporter
5-
version: 6.6.0
5+
version: 6.7.0
66
home: https://github.com/prometheus-community/postgres_exporter
77
sources:
88
- https://github.com/prometheus-community/postgres_exporter

charts/prometheus-postgres-exporter/templates/servicemonitor.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,52 @@ metadata:
1212
namespace: {{ .Values.serviceMonitor.namespace }}
1313
{{- end }}
1414
spec:
15+
{{- if .Values.serviceMonitor.multipleTarget.enabled }}
16+
endpoints:
17+
{{- range .Values.serviceMonitor.multipleTarget.targets }}
18+
- path: /probe
19+
port: {{ $.Values.service.name }}
20+
{{- if $.Values.serviceMonitor.interval }}
21+
interval: {{ $.Values.serviceMonitor.interval }}
22+
{{- end }}
23+
{{- if $.Values.serviceMonitor.timeout }}
24+
scrapeTimeout: {{ $.Values.serviceMonitor.timeout }}
25+
{{- end }}
26+
{{- if $.Values.serviceMonitor.scheme }}
27+
scheme: {{ $.Values.serviceMonitor.scheme }}
28+
{{- end }}
29+
{{- with $.Values.serviceMonitor.tlsConfig }}
30+
tlsConfig:
31+
{{- toYaml . | nindent 6 }}
32+
{{- end }}
33+
metricRelabelings:
34+
- action: replace
35+
replacement: {{ .endpoint }}
36+
sourceLabels: [instance]
37+
targetLabel: instance
38+
- action: replace
39+
replacement: {{ .name }}
40+
sourceLabels: [target]
41+
targetLabel: target
42+
{{- if $.Values.serviceMonitor.metricRelabelings -}}
43+
{{ toYaml $.Values.serviceMonitor.metricRelabelings | nindent 8 }}
44+
{{- end }}
45+
{{- if $.Values.serviceMonitor.relabelings }}
46+
relabelings: {{ toYaml $.Values.serviceMonitor.relabelings | nindent 8 }}
47+
{{- end }}
48+
params:
49+
target:
50+
- {{ .endpoint }}:{{ .port | default 5432 }}
51+
{{- if $.Values.serviceMonitor.multipleTarget.sharedAuthModule.enabled }}
52+
auth_module:
53+
- {{ $.Values.serviceMonitor.multipleTarget.sharedAuthModule.name }}
54+
{{- else }}
55+
auth_module:
56+
- client.{{ .name }}
57+
{{- end }}
58+
{{- end }}
59+
{{- end }}
60+
{{- if not .Values.serviceMonitor.multipleTarget.enabled -}}
1561
endpoints:
1662
- port: {{ .Values.service.name }}
1763
{{- if .Values.serviceMonitor.interval }}
@@ -37,6 +83,7 @@ spec:
3783
{{- with .Values.serviceMonitor.tlsConfig }}
3884
tlsConfig:
3985
{{- toYaml . | nindent 6 }}
86+
{{- end }}
4087
{{- end }}
4188
jobLabel: {{ template "prometheus-postgres-exporter.fullname" . }}
4289
namespaceSelector:

charts/prometheus-postgres-exporter/values.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ serviceMonitor:
5050
# TLS configuration to use when scraping the metric endpoint by Prometheus.
5151
# tlsConfig: {}
5252

53+
# Use multipleTarget mode
54+
multipleTarget:
55+
enabled: false
56+
# Use the same auth module for every target
57+
# The config file should have a section like [$name]
58+
sharedAuthModule:
59+
enabled: false
60+
name: ""
61+
62+
# Define each target's endpoint and name
63+
# When not using sharedAuthModule the config file should have one authModule for each target with key "client.$name"
64+
targets: []
65+
# - endpoint: pg01.local
66+
# name: pg01 (there needs to exist an authModule with key "client.pg01" if not using sharedAuthModule)
67+
# port: default 5432
68+
5369
prometheusRule:
5470
enabled: false
5571
additionalLabels: {}

0 commit comments

Comments
 (0)