From faec4db9eff070ad06093d01ef1b3110e4930fc9 Mon Sep 17 00:00:00 2001 From: j_r0dd <285797+jr0dd@users.noreply.github.com> Date: Mon, 13 Sep 2021 09:39:53 -0400 Subject: [PATCH] [unifi-poller] metrics refactor (#1182) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ᗪєνιη ᗷυнʟ --- charts/stable/unifi-poller/Chart.yaml | 2 +- charts/stable/unifi-poller/README.md | 23 +++++++--- .../unifi-poller/README_CHANGELOG.md.gotmpl | 7 +++ .../templates/prometheusrules.yaml | 27 +++++++++++ .../templates/servicemonitor.yaml | 19 ++++---- charts/stable/unifi-poller/values.yaml | 45 ++++++++++++------- 6 files changed, 94 insertions(+), 29 deletions(-) create mode 100644 charts/stable/unifi-poller/templates/prometheusrules.yaml diff --git a/charts/stable/unifi-poller/Chart.yaml b/charts/stable/unifi-poller/Chart.yaml index b6425efa..d70f7c4c 100644 --- a/charts/stable/unifi-poller/Chart.yaml +++ b/charts/stable/unifi-poller/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 appVersion: 2.1.3 description: Collect ALL UniFi Controller, Site, Device & Client Data - Export to InfluxDB or Prometheus name: unifi-poller -version: 9.0.0 +version: 10.0.0 kubeVersion: ">=1.16.0-0" keywords: - unifi diff --git a/charts/stable/unifi-poller/README.md b/charts/stable/unifi-poller/README.md index 09cf084f..08062fac 100644 --- a/charts/stable/unifi-poller/README.md +++ b/charts/stable/unifi-poller/README.md @@ -1,6 +1,6 @@ # unifi-poller -![Version: 9.0.0](https://img.shields.io/badge/Version-9.0.0-informational?style=flat-square) ![AppVersion: 2.1.3](https://img.shields.io/badge/AppVersion-2.1.3-informational?style=flat-square) +![Version: 10.0.0](https://img.shields.io/badge/Version-10.0.0-informational?style=flat-square) ![AppVersion: 2.1.3](https://img.shields.io/badge/AppVersion-2.1.3-informational?style=flat-square) Collect ALL UniFi Controller, Site, Device & Client Data - Export to InfluxDB or Prometheus @@ -87,10 +87,16 @@ N/A | influxdb.enabled | bool | `false` | Create an InfluxDB instance as a [unifi-poller storage backend](https://unifipoller.com/docs/dependencies/influxdb). See [bitnami/influxdb](https://github.com/bitnami/charts/tree/master/bitnami/influxdb) for more options. | | influxdb.persistence.enabled | bool | `false` | Enable persistence to store in a PV so data survives pod restarts. | | ingress.main.enabled | bool | `false` | Expose [unifi-poller's web interface](https://unifipoller.com/docs/advanced/webserver) (if enabled in the configuration) via the k8s ingress by setting this true. | -| prometheus.serviceMonitor.additionalLabels | object | `{}` | More labels to add to the ServiceMonitor resource. | -| prometheus.serviceMonitor.enabled | bool | `false` | Create a [ServiceMonitor](https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/design.md#servicemonitor) for the [unifi-poller prometheus exporter](https://unifipoller.com/docs/dependencies/prometheus) that is recognized by [prometheus-operator](https://github.com/prometheus-operator/prometheus-operator). This gets created in this chart's namespace. Note: this only creates a ServiceMonitor, not a prometheus instance. | -| prometheus.serviceMonitor.interval | string | `"1m"` | Prometheus [endpoint polling interval](https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/api.md#endpoint) for this ServiceMonitor (how often unifi-poller will be queried). | -| service.main.ports.http.port | int | `9130` | The port this prometheus exporter will listen on ([registered as 9130](https://github.com/prometheus/prometheus/wiki/Default-port-allocations)). This should match unifi-poller's [configured listen port](https://unifipoller.com/docs/install/configuration#prometheus). | +| metrics.enabled | bool | See values.yaml | Enable and configure a Prometheus serviceMonitor for the chart under this key. | +| metrics.prometheusRule | object | See values.yaml | Enable and configure Prometheus Rules for the chart under this key. | +| metrics.prometheusRule.rules | list | See prometheusrules.yaml | Configure additionial rules for the chart under this key. | +| metrics.serviceMonitor.interval | string | `"30s"` | | +| metrics.serviceMonitor.labels | object | `{}` | | +| metrics.serviceMonitor.scrapeTimeout | string | `"10s"` | | +| service.main.ports.http.enabled | bool | `false` | | +| service.main.ports.metrics.enabled | bool | `true` | | +| service.main.ports.metrics.port | int | `9130` | | +| service.main.ports.metrics.protocol | string | `"TCP"` | | ## Changelog @@ -98,6 +104,12 @@ All notable changes to this application Helm chart will be documented in this fi The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +### [10.0.0] + +#### Changed + +- **BREAKING**: Refactored Prometheus metrics section to add rules. Enabling metrics automatically enables the serviceMonitor. + ### [9.0.0] #### Changed @@ -113,6 +125,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - **BREAKING**: Change the default influxdb database name to match unifi-poller's default - Updates default unifi-poller version from 2.0.1 to 2.1.3 +[10.0.0]: #1000 [9.0.0]: #900 [8.0.0]: #800 diff --git a/charts/stable/unifi-poller/README_CHANGELOG.md.gotmpl b/charts/stable/unifi-poller/README_CHANGELOG.md.gotmpl index c6c35204..1dc446fc 100644 --- a/charts/stable/unifi-poller/README_CHANGELOG.md.gotmpl +++ b/charts/stable/unifi-poller/README_CHANGELOG.md.gotmpl @@ -9,6 +9,12 @@ All notable changes to this application Helm chart will be documented in this fi The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +### [10.0.0] + +#### Changed + +- **BREAKING**: Refactored Prometheus metrics section to add rules. Enabling metrics automatically enables the serviceMonitor. + ### [9.0.0] #### Changed @@ -24,6 +30,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - **BREAKING**: Change the default influxdb database name to match unifi-poller's default - Updates default unifi-poller version from 2.0.1 to 2.1.3 +[10.0.0]: #1000 [9.0.0]: #900 [8.0.0]: #800 {{- end -}} diff --git a/charts/stable/unifi-poller/templates/prometheusrules.yaml b/charts/stable/unifi-poller/templates/prometheusrules.yaml new file mode 100644 index 00000000..e80273d6 --- /dev/null +++ b/charts/stable/unifi-poller/templates/prometheusrules.yaml @@ -0,0 +1,27 @@ +{{- if and .Values.metrics.enabled .Values.metrics.prometheusRule.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: PrometheusRule +metadata: + name: {{ include "common.names.fullname" . }} + labels: + {{- include "common.labels" . | nindent 4 }} + {{- with .Values.metrics.prometheusRule.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + groups: + - name: {{ include "common.names.fullname" . }} + rules: + - alert: UnifiPollerAbsent + annotations: + description: Unifi Poller has disappeared from Prometheus service discovery. + summary: Unifi Poller is down. + expr: | + absent(up{job=~".*{{ include "common.names.fullname" . }}.*"} == 1) + for: 5m + labels: + severity: critical + {{- with .Values.metrics.prometheusRule.rules }} + {{- toYaml . | nindent 8 }} + {{- end }} +{{- end }} diff --git a/charts/stable/unifi-poller/templates/servicemonitor.yaml b/charts/stable/unifi-poller/templates/servicemonitor.yaml index 5fdcf649..b4245480 100644 --- a/charts/stable/unifi-poller/templates/servicemonitor.yaml +++ b/charts/stable/unifi-poller/templates/servicemonitor.yaml @@ -1,11 +1,11 @@ -{{- if .Values.prometheus.serviceMonitor.enabled }} +{{- if .Values.metrics.enabled }} apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: - name: {{ template "common.names.fullname" . }} + name: {{ include "common.names.fullname" . }} labels: {{- include "common.labels" . | nindent 4 }} - {{- with .Values.prometheus.serviceMonitor.additionalLabels }} + {{- with .Values.metrics.serviceMonitor.labels }} {{- toYaml . | nindent 4 }} {{- end }} spec: @@ -13,9 +13,12 @@ spec: matchLabels: {{- include "common.labels.selectorLabels" . | nindent 6 }} endpoints: - - port: http - {{- with .Values.prometheus.serviceMonitor.interval }} - interval: {{ . }} - {{- end }} - path: /metrics + - port: metrics + {{- with .Values.metrics.serviceMonitor.interval }} + interval: {{ . }} + {{- end }} + {{- with .Values.metrics.serviceMonitor.scrapeTimeout }} + scrapeTimeout: {{ . }} + {{- end }} + path: /metrics {{- end }} diff --git a/charts/stable/unifi-poller/values.yaml b/charts/stable/unifi-poller/values.yaml index 84326fd4..4a5bbf3e 100644 --- a/charts/stable/unifi-poller/values.yaml +++ b/charts/stable/unifi-poller/values.yaml @@ -28,8 +28,10 @@ service: main: ports: http: - # -- The port this prometheus exporter will listen on ([registered as 9130](https://github.com/prometheus/prometheus/wiki/Default-port-allocations)). - # This should match unifi-poller's [configured listen port](https://unifipoller.com/docs/install/configuration#prometheus). + enabled: false + metrics: + enabled: true + protocol: TCP port: 9130 ingress: @@ -38,19 +40,6 @@ ingress: # (if enabled in the configuration) via the k8s ingress by setting this true. enabled: false -prometheus: - serviceMonitor: - # -- Create a [ServiceMonitor](https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/design.md#servicemonitor) - # for the [unifi-poller prometheus exporter](https://unifipoller.com/docs/dependencies/prometheus) - # that is recognized by [prometheus-operator](https://github.com/prometheus-operator/prometheus-operator). - # This gets created in this chart's namespace. Note: this only creates a ServiceMonitor, not a prometheus instance. - enabled: false - # -- Prometheus [endpoint polling interval](https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/api.md#endpoint) - # for this ServiceMonitor (how often unifi-poller will be queried). - interval: 1m - # -- More labels to add to the ServiceMonitor resource. - additionalLabels: {} - influxdb: # -- Create an InfluxDB instance as a [unifi-poller storage backend](https://unifipoller.com/docs/dependencies/influxdb). # See [bitnami/influxdb](https://github.com/bitnami/charts/tree/master/bitnami/influxdb) for more options. @@ -68,3 +57,29 @@ influxdb: enabled: false # storageClass: "" # size: 8Gi + +metrics: + # -- Enable and configure a Prometheus serviceMonitor for the chart under this key. + # @default -- See values.yaml + enabled: false + serviceMonitor: + interval: 1m + scrapeTimeout: 30s + labels: {} + # -- Enable and configure Prometheus Rules for the chart under this key. + # @default -- See values.yaml + prometheusRule: + enabled: false + labels: {} + # -- Configure additionial rules for the chart under this key. + # @default -- See prometheusrules.yaml + rules: [] + # - alert: UnifiPollerAbsent + # annotations: + # description: Unifi Poller has disappeared from Prometheus service discovery. + # summary: Unifi Poller is down. + # expr: | + # absent(up{job=~".*unifi-poller.*"} == 1) + # for: 5m + # labels: + # severity: critical