Skip to content

Commit

Permalink
[prometheus-postgres-exporter] Implement multiple target in service m…
Browse files Browse the repository at this point in the history
…onitor (#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]>
  • Loading branch information
festeveira and zanhsieh authored Dec 9, 2024
1 parent d53ec4d commit aaa91c9
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion charts/prometheus-postgres-exporter/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
appVersion: "v0.16.0"
description: A Helm chart for prometheus postgres-exporter
name: prometheus-postgres-exporter
version: 6.6.0
version: 6.7.0
home: https://github.com/prometheus-community/postgres_exporter
sources:
- https://github.com/prometheus-community/postgres_exporter
Expand Down
47 changes: 47 additions & 0 deletions charts/prometheus-postgres-exporter/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,52 @@ metadata:
namespace: {{ .Values.serviceMonitor.namespace }}
{{- end }}
spec:
{{- if .Values.serviceMonitor.multipleTarget.enabled }}
endpoints:
{{- range .Values.serviceMonitor.multipleTarget.targets }}
- path: /probe
port: {{ $.Values.service.name }}
{{- if $.Values.serviceMonitor.interval }}
interval: {{ $.Values.serviceMonitor.interval }}
{{- end }}
{{- if $.Values.serviceMonitor.timeout }}
scrapeTimeout: {{ $.Values.serviceMonitor.timeout }}
{{- end }}
{{- if $.Values.serviceMonitor.scheme }}
scheme: {{ $.Values.serviceMonitor.scheme }}
{{- end }}
{{- with $.Values.serviceMonitor.tlsConfig }}
tlsConfig:
{{- toYaml . | nindent 6 }}
{{- 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 5432 }}
{{- if $.Values.serviceMonitor.multipleTarget.sharedAuthModule.enabled }}
auth_module:
- {{ $.Values.serviceMonitor.multipleTarget.sharedAuthModule.name }}
{{- else }}
auth_module:
- client.{{ .name }}
{{- end }}
{{- end }}
{{- end }}
{{- if not .Values.serviceMonitor.multipleTarget.enabled -}}
endpoints:
- port: {{ .Values.service.name }}
{{- if .Values.serviceMonitor.interval }}
Expand All @@ -37,6 +83,7 @@ spec:
{{- with .Values.serviceMonitor.tlsConfig }}
tlsConfig:
{{- toYaml . | nindent 6 }}
{{- end }}
{{- end }}
jobLabel: {{ template "prometheus-postgres-exporter.fullname" . }}
namespaceSelector:
Expand Down
16 changes: 16 additions & 0 deletions charts/prometheus-postgres-exporter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ serviceMonitor:
# TLS configuration to use when scraping the metric endpoint by Prometheus.
# tlsConfig: {}

# Use multipleTarget mode
multipleTarget:
enabled: false
# Use the same auth module for every target
# The config file should have a section like [$name]
sharedAuthModule:
enabled: false
name: ""

# Define each target's endpoint and name
# When not using sharedAuthModule the config file should have one authModule for each target with key "client.$name"
targets: []
# - endpoint: pg01.local
# name: pg01 (there needs to exist an authModule with key "client.pg01" if not using sharedAuthModule)
# port: default 5432

prometheusRule:
enabled: false
additionalLabels: {}
Expand Down

0 comments on commit aaa91c9

Please sign in to comment.