閱讀569 返回首頁    go 微軟 go windows


如何查看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

最後更新:2017-04-03 12:56:18

  上一篇:go JDBC PreparedStatement 批量查詢 in 的實現 方案
  下一篇:go JDBC PreparedStatement 批量查詢 in 的實現 方案