Redis shake实现可视化监控的示例代码

 更新时间:2024年03月29日 08:49:22   作者:真雪  
Redis可视化监控是通过监控Redis服务器的各项指标和状态,并将其以可视化的方式展示给用户,本文给大家介绍了Redis shake实现可视化监控,并通过代码示例讲解的非常详细,需要的朋友可以参考下
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud

(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

一.redis-shake v4

1.镜像

######################### Dockerfile ########################################
FROM centos:7
 
WORKDIR /opt
COPY shake.toml /tmp/
COPY redis-shake /opt/
COPY entrypoint.sh /usr/local/bin/
RUN  chmod +x redis-shake  &&  chmod +x /usr/local/bin/entrypoint.sh
EXPOSE 8888
ENTRYPOINT ["entrypoint.sh"]
 
######################### entrypoint.sh ######################################
#!/bin/bash
set -e
 
eval "cat <<EOF
 $(< /tmp/shake.toml)
EOF
"  > /opt/shake.toml
/opt/redis-shake /opt/shake.toml
exit 0

2.shake.toml

status_port = 8888 获取监控数据端口,部署启动时映射8888端口

function = ""
 
########## 过滤key #########################################
#function """
#local prefix = "user:"
#local prefix_len = #prefix
#if string.sub(KEYS[1], 1, prefix_len) ~= prefix then
#  return
#end
#shake.call(DB, ARGV)
#"""
 
[sync_reader]
cluster = ${SOURCE_IF_CLUSTER}  # set to true if source is a redis cluster
address = ${SOURCE_ADDRESS}     # when cluster is true, set address to one of the cluster node
password = ${SOURCE_PASSWORD}   # keep empty if no authentication is required
sync_rdb = ${SYNC_RDB} # set to false if you don't want to sync rdb true全量同步 false不全量同步
sync_aof = ${SYNC_AOF} # set to false if you don't want to sync aof true 增量同步 false不增量同步
prefer_replica = true # set to true if you want to sync from replica node
dbs = []           # set you want to scan dbs such as [1,5,7], if you don't want to scan all
tls = false
# username = ""              # keep empty if not using ACL
# ksn = false         # set to true to enabled Redis keyspace notifications (KSN) subscription
 
[redis_writer]
cluster = ${TARGET_IF_CLUSTER}   # set to true if target is a redis cluster
address = ${TARGET_ADDRESS}      # when cluster is true, set address to one of the cluster node
password = ${TARGET_PASSWORD}    # keep empty if no authentication is required
tls = false
off_reply = false       # ture off the server reply
# username = ""         # keep empty if not using ACL
 
[advanced]
dir = "data"
ncpu = 0        # runtime.GOMAXPROCS, 0 means use runtime.NumCPU() cpu cores
# pprof_port = 8856  # pprof port, 0 means disable
status_port = 8888 # status port, 0 means disable
 
# log
log_file = "shake.log"
log_level = "info"     # debug, info or warn
log_interval = 5       # in seconds
 
# redis-shake gets key and value from rdb file, and uses RESTORE command to
# create the key in target redis. Redis RESTORE will return a "Target key name
# is busy" error when key already exists. You can use this configuration item
# to change the default behavior of restore:
# panic:   redis-shake will stop when meet "Target key name is busy" error.
# rewrite: redis-shake will replace the key with new value.
# ignore:  redis-shake will skip restore the key when meet "Target key name is busy" error.
rdb_restore_command_behavior = ${RESTORE_BEHAVIOR} # panic, rewrite or ignore
 
# redis-shake uses pipeline to improve sending performance.
# This item limits the maximum number of commands in a pipeline.
pipeline_count_limit = 1024
 
# Client query buffers accumulate new commands. They are limited to a fixed
# amount by default. This amount is normally 1gb.
target_redis_client_max_querybuf_len = 1024_000_000
 
# In the Redis protocol, bulk requests, that are, elements representing single
# strings, are normally limited to 512 mb.
target_redis_proto_max_bulk_len = 512_000_000
 
# If the source is Elasticache or MemoryDB, you can set this item.
aws_psync = "" # example: aws_psync = "10.0.0.1:6379@nmfu2sl5osync,10.0.0.1:6379@xhma21xfkssync"
 
# destination will delete itself entire database before fetching files
# from source during full synchronization.
# This option is similar redis replicas RDB diskless load option:
#   repl-diskless-load on-empty-db
empty_db_before_sync = false
 
[module]
# The data format for BF.LOADCHUNK is not compatible in different versions. v2.6.3 <=> 20603
target_mbbloom_version = 20603

3.启动redis-shake后

可部署多个 redis-shake 10.111.11.12:8888  10.111.11.12:8889 10.111.11.12:8890

{"start_time":"2024-02-02 16:13:07","consistent":true,"total_entries_count":{"read_count":77403368,"read_ops":0,"write_count":77403368,"write_ops":0},"per_cmd_entries_count":{"APPEND":{"read_count":2,"read_ops":0,"write_count":2,"write_ops":0},"DEL":{"read_count":5,"read_ops":0,"write_count":5,"write_ops":0},"HMSET":{"read_count":2,"read_ops":0,"write_count":2,"write_ops":0},"PEXPIRE":{"read_count":8,"read_ops":0,"write_count":8,"write_ops":0},"RESTORE":{"read_count":77403341,"read_ops":0,"write_count":77403341,"write_ops":0},"SADD":{"read_count":1,"read_ops":0,"write_count":1,"write_ops":0},"SCRIPT-LOAD":{"read_count":7,"read_ops":0,"write_count":7,"write_ops":0},"SET":{"read_count":2,"read_ops":0,"write_count":2,"write_ops":0}},"reader":[{"name":"reader_10.127.11.11_9984","address":"10.127.11.11:9984","dir":"/opt/data/reader_10.172.48.17_9984","status":"syncing aof","rdb_file_size_bytes":867659640,"rdb_file_size_human":"828 MiB","rdb_received_bytes":867659640,"rdb_received_human":"828 MiB","rdb_sent_bytes":867659640,"rdb_sent_human":"828 MiB","aof_received_offset":567794044,"aof_sent_offset":567794044,"aof_received_bytes":6614445,"aof_received_human":"6.3 MiB"},{"name":"reader_10.127.11.12_9984","address":"10.127.11.12:9984","dir":"/opt/data/reader_10.172.48.16_9984","status":"syncing aof","rdb_file_size_bytes":867824091,"rdb_file_size_human":"828 MiB","rdb_received_bytes":867824091,"rdb_received_human":"828 MiB","rdb_sent_bytes":867824091,"rdb_sent_human":"828 MiB","aof_received_offset":564917306,"aof_sent_offset":564917306,"aof_received_bytes":6612502,"aof_received_human":"6.3 MiB"},{"name":"reader_10.127.11.13_9984","address":"10.127.11.13:9984","dir":"/opt/data/reader_10.172.48.15_9984","status":"syncing aof","rdb_file_size_bytes":867661773,"rdb_file_size_human":"828 MiB","rdb_received_bytes":867661773,"rdb_received_human":"828 MiB","rdb_sent_bytes":867661773,"rdb_sent_human":"828 MiB","aof_received_offset":562834707,"aof_sent_offset":562834707,"aof_received_bytes":6615286,"aof_received_human":"6.3 MiB"}],"writer":[{"name":"writer_10.127.12.11_9984","unanswered_bytes":0,"unanswered_entries":0},{"name":"writer_10.127.12.12_9984","unanswered_bytes":0,"unanswered_entries":0},{"name":"writer_10.127.12.13_9984","unanswered_bytes":0,"unanswered_entries":0}]}

二.json-exporter配置

1.Dockerfile

FROM prometheuscommunity/json-exporter:latest
 
USER root
RUN mkdir -p  /opt
WORKDIR /opt
COPY  config.yml /opt/

2.config.yml

根据上边返回的json数据,制定自己需要的监控模版,部署json-exporter 10.111.11.11:7979

modules:
  default:
    headers:
      X-Dummy: my-test-header
    metrics:
    - name: shake_consistent
      help: Example of sub-level value scrapes from a json
      path: '{.consistent}'
      labels:
        start_time: '{.start_time}'
    - name: shake_total_entries_count
      type: object
      help: Example of sub-level value scrapes from a json
      path: '{.total_entries_count}'
      values:
        read_count: '{.read_count}'     # static value
        read_ops: '{.read_ops}' # dynamic value
        write_count: '{.write_count}'
        write_ops: '{.write_ops}'
    - name: shake_per_cmd_entries_count_restore
      type: object
      help: Example of sub-level value scrapes from a json
      path: "{.per_cmd_entries_count.RESTORE}"
      values:
        read_count: '{.read_count}'
        read_ops: '{.read_ops}'
        write_count: '{.write_count}'
        write_ops: '{.write_ops}'
    - name: shake_per_cmd_entries_script_load
      type: object
      help: Example of sub-level value scrapes from a json
      path: "{.per_cmd_entries_count.SCRIPT-LOAD}"
      values:
        read_count: '{.read_count}'
        read_ops: '{.read_ops}'
        write_count: '{.write_count}'
        write_ops: '{.write_ops}'
    - name: shake_reader
      type: object
      help: Example of sub-level value scrapes from a json
      path: "{.reader}"
      labels:
        address: '{.address}'          # dynamic label
        dir: '{.dir}'
        status: '{.status}'
      values:
        rdb_file_size_bytes: '{.rdb_file_size_bytes}'
        rdb_received_bytes: '{.rdb_received_bytes}'
        rdb_sent_bytes: '{.rdb_sent_bytes}'
        aof_received_offset: '{.aof_received_offset}'
        aof_sent_offset: '{.aof_sent_offset}'
        aof_received_bytes: '{.aof_received_bytes}'
    - name: shake_writer
      type: object
      help: Example of sub-level value scrapes from a json
      path: "{.writer}"
      labels:
        name: '{.name}'          # dynamic label
      values:
        unanswered_bytes: '{.unanswered_bytes}'
        unanswered_entries: '{.unanswered_entries}'

三.prometheus配置

1.prometheus.yml

global:
  scrape_interval: 15s 
  evaluation_interval: 15s
 
scrape_configs:
  - job_name: json_exporter
    metrics_path: /probe
    file_sd_configs:
    - files:
      - 'redis-shake.json'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 10.111.11.11:7979 # json-exporter地址

2.redis-shake.json

单独的文件配置可实现动态加载,同时可添加自定义的标签在文件中

[
# labels为自定义的标签,targets为部署各个redis-shake地址
{"labels": {"env-1":"团队1"},"targets": ["http://10.111.11.12:8888"]},
{"labels": {"env-1":"团队2"},"targets": ["http://10.111.11.12:8889"]},
{"labels": {"env-1":"团队3"},"targets": ["http://10.111.11.12:8890"]}
]

四.grafana

上边的都配置好,把自己的peometheus数据源添加到grafana中,就可以设置自己想要的监控界面了

到此这篇关于Redis shake实现可视化监控的示例代码的文章就介绍到这了,更多相关Redis shake可视化监控内容请搜索程序员之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持程序员之家!

相关文章

  • Redis 中spark参数executor-cores引起的异常解决办法

    Redis 中spark参数executor-cores引起的异常解决办法

    这篇文章主要介绍了Redis 中spark参数executor-cores引起的异常解决办法的相关资料,需要的朋友可以参考下
    2017-03-03
  • 深入浅析Redis 集群伸缩原理

    深入浅析Redis 集群伸缩原理

    Redis 集群提供了灵活的节点扩容和收缩方案。在不影响集群对外服务的情况下,可以为集群添加节点进行扩容,也可以下线部分节点进行缩容,接下来通过本文给大家分享Redis 集群伸缩原理,感兴趣的朋友一起看看吧
    2021-05-05
  • Redis 删除策略的三种实现

    Redis 删除策略的三种实现

    本文主要介绍了Redis 删除策略的三种实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-06-06
  • Redis和数据库 数据同步问题的解决

    Redis和数据库 数据同步问题的解决

    这篇文章主要介绍了Redis和数据库 数据同步问题的解决操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2021-01-01
  • redislive监控redis服务的图文教程_动力节点Java 学院整理

    redislive监控redis服务的图文教程_动力节点Java 学院整理

    这篇文章主要介绍了redislive监控redis服务的图文教程_动力节点Java 学院整理,需要的朋友可以参考下
    2017-08-08
  • Redis分布式锁解决超卖问题的使用示例

    Redis分布式锁解决超卖问题的使用示例

    超卖问题通常出现在多用户并发操作的情况下,即多个用户尝试购买同一件商品,导致商品库存不足或者超卖,本文就来介绍一下超卖问题,感兴趣的可以了解一下
    2023-09-09
  • 基于Redis的分布式锁的简单实现方法

    基于Redis的分布式锁的简单实现方法

    这篇文章主要介绍了基于Redis的分布式锁的简单实现方法,Redis官方给出两种思路,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-10-10
  • 使用注解实现Redis缓存功能

    使用注解实现Redis缓存功能

    这篇文章主要为大家详细介绍了使用注解实现Redis缓存功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-07-07
  • Redis高可用梳理详解

    Redis高可用梳理详解

    高可用的本质是有备份,在出现故障的时候,有backup可以提供服务,本文详细介绍了Redis的高可用,感兴趣的同学可以参考阅读
    2023-05-05
  • redis添加key几种方式

    redis添加key几种方式

    本文主要介绍了redis添加key几种方式,主要介绍了3种方式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2024-01-01

最新评论

?


http://www.vxiaotou.com