From 9601462c77d57a5999d0261dd968c9cd827a12af Mon Sep 17 00:00:00 2001 From: Alex Morbo <alex@morbo.ru> Date: Sat, 15 Feb 2025 13:56:06 +0300 Subject: [PATCH] Added support for prometheus metrics and service-monitor (#1387) --- charts/graylog/Chart.yaml | 2 +- charts/graylog/README.md | 22 ++++++++- charts/graylog/RELEASENOTES.md | 2 + charts/graylog/templates/_helpers.tpl | 6 +++ charts/graylog/templates/service-metrics.yaml | 34 ++++++++++++++ charts/graylog/templates/servicemonitor.yaml | 36 ++++++++++++++ charts/graylog/templates/statefulset.yaml | 5 ++ charts/graylog/values.yaml | 47 +++++++++++++++++++ 8 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 charts/graylog/templates/service-metrics.yaml create mode 100644 charts/graylog/templates/servicemonitor.yaml diff --git a/charts/graylog/Chart.yaml b/charts/graylog/Chart.yaml index 3e9af8c8..2d8e2dd5 100644 --- a/charts/graylog/Chart.yaml +++ b/charts/graylog/Chart.yaml @@ -7,7 +7,7 @@ type: application maintainers: - name: groundhog2k -version: "0.9.6" +version: "0.9.7" appVersion: "6.1.6" diff --git a/charts/graylog/README.md b/charts/graylog/README.md index da89f115..fa8a4c9b 100644 --- a/charts/graylog/README.md +++ b/charts/graylog/README.md @@ -1,6 +1,6 @@ # Graylog -   +   ## Changelog @@ -223,3 +223,23 @@ The policyTypes will be automatically set | settings.smtp.subjectPrefix | string | `"[graylog]"` | Mail subject prefix | Further Graylog parameter can be set via environment variables (see Deployment parameter: `env:`) + +## Metrics support parameters + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| metrics.enabled | bool | `false` | Enable metrics support | +| metrics.service.type | string | `"ClusterIP"` | Service type (not available when haMode is enabled) | +| metrics.service.servicePort | int | `9833` | Redis metrics exporter service port | +| metrics.service.containerPort | int | `9833` | Redis metrics exporter container port | +| metrics.service.nodePort | int | `nil` | The node port (only relevant for type LoadBalancer or NodePort - not available when haMode is enabled) | +| metrics.service.clusterIP | string | `nil` | The cluster ip address (only relevant for type LoadBalancer or NodePort) | +| metrics.service.loadBalancerIP | string | `nil` | The load balancer ip address (only relevant for type LoadBalancer - not available when haMode is enabled) | +| metrics.service.annotations | object | `{}` | Additional service annotations | +| metrics.service.lables | object | `{}` | Additional service labels | +| metrics.serviceMonitor.additionalLabels | object | `{}` | Additional labels for the service monitor object | +| metrics.serviceMonitor.annotations | object | `{}` | Annotations for the service monitor object | +| metrics.serviceMonitor.interval | Duration | `nil` | Scrape interval for prometheus | +| metrics.serviceMonitor.scrapeTimeout | Duration | `nil` | Scrape timeout value | +| metrics.serviceMonitor.extraEndpointParameters | object | `nil` | Extra parameters rendered to the [service monitor endpoint](https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#endpoint) | +| metrics.serviceMonitor.extraParameters | object | `nil` | Extra parameters rendered to the [service monitor object](https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#servicemonitorspec) | diff --git a/charts/graylog/RELEASENOTES.md b/charts/graylog/RELEASENOTES.md index 336e3d56..6dcca0c4 100644 --- a/charts/graylog/RELEASENOTES.md +++ b/charts/graylog/RELEASENOTES.md @@ -86,4 +86,6 @@ | 0.9.4 | 6.1.4 | Updated chart for Graylog 6.1.4 | | 0.9.5 | 6.1.5 | Updated chart for Graylog 6.1.5 | | 0.9.6 | 6.1.6 | Updated chart for Graylog 6.1.6 | +| 0.9.7 | 6.1.6 | Added support for prometheus metrics and service-monitor | | | | | + diff --git a/charts/graylog/templates/_helpers.tpl b/charts/graylog/templates/_helpers.tpl index ec041e45..8fe004aa 100644 --- a/charts/graylog/templates/_helpers.tpl +++ b/charts/graylog/templates/_helpers.tpl @@ -156,4 +156,10 @@ Graylog settings via environment variables value: {{ .Values.initGeoIPDatabase.proxy | quote }} {{- end }} {{- end }} +{{- if .Values.metrics.enabled }} +- name: GRAYLOG_PROMETHEUS_EXPORTER_ENABLED + value: {{ .Values.metrics.enabled | quote }} +- name: GRAYLOG_PROMETHEUS_EXPORTER_BIND_ADDRESS + value: "0.0.0.0:{{ .Values.metrics.service.servicePort }}" +{{- end }} {{- end }} diff --git a/charts/graylog/templates/service-metrics.yaml b/charts/graylog/templates/service-metrics.yaml new file mode 100644 index 00000000..ea9af0b1 --- /dev/null +++ b/charts/graylog/templates/service-metrics.yaml @@ -0,0 +1,34 @@ +{{- if and .Values.metrics.enabled .Values.metrics.service.enabled }} +apiVersion: v1 +kind: Service +metadata: + name: {{ include "graylog.fullname" . }}-metrics + labels: + {{- include "graylog.labels" . | nindent 4 }} + graylog/metrics-service: {{ include "graylog.fullname" . }}-metrics + {{- with .Values.metrics.service.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.metrics.service.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + ports: + - port: {{ .Values.metrics.service.servicePort }} + targetPort: exporter + protocol: TCP + name: exporter + {{- if and ( or (eq .Values.metrics.service.type "LoadBalancer") (eq .Values.metrics.service.type "NodePort") ) (.Values.metrics.service.nodePort) }} + nodePort: {{ .Values.service.nodePort }} + {{- end }} + type: {{ .Values.metrics.service.type }} + {{- if and (eq .Values.metrics.service.type "LoadBalancer") (.Values.metrics.service.loadBalancerIP) }} + loadBalancerIP: {{ .Values.metrics.service.loadBalancerIP }} + {{- end }} + {{- if .Values.metrics.service.clusterIP }} + clusterIP: {{ .Values.metrics.service.clusterIP }} + {{- end }} + selector: + {{- include "graylog.selectorLabels" . | nindent 4 }} +{{- end }} \ No newline at end of file diff --git a/charts/graylog/templates/servicemonitor.yaml b/charts/graylog/templates/servicemonitor.yaml new file mode 100644 index 00000000..b8750f55 --- /dev/null +++ b/charts/graylog/templates/servicemonitor.yaml @@ -0,0 +1,36 @@ +{{- if and .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "graylog.fullname" . }} + labels: + {{- include "graylog.labels" . | nindent 4 }} + {{- with .Values.metrics.serviceMonitor.additionalLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.metrics.serviceMonitor.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + endpoints: + - port: "exporter" + path: {{ .Values.metrics.serviceMonitor.path }} + scheme: {{ .Values.metrics.serviceMonitor.scheme }} + {{- if .Values.metrics.serviceMonitor.interval }} + interval: {{ .Values.metrics.serviceMonitor.interval }} + {{- end }} + {{- if .Values.metrics.serviceMonitor.scrapeTimeout }} + scrapeTimeout: {{ .Values.metrics.serviceMonitor.scrapeTimeout }} + {{- end }} + {{- with .Values.metrics.serviceMonitor.extraEndpointParameters }} + {{- toYaml . | nindent 6 }} + {{- end }} + {{- with .Values.metrics.serviceMonitor.extraParameters }} + {{- toYaml . | nindent 2 }} + {{- end }} + selector: + matchLabels: + {{- include "graylog.selectorLabels" . | nindent 6 }} + graylog/metrics-service: {{ include "graylog.fullname" . }}-metrics +{{- end }} \ No newline at end of file diff --git a/charts/graylog/templates/statefulset.yaml b/charts/graylog/templates/statefulset.yaml index 830825d1..25621157 100644 --- a/charts/graylog/templates/statefulset.yaml +++ b/charts/graylog/templates/statefulset.yaml @@ -88,6 +88,11 @@ spec: - name: http containerPort: 9000 protocol: TCP + {{- if .Values.metrics.enabled }} + - name: exporter + containerPort: {{ .Values.metrics.service.containerPort }} + protocol: TCP + {{- end }} {{- range $service := .Values.extraServices }} - name: {{ $service.name }} containerPort: {{ $service.containerPort}} diff --git a/charts/graylog/values.yaml b/charts/graylog/values.yaml index a3656b55..c2bcf49a 100644 --- a/charts/graylog/values.yaml +++ b/charts/graylog/values.yaml @@ -62,6 +62,53 @@ securityContext: runAsGroup: 1100 runAsUser: 1100 +## Prometheus metrics and service monitor configuration +metrics: + ## Enable metrics export + enabled: false + + ## Exporter service configuration + service: + ## Enable metrics service + enabled: true + ## Type of service (not available when haMode is enabled) + type: ClusterIP + ## Valkey exporter service port + servicePort: 9833 + ## Valkey exporter container port + containerPort: 9833 + ## The node port (only relevant for type LoadBalancer or NodePort - not available when haMode is enabled) + nodePort: + ## The cluster ip address (only relevant for type LoadBalancer or NodePort) + clusterIP: + ## The loadbalancer ip address (only relevant for type LoadBalancer - not available when haMode is enabled) + loadBalancerIP: + # Annotations to add to the service + annotations: {} + # Labels to add to the service + labels: {} + + ## Prometheus service monitor configuration + serviceMonitor: + ## Enable service monitor + enabled: true + ## Additional labels for the service monitor object + additionalLabels: {} + ## Annotations for the service monitor object + annotations: {} + ## The scrape interval for prometheus + # interval: + ## The scrape timeout value + # scrapeTimeout: + ## Extra parameters rendered to the service monitor endpoint + extraEndpointParameters: {} + ## Extra parameters rendered to the service monitor + extraParameters: {} + ## Path to metrics + path: "/api/metrics/prometheus" + ## Scheme to use for metrics endpoint + scheme: http + ## Default Graylog service port (default web service port) service: type: ClusterIP -- GitLab