[转帖]prometheus部暑redis_exporter(sentinel, cluster实战)

prometheus,redis,exporter,sentinel,cluster,实战 · 浏览次数 : 0

小编点评

**Redis监控脚本** ```python # 创建工作目录 mkdir /data/redis_exporter/ -p # 启动脚本 docker run -d --name redis_exporter --restart=always -p 9121:9121 -e REDIS_ADDR=192.168.11.221:6379 -e REDIS_PASSWORD=password -e REDIS_EXPORTER_INCL_SYSTEM_METRICS=true -v /etc/localtime:/etc/localtime:ro -e REDIS_EXPORTER_LOG_LEVEL=info -o /data/redis_exporter/redis_exporter_log.txt --name redis_exporter -d /data/redis_exporter/start.sh > /data/prometheus/conf/rules/redis.rules << # 添加自动发现脚本 cat > /data/prometheus/conf/prometheus.yml << 'EOF' redis自动发现job_name: 'redis'file_sd_configs:files:/etc/prometheus/sd_config/redis.yamlrefresh_interval: 5smetrics_path: /scraperelabel_configs:source_labels: [address]target_label: __param_targetsource_labels: [__param_target]target_label: instancetarget_label: addressreplacement: 192.168.11.221:9121 ``` **配置** * `redis_exporter_log.txt` 用于记录监控器的日志。 * `redis.yaml` 是 Redis 自动发现的配置文件。 * `prometheus.yml` 是 Prometheus 自动发现的配置文件。 * `grfana_id` 是 GRANA ID。

正文

redis_exporter

#创建工作目录
mkdir /date/redis -p
cat > /data/redis/start.sh << 'EOF'
docker run -d \
--name redis \
-p 6379:6379 \
redis redis-server \
--appendonly yes \
--requirepass password \
--maxmemory 20M
EOF
bash /data/redis/start.sh

mkdir /data/redis_exporter/ -p

#启动脚本
cat > /data/redis_exporter/start.sh<< 'EOF'
docker run -d
--name redis_exporter
--restart=always
-p 9121:9121
-e REDIS_ADDR=192.168.11.221:6379
-e REDIS_PASSWORD=password
-e REDIS_EXPORTER_INCL_SYSTEM_METRICS=true
-v /etc/localtime:/etc/localtime:ro
oliver006/redis_exporter
EOF

bash /data/redis_exporter/start.sh

cat > /data/prometheus/conf/rules/redis.rules << 'EOF'
groups:

  • name: Redis-监控告警
    rules:
    • alert: 警报!Redis应用不可用
      expr: redis_up == 0
      for: 0m
      labels:
      severity: 严重告警
      annotations:
      summary: "{{ $labels.instance }} Redis应用不可用"
      description: "Redis应用不可达\n 当前值 = {{ $value }}"

    • alert: 警报!丢失Master节点
      expr: (count(redis_instance_info{role="master"}) ) < 1
      for: 0m
      labels:
      severity: 严重告警
      annotations:
      summary: "{{ $labels.instance }} 丢失Redis master"
      description: "Redis集群当前没有主节点\n 当前值 = {{ $value }}"

    • alert: 警报!脑裂,主节点太多
      expr: count(redis_instance_info{role="master"}) > 1
      for: 0m
      labels:
      severity: 严重告警
      annotations:
      summary: "{{ $labels.instance }} Redis脑裂,主节点太多"
      description: "{{ $labels.instance }} 主节点太多\n 当前值 = {{ $value }}"

    • alert: 警报!Slave连接不可达
      expr: count without (instance, job) (redis_connected_slaves) - sum without (instance, job) (redis_connected_slaves) - 1 > 1
      for: 0m
      labels:
      severity: 严重告警
      annotations:
      summary: "{{ $labels.instance }} Redis丢失slave节点"
      description: "Redis slave不可达.请确认主从同步状态\n 当前值 = {{ $value }}"

    • alert: 警报!Redis副本不一致
      expr: delta(redis_connected_slaves[1m]) < 0
      for: 0m
      labels:
      severity: 严重告警
      annotations:
      summary: "{{ $labels.instance }} Redis 副本不一致"
      description: "Redis集群丢失一个slave节点\n 当前值 = {{ $value }}"

    • alert: 警报!Redis集群抖动
      expr: changes(redis_connected_slaves[1m]) > 1
      for: 2m
      labels:
      severity: 严重告警
      annotations:
      summary: "{{ $labels.instance }} Redis集群抖动"
      description: "Redis集群抖动,请检查.\n 当前值 = {{ $value }}"

    • alert: 警报!持久化失败
      expr: (time() - redis_rdb_last_save_timestamp_seconds) / 3600 > 24
      for: 0m
      labels:
      severity: 严重告警
      annotations:
      summary: "{{ $labels.instance }} Redis持久化失败"
      description: "Redis持久化失败(>24小时)\n 当前值 = {{ printf "%.1f" $value }}小时"

    • alert: 警报!内存不足
      expr: redis_memory_used_bytes / redis_total_system_memory_bytes * 100 > 90
      for: 2m
      labels:
      severity: 一般告警
      annotations:
      summary: "{{ $labels.instance }}系统内存不足"
      description: "Redis占用系统内存(> 90%)\n 当前值 = {{ printf "%.2f" $value }}%"

    • alert: 警报!Maxmemory不足
      expr: redis_config_maxmemory !=0 and redis_memory_used_bytes / redis_memory_max_bytes * 100 > 80
      for: 2m
      labels:
      severity: 一般告警
      annotations:
      summary: "{{ $labels.instance }} Maxmemory设置太小"
      description: "超出设置最大内存(> 80%)\n 当前值 = {{ printf "%.2f" $value }}%"

    • alert: 警报!连接数太多
      expr: redis_connected_clients > 200
      for: 2m
      labels:
      severity: 一般告警
      annotations:
      summary: "{{ $labels.instance }} 实时连接数太多"
      description: "连接数太多(>200)\n 当前值 = {{ $value }}"

    • alert: 警报!连接数太少
      expr: redis_connected_clients < 1
      for: 2m
      labels:
      severity: 一般告警
      annotations:
      summary: "{{ $labels.instance }} 实时连接数太少"
      description: "连接数(<1)\n 当前值 = {{ $value }}"

    • alert: 警报!拒绝连接数
      expr: increase(redis_rejected_connections_total[1m]) > 0
      for: 0m
      labels:
      severity: 严重告警
      annotations:
      summary: "{{ $labels.instance }} 拒绝连接"
      description: "Redis有拒绝连接,请检查连接数配置\n 当前值 = {{ printf "%.0f" $value }}"

    • alert: 警报!执行命令数大于1000
      expr: rate(redis_commands_processed_total[1m]) > 1000
      for: 0m
      labels:
      severity: 严重告警
      annotations:
      summary: "{{ $labels.instance }} 执行命令次数太多"
      description: "Redis执行命令次数太多\n 当前值 = {{ printf "%.0f" $value }}"
      EOF

#添加自动发现脚本
cat >> /data/prometheus/conf/prometheus.yml << 'EOF'

redis自动发现

  • job_name: 'redis'
    file_sd_configs:
    • files:
      • /etc/prometheus/sd_config/redis.yaml
        refresh_interval: 5s
        metrics_path: /scrape
        relabel_configs:
    • source_labels: [address]
      target_label: __param_target
    • source_labels: [__param_target]
      target_label: instance
    • target_label: address
      replacement: 192.168.11.221:9121
      EOF

#自动发现配置
cat >> /data/prometheus/conf/sd_config/redis.yaml << 'EOF'

redis自动发现

  • labels:
    project: 民生redis
    targets:
    • 192.168.11.221:6379
    • 192.168.11.222:6379
    • 192.168.11.223:6379
      EOF

    grfana_id :2751
    在这里插入图片描述

    grfana_id: 14615 (cluster)

    在这里插入图片描述

    监控redis_cluster
    http://t.zoukankan.com/fsckzy-p-12053604.html

    </article>
    

    与[转帖]prometheus部暑redis_exporter(sentinel, cluster实战)相似的内容:

    [转帖]prometheus部暑redis_exporter(sentinel, cluster实战)

    redis_exporter #创建工作目录 mkdir /date/redis -p cat > /data/redis/start.sh << 'EOF' docker run -d \ --name redis \ -p 6379:6379 \ redis redis-server \ --a

    [转帖]Prometheus + Spring Boot 应用监控

    https://blog.51cto.com/u_15127622/2757942 1. Prometheus是什么Prometheus是一个具有活跃生态系统的开源系统监控和告警工具包。一言以蔽之,它是一套开源监控解决方案。Prometheus主要特性:多维数据模型,其中包含由指标名称和键/值对标识

    [转帖]Prometheus的Exporter详解

    https://www.cnblogs.com/lizexiong/p/15578427.html 导航:这里主要是列出一个prometheus一些系统的学习过程,最后按照章节顺序查看,由于写作该文档经历了不同时期,所以在文中有时出现 的云环境不统一,但是学习具体使用方法即可,在最后的篇章,有一个完

    [转帖]prometheus监控nginxt的两种方法(vts)

    方法一 使用nginx_ vts_exporter mkdir -p /data/nginx/{log,conf/conf.d} cat > /data/nginx/conf/nginx.conf << 'EOF' user root; worker_processes auto; error_lo

    [转帖]Prometheus 都可以采集那些指标?-- 常用 Exporter 合集

    Prometheus 可以通过各种 Exporter 来获取很多指标,并且只要符合 Prometheus 规范的都可以获取到,本文汇总一些常用的采集器到这里。 Prometheus Exporter(一)Node Exporter Prometheus Exporter(二)Windows Expo

    [转帖]Prometheus监控系统存储容量优化攻略,让你的数据安心保存!

    云原生监控领域不可撼动,Prometheus 是不是就没缺点?显然不是。 一个软件如果什么问题都想解决,就会导致什么问题都解决不好。所以Prometheus 也存在不足,广受诟病的问题就是 单机存储不好扩展。 1 真的需要扩展容量吗? 大部分场景其实不需要扩展,因为一般的数据量压根达不到 Prome

    [转帖]prometheus的TCP alloc取值

    prometheus的TCP alloc取值 sockets: used:已使用的所有协议套接字总量 TCP: orphan:无主(不属于任何进程)的TCP连接数(无用、待销毁的TCP socket数) TCP_mem :TCP 套接字缓冲区使用量 ESTABLISHED: Tcp_tw:等待关闭的

    [转帖]Prometheus+Grafana+rabbitmq_prometheus 监控 RabbitMQ

    https://www.zhangbj.com/p/1065.html 关于 rabbitmq_prometheus rabbitmq_prometheus是RabbitMQ 3.8.0默认集成的监控插件。 相关文档 https://www.rabbitmq.com/monitoring.html

    [转帖]使用Prometheus和Grafana监控RabbitMQ集群 (使用RabbitMQ自带插件)

    https://www.cnblogs.com/hahaha111122222/p/15683696.html 配置RabbitMQ集群 官方文档:https://www.rabbitmq.com/prometheus.html#quick-start 官方github地址:https://gith

    [转帖]使用Prometheus监控bind9的DNS服务

    https://www.cnblogs.com/charlieroro/p/11013428.html 首先编译bind_exporter,编译方式参见bind_exporter 创建一个systemd配置文件来运行bind_exporter vi /etc/systemd/system/bind_