From 7ad89a87fde8a92bd43bb9032dd761f64c17ea7e Mon Sep 17 00:00:00 2001 From: Alexander Zimmermann <7714821+alexzimmer96@users.noreply.github.com> Date: Sat, 22 Jun 2019 11:10:12 +0200 Subject: [PATCH] [stable/prometheus-redis-exporter] Adding abbility to use custom script (#14552) * Added support for custom LUA scripts Signed-off-by: Alexander Zimmermann * Removed unnecessary comments Signed-off-by: Alexander Zimmermann * Bumping chart version and removed whitespaces Signed-off-by: Alexander Zimmermann * Removed unnecessary comments Signed-off-by: Alexander Zimmermann * Added documentation for script.keyname parameter Signed-off-by: Alexander Zimmermann * Restored imagePullSecret-part Signed-off-by: Alexander Zimmermann --- stable/prometheus-redis-exporter/Chart.yaml | 2 +- stable/prometheus-redis-exporter/README.md | 34 +++++++++++++++++++ .../templates/deployment.yaml | 18 ++++++++++ stable/prometheus-redis-exporter/values.yaml | 15 +++++--- 4 files changed, 63 insertions(+), 6 deletions(-) diff --git a/stable/prometheus-redis-exporter/Chart.yaml b/stable/prometheus-redis-exporter/Chart.yaml index d1c965cc47..4133722640 100644 --- a/stable/prometheus-redis-exporter/Chart.yaml +++ b/stable/prometheus-redis-exporter/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v1 appVersion: 0.28.0 description: Prometheus exporter for Redis metrics name: prometheus-redis-exporter -version: 2.0.0 +version: 2.0.1 home: https://github.com/oliver006/redis_exporter sources: - https://github.com/oliver006/redis_exporter diff --git a/stable/prometheus-redis-exporter/README.md b/stable/prometheus-redis-exporter/README.md index 849246d4e5..556f37e6ef 100644 --- a/stable/prometheus-redis-exporter/README.md +++ b/stable/prometheus-redis-exporter/README.md @@ -66,6 +66,8 @@ The following table lists the configurable parameters and their default values. | `serviceMonitor.telemetryPath` | Path to redis-exporter telemtery-path | | | `serviceMonitor.labels` | Labels for the servicemonitor passed to Prometheus Operator | `{}` | | `serviceMonitor.timeout` | Timeout after which the scrape is ended | | +| `script.configmap` | Let you run a custom lua script from a configmap. The corresponding environment variable `REDIS_EXPORTER_SCRIPT` will be set automatically || +| `script.keyname` | Name of the key inside configmap which contains your script || For more information please refer to the [redis_exporter](https://github.com/oliver006/redis_exporter) documentation. @@ -82,3 +84,35 @@ Alternatively, a YAML file that specifies the values for the parameters can be p ```bash $ helm install --name my-release -f values.yaml stable/prometheus-redis-exporter ``` +### Using a custom LUA-Script +First, you need to deploy the script with a configmap. This is an example script from mentioned in the [redis_exporter-image repository](https://github.com/oliver006/redis_exporter/blob/master/contrib/sample_collect_script.lua) +```yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: prometheus-redis-exporter-script +data: + script: |- + -- Example collect script for -script option + -- This returns a Lua table with alternating keys and values. + -- Both keys and values must be strings, similar to a HGETALL result. + -- More info about Redis Lua scripting: https://redis.io/commands/eval + + local result = {} + + -- Add all keys and values from some hash in db 5 + redis.call("SELECT", 5) + local r = redis.call("HGETALL", "some-hash-with-stats") + if r ~= nil then + for _,v in ipairs(r) do + table.insert(result, v) -- alternating keys and values + end + end + + -- Set foo to 42 + table.insert(result, "foo") + table.insert(result, "42") -- note the string, use tostring() if needed + + return result +``` +If you want to use this script for collecting metrics, you could do this by just set `script.configmap` to the name of the configmap (e.g. `prometheus-redis-exporter-script`) and `script.keyname` to the configmap-key holding the script (eg. `script`). The required variables inside the container will be set automatically. diff --git a/stable/prometheus-redis-exporter/templates/deployment.yaml b/stable/prometheus-redis-exporter/templates/deployment.yaml index ed66b1994f..84b0c0ae91 100644 --- a/stable/prometheus-redis-exporter/templates/deployment.yaml +++ b/stable/prometheus-redis-exporter/templates/deployment.yaml @@ -42,8 +42,17 @@ spec: env: - name: REDIS_ADDR value: {{ join "," .Values.redisAddress }} +{{- if .Values.script }} + - name: REDIS_EXPORTER_SCRIPT + value: /script/script.lua +{{- end }} {{- if .Values.env }} {{ toYaml .Values.env | indent 12 }} +{{- end }} +{{- if .Values.script }} + volumeMounts: + - mountPath: /script + name: script-mount {{- end }} livenessProbe: httpGet: @@ -55,6 +64,15 @@ spec: port: exporter-port resources: {{ toYaml .Values.resources | indent 12 }} + {{- if .Values.script }} + volumes: + - name: script-mount + configMap: + name: {{ .Values.script.configmap }} + items: + - key: {{ .Values.script.keyname }} + path: script.lua + {{- end }} {{- if .Values.nodeSelector }} nodeSelector: {{ toYaml .Values.nodeSelector | indent 8 }} diff --git a/stable/prometheus-redis-exporter/values.yaml b/stable/prometheus-redis-exporter/values.yaml index 0790d82dda..50bc214c2d 100644 --- a/stable/prometheus-redis-exporter/values.yaml +++ b/stable/prometheus-redis-exporter/values.yaml @@ -18,11 +18,11 @@ image: extraArgs: {} # Additional Environment variables env: {} - # - name: REDIS_PASSWORD - # valueFrom: - # secretKeyRef: - # key: redis-password - # name: redis-config-0.0.2 +# - name: REDIS_PASSWORD +# valueFrom: +# secretKeyRef: +# key: redis-password +# name: redis-config-0.0.2 service: type: ClusterIP port: 9121 @@ -52,3 +52,8 @@ serviceMonitor: # labels: # Set timeout for scrape # timeout: 10s + +# Used to mount a LUA-Script via config map and use it for metrics-collection +# script: +# configmap: prometheus-redis-exporter-script +# keyname: script