Connect redis exporter and prometheus operator

2.5k views Asked by At

I have a Redis cluster and Redis-exporter in two separate deployments in the same namespace of a Kubernetes cluster. I am using Prometheus operator to monitor the cluster, but I can not find a way to set up the exporter and the operator. I have set up a service targeting the Redis exporter(check below) and a ServiceMonitor(also below). If I port forward to the Redis exporter service I can see the metrics. Also, the Redis exporter logs do not show issues.

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: foo
  name: redis-exporter
  labels:
    app: redis-exporter
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis-exporter
  template:
    metadata:
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9121"
      labels:
        app: redis-exporter
    spec:
      containers:
      - name: redis-exporter
        image: oliver006/redis_exporter:latest
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        env:
        - name: REDIS_ADDR
          value:  redis-cluster.foo.svc:6379
        ports:
        - containerPort: 9121

My service and servicemonitor

kind: Service
metadata:
  name: redis-external-exporter
  namespace: foo
  labels:
    app: redis
    k8s-app: redis-ext
  annotations:
    prometheus.io/scrape: 'true'
    prometheus.io/port: "9121"
spec:
  ports:
  - name: redis-ext
    port: 9121
    protocol: TCP
    targetPort: 9121
  selector:
    app: redis-exporter
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: redis-external-exporter
  namespace: bi-infra
  labels:
    app: redis-external-exporter
    k8s-app: redis-monitor
spec:
  jobLabel: app
  selector:
    matchLabels:
      app: redis-ext
  namespaceSelector:
    matchNames:
    - foo
  endpoints:
  - port: redis-ext
    interval: 30s
    honorLabels: true

If I switch to a sidecar Redis exporter next to the Redis cluster all is working properly. Has anyone faced such issue?

1

There are 1 answers

0
Zambozo On BEST ANSWER

I was missing spec.endpoints.path on the ServiceMonitor

Here is an example manifest from adding new scraping targets and troubleshooting tutorial.

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: monitoring-pili
  namespace: monitoring
  labels:
    app: pili-service-monitor
spec:
  selector:
    matchLabels:
      # Target app service
      app: pili
  endpoints:
  - interval: 15s
    path: /metrics    <---
    port: uwsgi
  namespaceSelector:
    matchNames:
    - default