|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
分类:
bdv012-redis
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通