From 970315e41e36645f601c793c722caaa1959a4a70 Mon Sep 17 00:00:00 2001 From: Dimitrios Karagiannis Date: Tue, 13 Aug 2019 08:17:41 +0100 Subject: [PATCH] [stable/prometheus-postgres-exporter]: add the ability to create a ServiceMonitor (#14918) * Add the ability to create a ServiceMonitor Signed-off-by: Dimitrios Karagiannis This is intended for users of the prometheus-operator helm chart. * Update README with serviceMonitor values Signed-off-by: Dimitrios Karagiannis * Remove missed comment Signed-off-by: Dimitrios Karagiannis * Update chart version Signed-off-by: Dimitrios Karagiannis --- .../prometheus-postgres-exporter/Chart.yaml | 2 +- stable/prometheus-postgres-exporter/README.md | 6 ++++ .../templates/servicemonitor.yaml | 33 +++++++++++++++++++ .../prometheus-postgres-exporter/values.yaml | 14 ++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 stable/prometheus-postgres-exporter/templates/servicemonitor.yaml diff --git a/stable/prometheus-postgres-exporter/Chart.yaml b/stable/prometheus-postgres-exporter/Chart.yaml index 6cdf37eb1d..06f21e6d61 100644 --- a/stable/prometheus-postgres-exporter/Chart.yaml +++ b/stable/prometheus-postgres-exporter/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v1 appVersion: "0.5.1" description: A Helm chart for prometheus postgres-exporter name: prometheus-postgres-exporter -version: 0.7.1 +version: 0.7.2 home: https://github.com/wrouesnel/postgres_exporter sources: - https://github.com/wrouesnel/postgres_exporter diff --git a/stable/prometheus-postgres-exporter/README.md b/stable/prometheus-postgres-exporter/README.md index 7621428647..56d3221a9b 100644 --- a/stable/prometheus-postgres-exporter/README.md +++ b/stable/prometheus-postgres-exporter/README.md @@ -47,6 +47,12 @@ The following table lists the configurable parameters of the postgres Exporter c | `service.targetPort` | The target port of the container | `9187` | | `service.name` | Name of the service port | `http` | | `service.labels` | Labels to add to the service | `{}` | +| `servicemonitor.enabled` | Use servicemonitor from prometheus operator | `false` | +| `servicemonitor.namespace` | Namespace thes Servicemonitor is installed in | | +| `servicemonitor.interval` | How frequently Prometheus should scrape | | +| `servicemonitor.telemetryPath` | path to cloudwatch-exporter telemtery-path | | +| `servicemonitor.labels` | labels for the ServiceMonitor passed to Prometheus Operator | `{}` | +| `servicemonitor.timeout` | Timeout after which the scrape is ended | | | `resources` | | `{}` | | `config.datasource` | Postgresql datasource configuration | see [values.yaml](values.yaml) | | `config.queries` | SQL queries that the exporter will run | [postgres exporter defaults](https://github.com/wrouesnel/postgres_exporter/blob/master/queries.yaml) | diff --git a/stable/prometheus-postgres-exporter/templates/servicemonitor.yaml b/stable/prometheus-postgres-exporter/templates/servicemonitor.yaml new file mode 100644 index 0000000000..2e89c27e2e --- /dev/null +++ b/stable/prometheus-postgres-exporter/templates/servicemonitor.yaml @@ -0,0 +1,33 @@ +{{- if and ( .Capabilities.APIVersions.Has "monitoring.coreos.com/v1" ) ( .Values.serviceMonitor.enabled ) }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: +{{- if .Values.serviceMonitor.labels }} + labels: +{{ toYaml .Values.serviceMonitor.labels | indent 4}} +{{- end }} + name: {{ template "prometheus-postgres-exporter.fullname" . }} +{{- if .Values.serviceMonitor.namespace }} + namespace: {{ .Values.serviceMonitor.namespace }} +{{- end }} +spec: + endpoints: + - targetPort: {{ .Values.service.name }} +{{- if .Values.serviceMonitor.interval }} + interval: {{ .Values.serviceMonitor.interval }} +{{- end }} +{{- if .Values.serviceMonitor.telemetryPath }} + path: {{ .Values.serviceMonitor.telemetryPath }} +{{- end }} +{{- if .Values.serviceMonitor.timeout }} + scrapeTimeout: {{ .Values.serviceMonitor.timeout }} +{{- end }} + jobLabel: {{ template "prometheus-postgres-exporter.fullname" . }} + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} + selector: + matchLabels: + app: {{ template "prometheus-postgres-exporter.name" . }} + release: {{ .Release.Name }} +{{- end }} diff --git a/stable/prometheus-postgres-exporter/values.yaml b/stable/prometheus-postgres-exporter/values.yaml index 816d5f3ff3..f24fcfa2c1 100644 --- a/stable/prometheus-postgres-exporter/values.yaml +++ b/stable/prometheus-postgres-exporter/values.yaml @@ -17,6 +17,20 @@ service: labels: {} annotations: {} +serviceMonitor: + # When set true then use a ServiceMonitor to configure scraping + enabled: false + # Set the namespace the ServiceMonitor should be deployed + # namespace: monitoring + # Set how frequently Prometheus should scrape + # interval: 30s + # Set path to cloudwatch-exporter telemtery-path + # telemetryPath: /metrics + # Set labels for the ServiceMonitor, use this to define your scrape label for Prometheus Operator + # labels: + # Set timeout for scrape + # timeout: 10s + resources: {} # We usually recommend not to specify default resources and to leave this as a conscious # choice for the user. This also increases chances charts run on environments with little