如何查看Memcache 运行状态 stats(Status) —— Memcache Telnet 接口

简介:


     下面主要介绍一下如果监控 memcached 实例的运行情况. 我们需要明确的是需要通过 telnet才能获得Memcache的运行信息. 下面详细介绍下Memcache Telnet接口的主要用法。

连接到Telnet

     当Memcache启动后,可以先使用 "ps -ef"查看哪一个 IP 和 端口正在被Memcache进程使用,如果知道了Memcache运行的ip和端口,我们可以通过下面这个命令访问Memcache实例:

telnet 10.0.0.2 11211

Memcache 命令

下面是一些主要用到的命令,具体详细情况请查阅官方文档 doc/protocol.txt

Command Description Example
get Reads a value get mykey
set Set a key unconditionally set mykey 0 60 5
add Add a new key add newkey 0 60 5
replace Overwrite existing key replace key 0 60 5
append Append data to existing key append key 0 60 15
prepend Prepend data to existing key prepend key 0 60 15
incr Increments numerical key value by given number incr mykey 2
decr Decrements numerical key value by given number decr mykey 5
delete Deletes an existing key delete mykey
flush_all Invalidate specific items immediately flush_all
Invalidate all items in n seconds flush_all 900
stats Prints general statistics stats
Prints memory statistics stats slabs
Prints memory statistics stats malloc
Print higher level allocation statistics stats items
  stats detail
  stats sizes
Resets statistics stats reset
version Prints server version. version
verbosity Increases log level verbosity
quit Terminate telnet session quit

查看Statistics

通过下面命令查看 statistics 信息:

stats
你会获得一个服务状态的详细列表信息,具体情况如下:
 
  
参数 描述
pid 7862 memcache服务器进程ID
uptime 12617972 服务器已运行秒数
time 1320756409 服务器当前Unix时间戳
version 1.4.5 memcache版本
pointer_size 64 操作系统指针大小
rusage_user 1.731736 进程累计用户时间
rusage_system 251.421778 进程累计系统时间
curr_connections 41 当前连接数量
total_connections 848 Memcached运行以来连接总数
connection_structures 46 Memcached分配的连接结构数量
cmd_get 164377 get命令请求次数
cmd_set 58617 set命令请求次数
cmd_flush 0 flush命令请求次数
get_hits 105598 get命令命中次数
get_misses 58779 get命令未命中次数
delete_misses 0 delete命令未命中次数
delete_hits 0 delete命令命中次数
incr_misses 0 incr命令未命中次数
incr_hits 0 incr命令命中次数
decr_misses 0 decr命令未命中次数
decr_hits 0 decr命令命中次数
cas_misses 0 cas命令未命中次数
cas_hits 0 cas命令命中次数
cas_badval 0 使用擦拭次数
auth_cmds 0 认证命令处理的次数
auth_errors 0 认证失败数目
bytes_read 262113283 读取总字节数
bytes_written 460023263 发送总字节数
limit_maxbytes 536870912 分配的内存总大小(字节)
accepting_conns 1 服务器是否达到过最大连接(0/1)
listen_disabled_num 0 失效的监听数
threads 4 当前线程数
conn_yields 0 连接操作主动放弃数目
bytes 1941693 当前存储占用的字节数
curr_items 476 当前存储的数据总数
total_items 58617 启动以来存储的数据总数
evictions 0 LRU释放的对象数目
reclaimed 48830 已过期的数据条目来存储新数据的数目
     如果你不确定你是否有足够的内存,你可以通过查看 evictions”的值来确定Memcache实例的内存使用情况,如果还有足够的内存,那么 evictions”的值应该为0或者不在增长。

查看 Memory Statistics

你可以通过下面命令查看当前 memory statistics :

stats slabs

Example:

STAT 1:chunk_size 80
STAT 1:chunks_per_page 13107
STAT 1:total_pages 1
STAT 1:total_chunks 13107
STAT 1:used_chunks 13106
STAT 1:free_chunks 1
STAT 1:free_chunks_end 12886
STAT 2:chunk_size 100
STAT 2:chunks_per_page 10485
STAT 2:total_pages 1
STAT 2:total_chunks 10485
STAT 2:used_chunks 10484
STAT 2:free_chunks 1
STAT 2:free_chunks_end 10477
[...]
STAT active_slabs 3
STAT total_malloced 3145436
END

查看各个Slab中Item的数目和年龄(最后一次访问距现在的秒数)

stats items
 结果:
stats items
STAT items:1:number 220
STAT items:1:age 83095
STAT items:2:number 7
STAT items:2:age 1405
[...]
END

清空统计数据

stats resets

显示内存分配数据

stats malloc

设置或显示详细操作记录

stats detail [on|off|dump]

清空所有键值

flush_all

退出

quit

最大有效期为 30 !

     不要设置过期时间超过30天,如果超过30天,Memcache会把它当做一个 Unix timestamp。

      设置最大有效期(2592000ms)例子:

set my_key 0 2592000 1
1

目录
相关文章
|
8月前
|
监控 网络协议 算法
Telnet、DHCP、静态路由、等价路由、环回接口、浮动静态路由详解
Telnet是位于OSI模型的第7层—应用层上的一种协议,是一个通过创建虚拟终端提供连接到远程主机终端仿真的TCP/IP协议。这一协议需要通过用户名和口令进行认证,是Internet远程登陆服务的标准协议。应用Telnet协议能够把本地用户所使用的计算机变成远程主机系统的一个终端。它提供了三种基本服务:
149 0
|
Web App开发 Dubbo 应用服务中间件
[雪峰磁针石博客]python工具库介绍-dubbo:通过telnet接口访问dubbo服务
Django - The Easy Way pdf - 2017 [下载地址](https://itbooks.pipipan.com/fs/18113597-305049783) Django is a very powerful Python Web Framework.
|
5月前
|
Linux 网络安全
linux端口连通性测试telnet、wget、ssh、curl
linux端口连通性测试telnet、wget、ssh、curl
|
6月前
|
安全 Linux
Linux安装Telnet
Linux安装Telnet
67 0
|
1月前
|
网络协议 Shell Linux
【Shell 命令集合 网络通讯 】⭐Linux 远程登录工具 telnet 命令 使用指南
【Shell 命令集合 网络通讯 】⭐Linux 远程登录工具 telnet 命令 使用指南
30 0
|
2月前
|
Linux Shell
mac/linux提示bash: telnet: command not found
mac/linux提示bash: telnet: command not found
|
2月前
|
安全 网络协议 Linux
linux命令之telnet
linux命令之telnet
31 4
|
3月前
|
运维 网络协议 Linux
linux/windows如何退出telnet
linux/windows如何退出telnet
57 0
|
5月前
|
Linux
Linux命令(9)之telnet
Linux命令(9)之telnet
48 2
|
7月前
|
网络协议 安全 Linux
Linux安装telnet
Linux安装telnet
149 0