prometheus监控自建redis并实现报警

2,145次阅读
没有评论

共计 1983 个字符,预计需要花费 5 分钟才能阅读完成。

prometheus 监控自建 redis 并实现报警
周末因为一台 redis 代码链接 redis oom 所以需要进行相关监控
报错内容如下:
org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.) ... 40 common frames omitted Caused by: io.lettuce.core.RedisCommandExecutionException: OOM command not allowed when used memory > 'maxmemory'.

临时解决办法

CONFIG SET maxmemory 2gb

原因是我 redis 的最大内存设置了 1G,同时代码没有设置 key 的过期时间导致,设置成功后开发进行相关 bug 修复。

一,redis 客户端配置 虽然问题解决但是我们还是需要配置监控主动报警。配置的监控的过程如下。首先下载 redis_exporter

wget https://github.com/oliver006/redis_exporter/releases/download/v1.63.0/redis_exporter-v1.63.0.linux-amd64.tar.gz

然后配置 redis 启动

vim /lib/systemd/system/redis_exporter.service
[Unit]
Description=Redis exporter
After=network.target

[Service]
User=dev
Group=dev
ExecStart=/opt/apps/redis_exporter/redis_exporter -redis.addr 127.0.0.1:6379
Type=simple

[Install]
WantedBy=multi-user.target

加载配置
systemctl daemon-reload
启动
systemctl start redis_exporter
开机自启
systemctl enable redis_exporter

二,prometheus 服务端配置

  - job_name: 'redis_exporter'
    file_sd_configs:
      - files:
          - /usr/local/prometheus/configs/redis_exporter.yml

然后配置 redis_exporter.yml

- targets: 
    - '你 redis_exporter 的 ip:9121'

设置报警规则我们需要到 prometheus 的报警规则下加上相关报警规则

cat redis.yml 
groups:
- name: redis
  rules:
    - alert: RedisDown
      expr: redis_up == 0
      for: 30s
      labels:
        severity: critical
      annotations:
        summary: "Redis down (instance {{ $labels.instance}})"
        description: "Redis 挂了 \n  VALUE = {{$value}}\n  LABELS: {{$labels}}"
    - alert: RedisOutOfMemory
      expr: redis_memory_used_bytes / redis_total_system_memory_bytes * 100 > 90
      for: 60s
      labels:
        severity: warning
      annotations:
        summary: "Redis out of memory (instance {{ $labels.instance}})"
        description: "Redis 内存不足 (> 90%)\n  VALUE = {{$value}}\n  LABELS: {{$labels}}"
    - alert: RedisTooManyConnections
      expr: redis_connected_clients > 100
      for: 30s
      labels:
        severity: warning
      annotations:
        summary: "Redis too many connections (instance {{ $labels.instance}})"
        description: "Redis 实例连接过多 \n  VALUE = {{$value}}\n  LABELS: {{$labels}}"

这样基本我们就完成了,如果需要监控更多实例只需要安装 redis_exporter 并把配置加到 redis_exporter.yml 就能识别监控相关实例了。

最后在 grafana 倒入表盘 id 就能查看相关监控信息了。

我用的 id 是 18345 效果图如下:

prometheus 监控自建 redis 并实现报警

微信扫描下方的二维码阅读本文

正文完
 1
yx
版权声明:本站原创文章,由 yx 于2024-09-09发表,共计1983字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码

bttech

文章搜索
一言一句话
-「
随机文章
elasticsearch7.8.0索引备份到阿里云oss以及恢复

elasticsearch7.8.0索引备份到阿里云oss以及恢复

背景需求,阿里云新建了一套 elk 但是数据需要进行迁移备份, 解决方案使用 logstash 迁移很慢,10...
MacBook Pro M4 关闭swap

MacBook Pro M4 关闭swap

Swap 是将磁盘虚拟为内存来用的,所以速度肯定比不上扎扎实实的内存的。我是 16G 内存,对于我平时使用完全...
ubuntu20安装部署comfyui脚本

ubuntu20安装部署comfyui脚本

基础环境参考上一篇文章安装基本的驱动 这个使用的曲线较高,有一定的学习成本。脚本如下直接使用即可! 微信扫描下...
k8s安装chatwoot后配置邮件报超时问题

k8s安装chatwoot后配置邮件报超时问题

k8s 安装好 chathoot 后配置好了邮件的相关变量 官方配置示例 SMTP_ADDRESS: ""SM...
ubuntu20 TeslaT4 安装stable diffusion-webui

ubuntu20 TeslaT4 安装stable diffusion-webui

升级系统 执行 nvidia-smi 查看是否安装了相关驱动 如果执行 nvidia-smi 没有相关命令就需...