Monitoring Redis with Prometheus Exporter and Grafana
Rayan Slim
Posted on October 18, 2024
A Prometheus exporter is a tool that collects metrics from a specific system and exposes them in a format that Prometheus can scrape. The Redis Prometheus Exporter specifically collects metrics from Redis databases.
In this article, you will deploy Redis alongside the Redis Prometheus Exporter to scrape metrics from your database. You'll then visualize these metrics using a Grafana dashboard.
Table of Contents
- Clone the Repository
- Deploy Redis Resources
- Install Redis Exporter
- Verify Metrics
- Deploy Grafana Dashboard
- Access Grafana
- Cleaning Up Resources
Prerequisites
This guide assumes you have already installed Helm and set up Prometheus in your Kubernetes cluster. If you haven't done this yet, please check out this article on setting up Prometheus with Kubernetes before continuing with this guide.
Clone the Repository
First, clone the repository containing the necessary Redis resources, exporter configuration, and dashboard:
git clone https://github.com/rslim087a/redis-prometheus-sample
cd redis-prometheus-sample
Deploy Redis Resources
Create the namespace database-monitoring
if it doesn't already exist:
kubectl create namespace database-monitoring
Deploy the Redis resources (Secret, Service, and StatefulSet) using the following command:
kubectl apply -f redis/
This command applies all the Kubernetes manifests in the redis/
directory, setting up your Redis instance.
Install Redis Exporter
Add the Prometheus Community Helm repository and update it:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
Now, install the Redis Exporter using the custom values file:
helm install redis-exporter prometheus-community/prometheus-redis-exporter \
-f redis-exporter/redis-exporter-values.yaml \
-n database-monitoring
Let's examine the custom values in redis-exporter-values.yaml
:
# Redis Exporter Helm Values
redisAddress: redis://redis:6379
auth:
enabled: true
secret:
name: redis-secret
key: REDIS_PASSWORD
serviceMonitor:
enabled: true
labels:
release: prometheus
service:
type: ClusterIP
port: 9121
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
Explanation of key fields:
- redisAddress: Specifies the Redis connection details.
-
auth: Configures authentication for Redis.
-
enabled: true
: Activates authentication. -
secret
: Specifies the Kubernetes secret containing the Redis password.
-
-
serviceMonitor: Configuration for Prometheus to automatically discover and scrape metrics from the Redis exporter.
-
enabled: true
: Activates the creation of a ServiceMonitor resource. -
labels
: Ensures that the correct Prometheus instance picks up this ServiceMonitor.
-
- service: Configures the Kubernetes service for the exporter.
- resources: Sets resource limits and requests for the exporter.
Verify Metrics
Port-forward the Redis Exporter pod and check the metrics:
kubectl port-forward svc/redis-exporter-prometheus-redis-exporter 9121:9121 -n database-monitoring &
curl http://localhost:9121/metrics
After verifying, stop the port-forward:
kill %1
Deploy Grafana Dashboard
Apply the Grafana dashboard ConfigMap:
kubectl apply -f grafana -n monitoring
This creates a ConfigMap with the grafana_dashboard: "1"
label, which Grafana will automatically detect and import.
Access Grafana
Port-forward the Grafana service:
kubectl port-forward svc/prometheus-grafana 3000:80 -n monitoring &
Access Grafana at http://localhost:3000 using the default credentials (usually admin/prom-operator).
The Redis dashboard should now be available in your Grafana instance. To find it, follow these steps:
- Log into Grafana
- Click on the "Dashboards" icon in the left sidebar
- Select "Browse"
- Look for a dashboard named "Redis Dashboard for Prometheus"
This dashboard will provide detailed insights into your Redis performance and health, including metrics on connections, memory usage, operations per second, and more.
Cleaning Up Resources
If you've deployed this setup for testing or learning purposes, you may want to clean up the resources afterwards to avoid unnecessary costs or cluster clutter.
Here are the steps to remove the deployed resources:
Delete the Redis Exporter:
helm uninstall redis-exporter -n database-monitoring
If you deployed Redis as part of this guide:
kubectl delete -f redis/ -n database-monitoring
Remove the Grafana dashboard:
kubectl delete -f grafana -n monitoring
If you no longer need the Prometheus Community Helm repository:
helm repo remove prometheus-community
Finally, delete the namespace:
kubectl delete namespace database-monitoring
Kubernetes Training
If you found this guide helpful, check out our Kubernetes Training course
Posted on October 18, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.