Memcached stats 命令(建议收藏)

Memcached stats 命令:掌握缓存系统运行状态的钥匙

在现代 Web 应用开发中,缓存技术扮演着至关重要的角色。它能有效减轻数据库压力、提升页面响应速度,是构建高性能系统的基础组件之一。而 Memcached 作为最经典的分布式内存缓存系统,广泛应用于各类高并发场景。但你是否曾想过:如何知道 Memcached 正在“忙”什么?缓存命中率如何?是否出现了内存不足?这些问题的答案,就藏在一条简单却强大的命令里——Memcached stats 命令

这条命令就像缓存系统的“体检报告”,能让你清晰看到系统当前的运行状态、性能指标和资源使用情况。无论你是刚接触缓存的初学者,还是有一定经验的中级开发者,掌握它都至关重要。接下来,我们就一步步揭开它的神秘面纱。

什么是 Memcached stats 命令?

Memcached 是一个基于内存的键值存储系统,它不持久化数据,而是将数据存储在 RAM 中,从而实现极快的读写速度。但正因为数据在内存中,我们无法直接“看到”它的内部运行状态,这就需要借助命令行工具来获取信息。

Memcached stats 命令就是与 Memcached 服务通信、获取其运行时统计信息的核心命令。它通过 Telnet 或 telnet 命令连接到 Memcached 服务的默认端口(通常是 11211),发送一条 stats 指令,然后接收返回的详细数据。

这个命令本身并不修改任何数据,属于只读操作,非常适合用于监控和排查问题。

💡 类比理解:你可以把 Memcached 想象成一个智能快递柜,而 stats 命令就是你打开柜门查看内部状态的“管理面板”——它告诉你有多少格子被占用了,哪些包裹在等待取件,系统是否过载等。

如何使用 Memcached stats 命令?

使用 stats 命令非常简单,只需要一个支持 Telnet 的终端工具即可。以下是完整操作流程:

telnet localhost 11211

执行后,如果连接成功,你会看到类似如下提示:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

接着输入 stats 并回车:

stats

服务端会返回大量信息,格式如下:

STAT pid 12345
STAT uptime 3600
STAT time 1712345678
STAT version 1.6.15
STAT pointer_size 8
STAT rusage_user 0.120000
STAT rusage_system 0.080000
STAT curr_connections 10
STAT total_connections 100
STAT connection_structures 12
STAT reserved_fds 20
STAT cmd_get 5000
STAT cmd_set 2000
STAT get_hits 4500
STAT get_misses 500
STAT delete_hits 100
STAT delete_misses 20
STAT incr_hits 300
STAT incr_misses 100
STAT decr_hits 200
STAT decr_misses 50
STAT cas_hits 150
STAT cas_misses 50
STAT cas_badval 10
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 450000
STAT bytes_written 600000
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 50
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT malloc_max_allowed 1073741824
STAT bytes 250000
STAT curr_items 1500
STAT total_items 2000
STAT expired_unfetched 100
STAT evicted_unfetched 50
STAT evictions 200
STAT reclaimed 150
STAT crawler_reclaimed 10
STAT lrutail_reflocked 0
STAT crawler_entries 0
STAT lru_crawler_running 0
STAT lru_maintainer_juggler 0
STAT lru_maintainer_juggler_sleep 10
STAT lru_maintainer_juggler_runs 50
STAT lru_maintainer_juggler_sleeps 50
STAT lru_maintainer_juggler_time 0.001
STAT lru_maintainer_juggler_time_total 0.050
STAT lru_maintainer_juggler_time_avg 0.001
STAT lru_maintainer_juggler_time_max 0.005
STAT lru_maintainer_juggler_time_min 0.000
STAT lru_maintainer_juggler_time_stddev 0.001
STAT lru_maintainer_juggler_time_median 0.001
STAT lru_maintainer_juggler_time_95th 0.005
STAT lru_maintainer_juggler_time_99th 0.005
STAT lru_maintainer_juggler_time_99_9th 0.005
STAT lru_maintainer_juggler_time_99_99th 0.005
STAT lru_maintainer_juggler_time_99_999th 0.005
STAT lru_maintainer_juggler_time_99_9999th 0.005
STAT lru_maintainer_juggler_time_99_99999th 0.005
STAT lru_maintainer_juggler_time_99_999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_99_9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999th 0.005
STAT lru_maintainer_juggler_time_9