Redis monitor命令

redis,monitor,命令 · 浏览次数 : 322

小编点评

**MonitorSyntaxMonitorAvailable** **Description:** - A debugging command that streams back every command processed by the Redis server. - Useful for troubleshooting database issues. **Syntax:** ``` redis-cli monitor1339518083.107412 [0 127.0.0.1:60866] "keys" "*1339518087.877697" "dbsize" "1339518090.420270" "set" "x" "6" "1339518096.506257" "get" "x"1339518099.363765 "eval" "return redis.call('set', 'x', '7')" "0"1339518100.363799" "del" "x" ``` **Key Features:** - Monitors command execution in real-time. - Provides detailed information about each command, including the command name, arguments, and execution time. - Can be used via both `redis-cli` and `telnet`. **Benefits:** - Helps identify and troubleshoot database issues. - Provides visibility into command execution. - Can be used to monitor performance and identify bottlenecks. **Cost:** Running `MONITOR` can significantly impact throughput, as it streams back all commands. The cost can be measured using benchmarks, such as `redis-benchmark`. **Note:** - The `SIGINT` signal is used to stop the monitor stream. - Sensitive data is redacted from the command output.

正文

MONITOR

Syntax
MONITOR
Available since:
1.0.0
Time complexity:
ACL categories:
@admin@slow@dangerous

MONITOR is a debugging command that streams back every command processed by the Redis server. It can help in understanding what is happening to the database. This command can both be used via redis-cli and via telnet.

The ability to see all the requests processed by the server is useful in order to spot bugs in an application both when using Redis as a database and as a distributed caching system.

$ redis-cli monitor
1339518083.107412 [0 127.0.0.1:60866] "keys" "*"
1339518087.877697 [0 127.0.0.1:60866] "dbsize"
1339518090.420270 [0 127.0.0.1:60866] "set" "x" "6"
1339518096.506257 [0 127.0.0.1:60866] "get" "x"
1339518099.363765 [0 127.0.0.1:60866] "eval" "return redis.call('set','x','7')" "0"
1339518100.363799 [0 lua] "set" "x" "7"
1339518100.544926 [0 127.0.0.1:60866] "del" "x"

Use SIGINT (Ctrl-C) to stop a MONITOR stream running via redis-cli.

$ telnet localhost 6379
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
MONITOR
+OK
+1339518083.107412 [0 127.0.0.1:60866] "keys" "*"
+1339518087.877697 [0 127.0.0.1:60866] "dbsize"
+1339518090.420270 [0 127.0.0.1:60866] "set" "x" "6"
+1339518096.506257 [0 127.0.0.1:60866] "get" "x"
+1339518099.363765 [0 127.0.0.1:60866] "del" "x"
+1339518100.544926 [0 127.0.0.1:60866] "get" "x"
QUIT
+OK
Connection closed by foreign host.

Manually issue the QUIT or RESET commands to stop a MONITOR stream running via telnet.

Commands not logged by MONITOR

Because of security concerns, no administrative commands are logged by MONITOR's output and sensitive data is redacted in the command AUTH.

Furthermore, the command QUIT is also not logged.

Cost of running MONITOR

Because MONITOR streams back all commands, its use comes at a cost. The following (totally unscientific) benchmark numbers illustrate what the cost of running MONITOR can be.

Benchmark result without MONITOR running:

$ src/redis-benchmark -c 10 -n 100000 -q
PING_INLINE: 101936.80 requests per second
PING_BULK: 102880.66 requests per second
SET: 95419.85 requests per second
GET: 104275.29 requests per second
INCR: 93283.58 requests per second

Benchmark result with MONITOR running (redis-cli monitor > /dev/null):

$ src/redis-benchmark -c 10 -n 100000 -q
PING_INLINE: 58479.53 requests per second
PING_BULK: 59136.61 requests per second
SET: 41823.50 requests per second
GET: 45330.91 requests per second
INCR: 41771.09 requests per second

In this particular case, running a single MONITOR client can reduce the throughput by more than 50%. Running more MONITOR clients will reduce throughput even more.

Return

Non standard return value, just dumps the received commands in an infinite flow.

Behavior change history

与Redis monitor命令相似的内容:

Redis monitor命令

MONITOR Syntax MONITOR Available since:1.0.0Time complexity:ACL categories:@admin, @slow, @dangerous MONITOR is a debugging command that streams back

Linux时间戳转换成易读格式的方法

背景 最近一直在学习Redis相关的知识. 其中遇到了一个redis monitor的命令 但是这里有一个问题是: 原生命令查询出来的时间是Unix时间戳格式的. 不太好发现查看与进行对照. 所以今天中午就进行了简单的学习,希望能够最简单的方式进行转换. 思路 认为awk命令一个就够了. 但是自己a

Redis命令监控与简单分析

Redis命令监控与简单分析 前言 为了能够快速识别分析redis的命令 自己在环境上面进行了一些简单的跟踪以及脚本 这里不全是进行metrics, 细致到具体的命令分析 脚本部分-1 mkdir -p /redismonitor/ cd /redismonitor/ find . -mtime +

[转帖]redis-监控和告警

转载于 https://zhuoroger.github.io/2016/08/20/redis-monitor-and-alarm/?&utm_source=tuicool&utm_medium=referral 可以去他的博客看一下,真的写的很好对于任何应用服务和组件,都需要一套完善可靠谱监控方

35个Redis企业级性能优化点与解决方案

Redis作为企业级应用中广泛使用的高性能键值存储数据库,其性能优化是一个复杂且多面的话题。以下是V 哥整理的一些关键的优化点和相应的解决方案,提供给兄弟们参考。 Redis的性能优化涉及到硬件选择、配置调整、客户端优化、持久化策略等多个层面。 1. 硬件优化 解决方案:选择更快的CPU、更多的内存

Redis 分布式锁

Redis 分布式锁 分布式锁的演变 本地锁(单机用) 利用redis进行分布式锁 使用 set 防止死锁 加过期时间 使用 setnx 防止A请求未执行完 锁过期删除 B请求加锁后 A完成后误删该锁 使用 Hash结构, 规定每个请求只能删除自己的锁 保证并发安全,申请锁和加过期时间需要 原子性,

【长文】带你搞明白Redis

Redis,英文全称是Remote Dictionary Server(远程字典服务),是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。 与MySQL数据库不同的是,Redis的数据是存在内存中的。它的读写速度非常快,每...

(四)Redis 缓存应用、淘汰机制

1、缓存应用 一个系统中不同层面数据访问速度不一样,以计算机为例,CPU、内存和磁盘这三层的访问速度从几十 ns 到 100ns,再到几 ms,性能的差异很大,如果每次 CPU 处理数据时都要到磁盘读取数据,系统运行速度会大大降低。 所以,计算机系统中,默认有两种缓存: (1)CPU 里面的末级缓存

redis性能测试

环境 redis 7.2.5 主频 核心数 内存 2.5GHz 32 64GB 测试结论 当前场景下redis单线程、多线程表现差异不大 使用pipeline模式可以显著提高基准性能 非pipilie下redis性能再12~13w左右 pipiline下redis性能在35w左右 测试记录 单线程r

Redis 常用的数据结构简介与实例测试【Redis 系列二】

〇、都有哪些数据结构? Redis 提供了较为丰富的数据类型,常见的有五种:String(字符串),Hash(哈希),List(列表),Set(集合)、Zset(有序集合)。 随着 Redis 版本的更新,后面又支持了四种数据类型: BitMap(2.2 版新增)、HyperLogLog(2.8 版