Memcached STATS commands
使用者可以使用 STATS 命令,來查看目前 Memcached 運行的狀態。
Memcached stats command is used to return server statistics such as PID, version, connections, etc.
Memecached 常用操作及 STATS 命令清單
Storage Commands
■ set: Store this data, possibly overwriting any existing data.
■ add: Store this data, only if it does not already exist,
■ replace: Store this data, but only if the data already exists.
■ append: Add this data after the last byte in an existing item.
■ prepend: Same as append, but adding new data before existing data.
■ cas: heck And Set (or Compare And Swap). An operation that stores data, but only if no one else has updated the data since you read it last. Useful for resolving race conditions on updating cache data.
Retrieval Commands
■ get: Command for retrieving data.
■ gets: An alternative get command for using with CAS. Returns a CAS identifier (a unique 64bit number) with the item.
■ delete: Removes an item from the cache, if it exists.
■ incr/decr: Increment and Decrement.
Statistics Commands
■ stats: Return basic stats of the memcached server.
■ stats item: Return items stored in memcached.
!! 輸出 item 資訊 : 獲取像計數,年齡,eviction等由組織ID項目的統計數據
■ stats slabs: Return items stored in memcached. More centered to performance of a slab rather than counts of particular items.
!! 輸出 slab 資訊 : 統計數據,如大小,內存使用情況,命令等數據)
■ stats sizes: A special command that shows you how items would be distributed if slabs were broken into 32byte buckets instead of your current number of slabs. Useful for determining how efficient your slab sizing is.
!! 輸出所有 item 大小和數量
■ flush all: Invalidate all existing cache items. To clear the cache data.
STATS 命令輸出
## stats:查看目前狀態,類似pid,版本,連接等服務器統計 ###
stats
STAT pid 1
STAT uptime 1041 #已運行的時間
STAT time 1603078725 #系統時間
STAT version 1.5.16
STAT libevent 2.0.21-stable
STAT pointer_size 64
STAT rusage_user 0.067929
STAT rusage_system 0.042730
STAT max_connections 65000
STAT curr_connections 5
STAT total_connections 7 #曾經建立的連線累計
STAT rejected_connections 0
STAT connection_structures 6
STAT reserved_fds 5
STAT cmd_get 10 #get資料次數
STAT cmd_set 10 #set資料次數
STAT cmd_flush 1 #執行 flush_all 指令次數
STAT cmd_touch 0
…
STAT bytes 0 #快取資料大小(bytes)
STAT curr_items 0 #目前儲存的item數
STAT total_items 8 #從運行到現在,曾有過的item數累計
STAT slab_global_page_pool 0
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT evicted_active 0
STAT evictions 0 #為了取得空間,而剔除item的數量
…
STAT lru_bumps_dropped 0
END
輸出 slab 資訊 : 統計數據,如大小,內存使用情況,命令等數據)
!!! Memcached uses slab allocator for memory management for preventing memory fragmentation.
> stats slabs
STAT 1:chunk_size 96
STAT 1:chunks_per_page 10922
STAT 1:total_pages 1
STAT 1:total_chunks 10922
STAT 1:used_chunks 1
STAT 1:free_chunks 10921
STAT 1:free_chunks_end 0
STAT 1:mem_requested 70
STAT 1:get_hits 1
STAT 1:cmd_set 3
STAT 1:delete_hits 0
STAT 1:incr_hits 0
STAT 1:decr_hits 0
STAT 1:cas_hits 0
STAT 1:cas_badval 0
STAT 1:touch_hits 0
STAT active_slabs 1
STAT total_malloced 1048576
END
輸出 item 資訊 : 獲取像計數,年齡,eviction等由組織ID項目的統計數據。
> stats items
END
輸出所有 item 大小和數量
> stats sizes
STAT sizes_status disabled
END
memcached-tool
$ sudo amazon-linux-extras install memcached1.5
$ memcached-tool
Usage: memcached-tool <host[:port] | /path/to/socket> [mode]命令格式
> 'command name' 'key' 'flags' 'exptime' 'bytes' 'data block'
--
command name : 命令,像是 set/add/replace 等等。
key : 儲存資料的 key。
flags : 伺服器與數據(由用戶提供)存儲的32位元無符號整數,並在檢索項目時回傳數據
exptime : 存在時間,以秒為單位,0表示永遠存在。
bytes : data block 可儲存的位元數。
data block : 要儲存在 key 上的值。