Prometheus实战篇:Prometheus监控redis

本文涉及的产品
容器镜像服务 ACR,镜像仓库100个 不限时长
函数计算FC,每月15万CU 3个月
Serverless 应用引擎免费试用套餐包,4320000 CU,有效期3个月
简介: Prometheus监控redis

准备环境

docker-compose安装redis

docker-compose.yaml

version: '3'
services:
   redis:
  image:redis:5
  container_name: redis
  command: redis-server --requirepass 123456 --maxmemory 512mb
   restart: always
   volumes:
    - /data/redis/data: /data
   port:
   - "6379:6379"
docker-compose up -d

监控redis

docker安装exporter

docker直接运行

docker run -d --name redis_exporter -p 9121:9121 oliver006/redis_exporter --redis.addr redis://localhost:6379 --redis.password '123456'

docker-compose方式

cat >docker-compose.yaml <<FOF
version: '3.3'
services:
 redis_exproter:
  image:oliver006/redis-exporter
  container_name: redis_exporter
  restart: always
  environment:
    REDIS_ADDR:"localhost:6379"
    REDIS_PASSWORD: 123456
  port:
   - "9113:9113"
EOF

启动

docker-compose up -d

检查

查看正在运行的容器
docker ps
或者:
查看redis_exporter容器的运行日志
docker logs -f redis_exporter

参数解释

Environment variable

描述

REDIS_ADDR

localhost:6379

redis服务地址

REDIS_PASSWORD

123456

redis服务密码

metrics地址

安装好Exporter后会暴露一个/metrics结尾的服务

名称

地址

redis_exporter

http://localhost:9121/metrics

Prometheus配置

配置Prometheus去采集(拉取)nginx_exporter的监控样本数据

cd /data/docker-prometheus
# 在scrapc_configs(搜刮配置):下面增加如下配置:
cat >prometheus/prometheus.yml <<FOF
 - job_name: 'redis_exporter'
   static_configs:
   - targets: ['localhost:9121']
     labels:
      instance: test服务器 
EOF

重新加载配置

curl -x POST http://localhost:9090/-/reload

检查

常用的redis监控指标

redis_up                        服务器是否在线
redis_uptime_in_seconds                 运行时长,单位s
rate(redis_cpu_sys_seconds_total[1m])+rate(redis_cpu_user_seconds_total[1m])    占用CPU核数
redis_memory_used_bytes                 占用内存量
redis_memory_max_bytes                  限制的最大内存,如果没限制则为0
delta(redis_net_input_bytes_total[1m])          网络接受的bytes
delta(redis_net_output_bytes_total[1m])         网络发送的bytes
redis_connected_clients                 客户端连接数
redis_connected_clients / redis_config_maxclients
  连接数使用率
redis_rejected_connections_total
  拒绝的客户端连接数
redis_connected_slaves
  slave连接数

触发器配置

由于之前的触发器是全部写在了一个yml里面就是alert.yam,这样随着后面配置的触发器越来越多最终会变得难以维护.这里我们让它去读rules目录下所有的yml文件即可

Prometheus配置

rule_files:
  - "alert.yml"
  - "rules/*.yml"

配置redis触发器

因为是单机所以未配置集群的触发器

cat >prometheus/redis.yml <<FOF
groups:
- name: redis
  rules:
    - alert: RedisDown
      expr: redis_up ==0
      for: 0m
      labels:
        severity: critical
      annotations:
          summary: "redis Down,实例:{{$labels.instance }}"
          description: "Redis实例 is down"
    - alert: RedisMissingBackup
      expr: time() - redis_rdb_last_save_timestamp_seconds > 60 * 60 * 24
      for: 0m
      labels:
        severity: critical
      annotations:
          summary: "redis 备份丢失,实例:{{$labels.instance }}"
          description: "Redis 24小时未备份"
    - alert: RedisOutOfConfigredMaxmemory
      expr: redis_memory_used_bytes / redis_memory_max_bytes * 100 >90
      for: 2m
      labels:
        severity: warning
      annotations:
          summary: "redis超出配置的最大内存,实例:{{$labels.instance }}"
          description: "Redis内存使用超过配置的最大内存的90%"
    - alert: RedisTooManyConnections
      expr: redis_connected_clients > 100
      for: 2m
      labels:
        severity: warning
      annotations:
          summary: "redis连接数过多,实例:{{$labels.instance }}"
          description: "Redis当前连接数为:{{ $value }}"
    - alert: RedisNotEnoughConnections
      expr: redis_connected_clients < 1
      for: 2m
      labels:
        severity: warning
      annotations:
          summary: "redis没有足够的连接,实例:{{$labels.instance }}"
          description: "Redis当前连接数为:{{ $value }}"
    - alert: RedisRejectedConnections
      expr: increase(redis_rejected_connections_total[1m]) > 0
      for: 0m
      labels:
        severity: critical
      annotations:
          summary: "redis有拒绝连接,实例:{{$labels.instance }}"
          description: "与Redis的某些连接被拒绝:{{ $value }}"
EOF

一定记住这里需要仔细校对yaml语法,最好是能去在线验证yaml语法的网站上看看.yaml语法还是比较严格的一点缩进错误都不能有

检查配置

docker exec -it prometheus promtool check config /etc/prometheus/prometheus.yml

重新加载配置

curl -x POST http://localhost:9090/-/reload

检查

http://localhost:9090/alerts?search=

或:

http://localhost:9090/rules

dashboard

grafana展示Prometheus从redis_exporter收集到的数据

id :11835


相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
9月前
|
存储 NoSQL BI
Redis 实战篇:巧用 Bitmap 实现亿级海量数据统计
Redis 实战篇:巧用 Bitmap 实现亿级海量数据统计
203 0
|
3月前
|
Prometheus 运维 监控
智能运维实战:Prometheus与Grafana的监控与告警体系
【10月更文挑战第26天】Prometheus与Grafana是智能运维中的强大组合,前者是开源的系统监控和警报工具,后者是数据可视化平台。Prometheus具备时间序列数据库、多维数据模型、PromQL查询语言等特性,而Grafana支持多数据源、丰富的可视化选项和告警功能。两者结合可实现实时监控、灵活告警和高度定制化的仪表板,广泛应用于服务器、应用和数据库的监控。
419 3
|
8月前
|
消息中间件 NoSQL Java
Redis系列学习文章分享---第六篇(Redis实战篇--Redis分布式锁+实现思路+误删问题+原子性+lua脚本+Redisson功能介绍+可重入锁+WatchDog机制+multiLock)
Redis系列学习文章分享---第六篇(Redis实战篇--Redis分布式锁+实现思路+误删问题+原子性+lua脚本+Redisson功能介绍+可重入锁+WatchDog机制+multiLock)
280 0
|
3月前
|
Prometheus 运维 监控
智能运维实战:Prometheus与Grafana的监控与告警体系
【10月更文挑战第27天】在智能运维中,Prometheus和Grafana的组合已成为监控和告警体系的事实标准。Prometheus负责数据收集和存储,支持灵活的查询语言PromQL;Grafana提供数据的可视化展示和告警功能。本文介绍如何配置Prometheus监控目标、Grafana数据源及告警规则,帮助运维团队实时监控系统状态,确保稳定性和可靠性。
408 0
|
6月前
|
存储 Prometheus 监控
性能监控之初识 Prometheus
【8月更文挑战第2天】性能监控之初识 Prometheus
647 17
|
6月前
|
Prometheus 监控 Cloud Native
性能监控之 Golang 应用接入 Prometheus 监控
【8月更文挑战第4天】性能监控之 Golang 应用接入 Prometheus 监控
288 0
性能监控之 Golang 应用接入 Prometheus 监控
|
6月前
|
Prometheus 监控 Cloud Native
性能监控之 node_exporter+Prometheus+Grafana 实现主机监控
【8月更文挑战第3天】性能监控之 node_exporter+Prometheus+Grafana 实现主机监控
464 0
|
8月前
|
Prometheus 监控 Cloud Native
性能监控神器Prometheus、Grafana、ELK 在springboot中的运用
【6月更文挑战第27天】在 Spring Boot 应用中,监控和日志管理是确保系统稳定性和性能的重要手段。
511 4
|
8月前
|
NoSQL 容灾 Redis
Redis系列学习文章分享---第十一篇(Redis高级实战篇---RDB演示 +RDB的fork原理+A0F演示 +RDB和AOF)
Redis系列学习文章分享---第十一篇(Redis高级实战篇---RDB演示 +RDB的fork原理+A0F演示 +RDB和AOF)
56 0
|
8月前
|
NoSQL Redis
Redis系列学习文章分享---第五篇(Redis实战篇--优惠券秒杀,全局唯一id 添加优惠券 实现秒杀下单 库存超卖问题分析 乐观锁解决超卖 实现一人一单功能 集群下的线程并发安全问题)
Redis系列学习文章分享---第五篇(Redis实战篇--优惠券秒杀,全局唯一id 添加优惠券 实现秒杀下单 库存超卖问题分析 乐观锁解决超卖 实现一人一单功能 集群下的线程并发安全问题)
163 0

相关产品

  • 可观测监控 Prometheus 版