跳到主要内容

用夜莺监控 Redis

连上 Redis 执行 INFO 采集内存、命中率、连接、慢日志和主从状态,另带 Sentinel 插件和按 redis_exporter 写的模板。

最后校对于

Redis 插件连上实例执行 INFO 命令并解析,得到内存使用与碎片率、键空间命中率、连接数、阻塞客户端、持久化状态、主从复制状态等指标。多个实例就写多个 [[instances]],建议给每个实例一个 instance 标签,仪表盘靠它区分。

Sentinel 环境另有 redis_sentinel 插件采集哨兵视角的主从拓扑。模板里的仪表盘分 Categraf 和 redis_exporter 两套,规则覆盖内存逼近 maxmemory、命中率下降、连接数异常、主从断开和实例重启。

模板里有什么​

  • 3 张仪表盘,共 47 个面板
  • 13 条告警规则,每条附处置步骤
  • Categraf 采集配置:input.redis、input.redis_sentinel

怎么接入​

  1. 安装 Categraf,按需启用下面的插件。每个配置放到对应的 conf/input.<插件名>/ 目录,改好地址和凭据后重启 Categraf。

    conf/input.redis/redis.toml

    # # collect interval
    # interval = 15

    [[instances]]
    # address = "127.0.0.1:6379"
    # username = ""
    # password = ""
    # pool_size = 2

    # # Optional. Specify redis commands to retrieve values
    # commands = [
    # {command = ["get", "sample-key1"], metric = "custom_metric_name1"},
    # {command = ["get", "sample-key2"], metric = "custom_metric_name2"}
    # ]

    # # interval = global.interval * interval_times
    # interval_times = 1

    # important! use global unique string to specify instance
    # labels = { instance="n9e-10.2.3.4:6379" }

    ## Optional TLS Config
    # use_tls = false
    # tls_min_version = "1.2"
    # tls_ca = "/etc/categraf/ca.pem"
    # tls_cert = "/etc/categraf/cert.pem"
    # tls_key = "/etc/categraf/key.pem"
    ## Use TLS but skip chain & host verification
    # insecure_skip_verify = true

    conf/input.redis_sentinel/redis_sentinel.toml

    # # collect interval
    # interval = 15

    [[instances]]
    # [protocol://][:password]@address[:port]
    # e.g. servers = ["tcp://localhost:26379"]
    servers = []

    # # interval = global.interval * interval_times
    # interval_times = 1
    # add some dimension data by labels
    # labels = {}

    ## Optional TLS Config
    # use_tls = false
    # tls_min_version = "1.2"
    # tls_ca = "/etc/categraf/ca.pem"
    # tls_cert = "/etc/categraf/cert.pem"
    # tls_key = "/etc/categraf/key.pem"
    ## Use TLS but skip chain & host verification
    # insecure_skip_verify = true
  2. 在夜莺「集成中心」里找到 Redis,把仪表盘和告警规则导入到业务组。

  3. 导入的告警规则默认是停用的。先确认指标已经入库,再按自己环境的阈值逐条启用。

内置仪表盘​

仪表盘面板数
Redis by address16
Redis by instance16
Redis Overview - exporter15

内置告警规则​

共 13 条,导入后默认停用,按自己环境的阈值逐条启用。每条规则的触发条件(PromQL)和处置步骤收录在告警规则库:Redis 告警规则。

规则级别持续
High Redis eviction rateS2 警告1 分钟
High Redis memory usage rateS2 警告1 分钟
High Redis Ping latency (above 100 milliseconds)S2 警告1 分钟
Low Redis hit rateS2 警告1 分钟
Redis connection refusedS2 警告—
Redis has just been restarted, please be awareS3 提醒—
High Redis client connection count - exporterS2 警告1 分钟
High Redis eviction rate - exporterS2 警告1 分钟
High Redis latency - exporterS2 警告1 分钟
High Redis memory usage rate - exporterS2 警告1 分钟
Low Redis hit rate - exporterS2 警告1 分钟
Redis connection refused - exporterS2 警告—
Redis has just been restarted, please be aware - exporterS3 提醒—

相关链接​