DEV Community

Cover image for How to monitor Redis with Prometheus and Grafana | Docker
Nelson Hernández
Nelson Hernández

Posted on • Edited on

How to monitor Redis with Prometheus and Grafana | Docker

For this example we will use Docker compose to be able to run all the services

  1. Docker Compose


version: "3.9"
services:
  grafana:
    image: grafana/grafana
    ports:
      - 3000:3000
  prometheus:
    image: prom/prometheus
    container_name: prometheus
    ports:
      - 9090:9090
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
  redis:
    image: "bitnami/redis:latest"
    ports:
      - 6379:6379
    environment:
      - REDIS_REPLICATION_MODE=master
      - REDIS_PASSWORD=my_master_password

  redis-exporter:
    image: oliver006/redis_exporter
    ports:
      - 9121:9121
    restart: unless-stopped
    environment:
      REDIS_ADDR: "redis:6379"
      REDIS_USER: null
      REDIS_PASSWORD: my_master_password
    links:
      - redis
      - prometheus



Enter fullscreen mode Exit fullscreen mode

2.Prometheus File Settings (prometheus.yml)



global:
  scrape_interval:     15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
  - job_name: redis-exporter
    static_configs:
      - targets: ['redis-exporter:9121']



Enter fullscreen mode Exit fullscreen mode

3.Run Docker Compose



docker-compose up


Enter fullscreen mode Exit fullscreen mode

4.Check status of Prometheus and Redis Exporter



http://localhost:9090/targets


Enter fullscreen mode Exit fullscreen mode

Image description

5.Visit Grafana Dashboard

Default

User: admin
Password: admin



http://localhost:3000


Enter fullscreen mode Exit fullscreen mode

Image description

6.Add data source

Image description

Save and test

Image description

7.Import Redis Dashboard for Prometheus

For this we will use a Dashboard created by the community

Redis Dashboard for Prometheus

https://grafana.com/grafana/dashboards/763

8.Import JSON or code

Image description

Import JSON of code

Code: 763

JSON:
https://grafana.com/api/dashboards/763/revisions/3/download

9.Dashboard

Image description

Code of example (GitHub Gist)
https://gist.github.com/nelsoncode019/722727fdba11d846e39dc99f8064f7fe

Top comments (5)

Collapse
 
ianvaughan profile image
Ian Vaughan

Step 6 I get:
Error reading Prometheus: Post "localhost:9090/api/v1/query": dial tcp 127.0.0.1:9090: connect: connection refused

Collapse
 
nelsonmendezz_ profile image
Nelson Hernández

you must write prometheus:9090
to access the Internal Docker network

Collapse
 
ianvaughan profile image
Ian Vaughan

Ah I missed that, thanks a lot!

Collapse
 
railsstudent profile image
Connie Leung

Very useful. Just did a POC based on this blog post.
Now, I need to pitch to my cloud engineer lead to implement it.

Collapse
 
railsstudent profile image
Connie Leung

Found a mistake in docker-compose.yaml. It should be redis_exporter: