From 0d4676b87b1025ee36375109500d5052f6da27a8 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 23 May 2021 17:05:12 +0200 Subject: [PATCH 1/2] [fronius-exporter] Add prometheus service monitor --- charts/fronius-exporter/Chart.yaml | 2 +- charts/fronius-exporter/README.gotmpl.md | 20 +++++++++++ charts/fronius-exporter/README.md | 27 ++++++++++++++- .../templates/prometheus/service-monitor.yaml | 33 +++++++++++++++++++ charts/fronius-exporter/values.yaml | 12 +++++++ 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 charts/fronius-exporter/templates/prometheus/service-monitor.yaml diff --git a/charts/fronius-exporter/Chart.yaml b/charts/fronius-exporter/Chart.yaml index 5164f57..8774aba 100644 --- a/charts/fronius-exporter/Chart.yaml +++ b/charts/fronius-exporter/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.6.0 +version: 0.7.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/charts/fronius-exporter/README.gotmpl.md b/charts/fronius-exporter/README.gotmpl.md index e69de29..0abf404 100644 --- a/charts/fronius-exporter/README.gotmpl.md +++ b/charts/fronius-exporter/README.gotmpl.md @@ -0,0 +1,20 @@ + +## Prometheus Operator + +This chart features templates for [Prometheus Operator][prometheus-operator] if desired. +If you'd like to add additional Prometheus labels to all metrics, you could make use of relabelings: + +```yaml +serviceMonitor: + enabled: true + metricRelabelings: + - targetLabel: site + replacement: my-home +``` + + +[resource-units]: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#resource-units-in-kubernetes +[prometheus-operator]: https://github.com/coreos/prometheus-operator +[prom-relabel-config]: https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/api.md#relabelconfig diff --git a/charts/fronius-exporter/README.md b/charts/fronius-exporter/README.md index a63155c..819bd5f 100644 --- a/charts/fronius-exporter/README.md +++ b/charts/fronius-exporter/README.md @@ -1,6 +1,6 @@ # fronius-exporter -![Version: 0.6.0](https://img.shields.io/badge/Version-0.6.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) +![Version: 0.7.0](https://img.shields.io/badge/Version-0.7.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) Prometheus Exporter for Fronius Symo Photovoltaics @@ -13,6 +13,26 @@ helm repo add ccremer https://ccremer.github.io/charts helm install fronius-exporter ccremer/fronius-exporter ``` +## Prometheus Operator + +This chart features templates for [Prometheus Operator][prometheus-operator] if desired. +If you'd like to add additional Prometheus labels to all metrics, you could make use of relabelings: + +```yaml +serviceMonitor: + enabled: true + metricRelabelings: + - targetLabel: site + replacement: my-home +``` + + +[resource-units]: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#resource-units-in-kubernetes +[prometheus-operator]: https://github.com/coreos/prometheus-operator +[prom-relabel-config]: https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/api.md#relabelconfig + ## Source Code * @@ -51,6 +71,11 @@ helm install fronius-exporter ccremer/fronius-exporter | serviceAccount.annotations | object | `{}` | Annotations to add to the service account | | serviceAccount.create | bool | `true` | Specifies whether a service account should be created | | serviceAccount.name | string | `""` | The name of the service account to use. If not set and `create` is `true`, a name is generated using the fullname template | +| serviceMonitor.additionalLabels | object | `{}` | Add custom labels to the ServiceMonitor object | +| serviceMonitor.enabled | bool | `false` | Deploy a ServiceMonitor object for Prometheus. Requires an installed [Prometheus Operator][prometheus-operator]. | +| serviceMonitor.metricRelabelings | list | `[]` | Add relabeling configs before ingestion, see [RelabelConfig][prom-relabel-config]. | +| serviceMonitor.namespace | string | `""` | Namespace in which to deploy the ServiceMonitor, defaults to release namespace. | +| serviceMonitor.scrapeInterval | string | `""` | Override default scrape interval from Prometheus | | telegraf.enabled | bool | `false` | Whether to enable Telegraf sidecar for Influxdb | | telegraf.globalTags | object | `{}` | A dict with `key: value` to add to `global_tags` config | | telegraf.image.registry | string | `"docker.io"` | | diff --git a/charts/fronius-exporter/templates/prometheus/service-monitor.yaml b/charts/fronius-exporter/templates/prometheus/service-monitor.yaml new file mode 100644 index 0000000..f929c0d --- /dev/null +++ b/charts/fronius-exporter/templates/prometheus/service-monitor.yaml @@ -0,0 +1,33 @@ +{{- if .Values.serviceMonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ template "fronius-exporter.fullname" . }}-servicemonitor + namespace: {{ default .Release.Namespace .Values.serviceMonitor.namespace }} + labels: + {{- include "fronius-exporter.labels" . | nindent 4 }} + {{- with .Values.serviceMonitor.additionalLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} +{{- if .Values.serviceMonitor.annotations }} + annotations: +{{ toYaml .Values.serviceMonitor.annotations | indent 4 }} +{{- end }} +spec: + selector: + matchLabels: + {{- include "fronius-exporter.selectorLabels" . | nindent 6 }} + {{- if .Values.serviceMonitor.namespace }} + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} + {{- end }} + endpoints: + - path: /metrics + port: http + interval: {{ .Values.serviceMonitor.scrapeInterval }} + {{- with .Values.serviceMonitor.metricRelabelings }} + metricRelabelings: + {{- toYaml . | nindent 8 }} + {{- end }} +{{- end -}} diff --git a/charts/fronius-exporter/values.yaml b/charts/fronius-exporter/values.yaml index 2d7f773..881a814 100644 --- a/charts/fronius-exporter/values.yaml +++ b/charts/fronius-exporter/values.yaml @@ -114,3 +114,15 @@ nodeSelector: {} tolerations: [] affinity: {} + +serviceMonitor: + # -- Deploy a ServiceMonitor object for Prometheus. Requires an installed [Prometheus Operator][prometheus-operator]. + enabled: false + # -- Namespace in which to deploy the ServiceMonitor, defaults to release namespace. + namespace: "" + # -- Override default scrape interval from Prometheus + scrapeInterval: "" + # -- Add relabeling configs before ingestion, see [RelabelConfig][prom-relabel-config]. + metricRelabelings: [] + # -- Add custom labels to the ServiceMonitor object + additionalLabels: {} From f8a26f299c91294d18c9d7ca12b3c01c9940ef8b Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 13 Jun 2021 11:00:44 +0200 Subject: [PATCH 2/2] [fronius-exporter] Fix unit test for telegraf --- charts/fronius-exporter/test/telegraf_secret_test.go | 4 ++-- charts/fronius-exporter/test/values/telegraf_1.yaml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/charts/fronius-exporter/test/telegraf_secret_test.go b/charts/fronius-exporter/test/telegraf_secret_test.go index 7a6a548..4ab6f4a 100644 --- a/charts/fronius-exporter/test/telegraf_secret_test.go +++ b/charts/fronius-exporter/test/telegraf_secret_test.go @@ -19,8 +19,8 @@ func Test_TelegrafSecret_WhenDefiningGlobalTags_ThenRenderEachKeyValue(t *testin ValuesFiles: []string{"values/telegraf_1.yaml"}, } - expectedLine1 := "key1 = value1" - expectedLine2 := "key2 = value2" + expectedLine1 := "key1 = \"value1\"" + expectedLine2 := "key2 = \"value2\"" expectedSection := "[global_tags]" config := "telegraf.conf" secret := renderSecret(t, options, false, tplTelegrafSecret) diff --git a/charts/fronius-exporter/test/values/telegraf_1.yaml b/charts/fronius-exporter/test/values/telegraf_1.yaml index 890ef31..2bddf35 100644 --- a/charts/fronius-exporter/test/values/telegraf_1.yaml +++ b/charts/fronius-exporter/test/values/telegraf_1.yaml @@ -1,4 +1,5 @@ telegraf: + enabled: true globalTags: key1: value1 key2: value2