利用prometheus+grafana监控redis-server状态

行云流水
2023-04-10 / 0 评论 / 440 阅读 / 正在检测是否收录...

前言

Redis是一个开源的内存数据存储解决方案,它还支持磁盘持久性。Redis支持多种数据结构,例如字符串、哈希表、列表、集合和有序集合等。本文分享如何利用prometheus+grafana监控redis-server状态。

初始化

新服务需要一些基本的设置和优化,安装docker和docker-compose。

参考: docker和docker-compose一键安装脚本

prometheus配置

修改prometheus的配置文件,加入redis节点
scrape_configs:
  ## config for the multiple Redis targets that the exporter will scrape
  - job_name: 'redis_exporter_targets'
    static_configs:
      - targets:
        - redis://172.17.0.10:6379
    metrics_path: /scrape
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 172.17.16.10:9121

  ## config for scraping the exporter itself
  #- job_name: 'redis_exporter'
  #  static_configs:
  #    - targets:
  #      - 172.17.16.10:9121

docker配置

docker-compose.yml项目启动文件

version: "3.8"
networks:
    net:
        driver: bridge
services:
  redis-exporter:
    image: oliver006/redis_exporter
    command:
      - "--redis.addr=172.17.0.10:6379"
    ports:
      - "9121:9121"

  prometheus:
    image: prom/prometheus:latest
    restart: always
    user: "0"
    ports:
      - "9090:9090"
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/timezone:/etc/timezone:ro"
      - "./myapp/prometheus/:/prometheus"
    command:
      - "--storage.tsdb.retention.time=180d"
      - "--config.file=/prometheus/prometheus.yml"
      - "--web.enable-lifecycle"
    networks:
      - net
    depends_on:
      - redis-exporter

  grafana:
    image: grafana/grafana:latest
    restart: always
    user: "0"
    ports:
      - "3000:3000"
    environment:
      - "GF_SECURITY_ADMIN_PASSWORD=grafana@123"
      - "GF_RENDERING_SERVER_URL=http://renderer:8081/render"
      - "GF_RENDERING_CALLBACK_URL=http://grafana:3000/"
      - "GF_LOG_FILTERS=rendering:debug"
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - ./data/grafana/:/var/lib/grafana
    networks:
      - net
    depends_on:
      - prometheus
      - renderer

  renderer:
    image: grafana/grafana-image-renderer:latest
    ports:
      - "8081:8081"
    environment:
      - "ENABLE_METRICS=true"
      - "RENDERING_MODE=clustered"
      - "RENDERING_CLUSTERING_MODE=context"
      - "RENDERING_CLUSTERING_MAX_CONCURRENCY=5"
    networks:
      - net

启动

docker-compose up -d

grafana

数据可视化,默认账号密码:admin/grafana@123

'http://ip:3000'

添加数据源

添加promethous数据源,通过web界面添加。只修改url,其他参数默认即可。

导入redis模板

wget  https://grafana.com/api/dashboards/763/revisions/1/download -O redis.json

prometheus文章

评论 (0)

取消
只有登录/注册用户才可评论