redis-shake可视化监控

news/2024/5/18 20:56:18 标签: redis, 数据库, 缓存, prometheus, json-exporter

目录

redis-shake%20v4-toc" style="margin-left:40px;">一.redis-shake v4

 1.镜像

2.shake.toml

redis-shake%E5%90%8E-toc" style="margin-left:80px;">3.启动redis-shake后

json-exporter%E9%85%8D%E7%BD%AE-toc" style="margin-left:40px;">二.json-exporter配置

1.Dockerfile

2.config.yml

prometheus%E9%85%8D%E7%BD%AE-toc" style="margin-left:40px;">三.prometheus配置

prometheus.yml-toc" style="margin-left:80px;">1.prometheus.yml

redis-shake.json-toc" style="margin-left:80px;">2.redis-shake.json

四.grafana


redis-shake%20v4">一.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

redis-shake%E5%90%8E">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%E9%85%8D%E7%BD%AE">二.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%E9%85%8D%E7%BD%AE">三.prometheus配置

prometheus.yml">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地址

redis-shake.json">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中,就可以设置自己想要的监控界面了


http://www.niftyadmin.cn/n/5457123.html

相关文章

【差分约束+并查集】第十三届蓝桥杯省赛C++ A组 Java A组/研究生组《推导部分和》(C++)

【题目描述】 【输入格式】 【输出格式】 【数据范围】 【输入样例】 5 3 3 1 5 15 4 5 9 2 3 5 1 5 1 3 1 2 【输出样例】 15 6 UNKNOWN 【思路】 题解来源&#xff1a;AcWing 4651. $\Huge\color{gold}{推导部分和}$ - AcWing 【代码】 #include<bits/stdc.h> #define…

探索多种数据格式:JSON、YAML、XML、CSV等数据格式详解与比较

title: 探索多种数据格式&#xff1a;JSON、YAML、XML、CSV等数据格式详解与比较 date: 2024/3/28 17:34:03 updated: 2024/3/28 17:34:03 tags: 数据格式JSONYAMLXMLCSV数据交换格式比较 1. 数据格式介绍 数据格式是用于组织和存储数据的规范化结构&#xff0c;不同的数据格…

数据库内数据已清除,刷新后又出现

背景 源于客户需求要写一个告警接口&#xff0c;对第三方接口的返回值进行判断&#xff0c;达到一定数值后要推送告警&#xff0c;数值正常后要推送告警恢复。经过对数据的分析以及接口逻辑处理&#xff0c;采用数据库查询写入等方式。&#xff08;对此告警接口感兴趣的朋友请…

开源模型应用落地-qwen1.5-7b-chat-LoRA微调(二)

一、前言 预训练模型提供的是通用能力,对于某些特定领域的问题可能不够擅长,通过微调可以让模型更适应这些特定领域的需求,让它更擅长解决具体的问题。 本篇是开源模型应用落地-qwen-7b-chat-LoRA微调(一)进阶篇,学习通义千问最新1.5系列模型的微调方式。 二、术语介绍 …

GitHub开源项目权限管理-使用账号和个人令牌访问

1.打开后台账号设置 2.找到左下角的Developer settings 3.找到Personal access tokens 的 Tokens(classic) 4.选择创建新证书 5.填写证书信息 6.点击生成证书&#xff0c;复制证书并且保存起来&#xff08;血泪教训&#xff0c;证书只会在创建时显示一次&#xff0c;以后就再也…

8.均值滤波

1 简介 均值滤波是一种低通滤波&#xff0c;它可以有效过滤图片中的椒盐噪声&#xff0c;但是副作用也同样明显&#xff0c;会使图片的边缘过于模糊。   均值滤波的卷积核系数均为1。   这里最终重复一下算法实现以及验证的步骤&#xff1a;     1.MATLAB读取图片并转化…

LibreOffice 将word,excel,PowerPoint文件转换PDF

安装LibreOffice并将Word和Excel文件转换为PDF文件&#xff0c;并设置文件存放路径的步骤如下&#xff1a; 1. 安装LibreOffice 如果尚未安装LibreOffice&#xff0c;可以通过以下命令在Ubuntu上安装&#xff1a; sudo apt update sudo apt install libreoffice 2. 使用Li…

C/C++弹窗提示函数 | 简单易懂,没有废话

头文件&#xff1a; 函数格式&#xff1a; 弹窗函数格式&#xff1a; 返回按钮常量函数格式&#xff1a; 常量&#xff1a; 按钮常量&#xff1a; 图标常量&#xff1a; 1.错误图标 2.信息图标 3.提问图标 4.警告图标 返回值常量&#xff1a; 头文件&#xff1a; #in…