|NO.Z.00031|——————————|^^ 配置 ^^|——|Hadoop&Redis.V07|——|Redis.v07|监视器|

一、Redis监视器:监视器
### --- 监视器

~~~     Redis客户端通过执行MONITOR命令可以将自己变为一个监视器,
~~~     实时地接受并打印出服务器当前处理的命令请求的相关信息。
~~~     此时,当其他客户端向服务器发送一条命令请求时,服务器除了会处理这条命令请求之外,
~~~     还会将这条命令请求的信息发送给所有监视器。
### --- Redis客户端1

127.0.0.1:6379> monitor
OK
1631795768.802450 [0 127.0.0.1:43976] "COMMAND"
1631795777.655054 [0 127.0.0.1:43976] "set" "name:10" "zhaoyun"
1631795782.508276 [0 127.0.0.1:43976] "get" "name:10"
### --- Redis客户端2

[root@linux123 bin]# ./redis-cli 
127.0.0.1:6379> set name:10 zhaoyun
OK
127.0.0.1:6379> get name:10
"zhaoyun"
二、实现监视器
### --- 监视器
~~~     redisServer 维护一个monitors 的链表,记录自己的监视器,
~~~     每次收到MONITOR 命令之后,将客户端追加到链表尾。

void monitorCommand(redisClient *c) {
    /* ignore MONITOR if already slave or in monitor mode */
    if (c->flags & REDIS_SLAVE) return;
        c->flags |= (REDIS_SLAVE|REDIS_MONITOR);
        listAddNodeTail(server.monitors,c);
        addReply(c,shared.ok);         // 回复OK
}
### --- 向监视器发送命令信息

~~~     利用call函数实现向监视器发送命令
### --- call 主要调用了replicationFeedMonitors ,
~~~     这个函数的作用就是将命令打包为协议,发送给监视器。

// call() 函数是执行命令的核心函数,这里只看监视器部分
/*src/redis.c/call*/
/* Call() is the core of Redis execution of a command */
void call(redisClient *c, int flags) {
    long long dirty, start = ustime(), duration;
    int client_old_flags = c->flags;
    /* Sent the command to clients in MONITOR mode, only if the commands are
    * not generated from reading an AOF. */
    if (listLength(server.monitors) &&
        !server.loading &&
        !(c->cmd->flags & REDIS_CMD_SKIP_MONITOR))
        {
        replicationFeedMonitors(c,server.monitors,c->db->id,c->argv,c->argc);
    }
    ......
}
三、Redis监控平台
### --- grafana、prometheus以及redis_exporter。

~~~     # Grafana 
~~~     是一个开箱即用的可视化工具,具有功能齐全的度量仪表盘和图形编辑器,
~~~     有灵活丰富的图形化选项,可以混合多种风格,支持多个数据源特点。
~~~     # Prometheus
~~~     是一个开源的服务监控系统,
~~~     它通过HTTP协议从远程的机器收集数据并存储在本地的时序数据库上。
~~~     # redis_exporter
~~~     为Prometheus提供了redis指标的导出,配合Prometheus以及grafana进行可视化及监控。

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(22)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示