PHP Conference Japan 2024

Memcache::getStats

(PECL memcache >= 0.2.0)

Memcache::getStats取得伺服器統計資訊

說明

Memcache::getStats(字串 $type = ?, 整數 $slabid = ?, 整數 $limit = 100): 陣列|false

Memcache::getStats() 會傳回一個包含伺服器統計資訊的關聯陣列。陣列鍵對應統計參數,而值對應參數的值。您也可以使用 memcache_get_stats() 函式。

參數

type

要擷取的統計資訊類型。有效值為 {reset, malloc, maps, cachedump, slabs, items, sizes}。根據 memcached 協議規範,這些額外參數「可能會為了 memcache 開發人員的方便而有所變動」。

slabid

type 設定為 cachedump 一起使用,以識別要從哪個 slab 進行傾印。cachedump 命令會佔用伺服器資源,嚴格來說僅供除錯用途使用。

limit

type 設定為 cachedump 一起使用,以限制要傾印的項目數量。

傳回值

傳回伺服器統計資訊的關聯陣列,如果失敗則傳回 false

另請參閱

新增註解

使用者貢獻的註解 4 則註解

mikael at synd dot info
18 年前
pid 此伺服器行程的行程 ID
uptime 此伺服器已執行的秒數
time 根據伺服器的目前 UNIX 時間
version 此伺服器的版本字串
rusage_user 此行程累計的使用者時間
rusage_system 此行程累計的系統時間
curr_items 伺服器目前儲存的項目數量
total_items 自啟動以來,此伺服器儲存的項目總數
bytes 此伺服器用於儲存項目的目前位元組數
curr_connections 開啟的連線數
total_connections 自伺服器開始執行以來開啟的連線總數
connection_structures 伺服器配置的連線結構數
cmd_get 擷取請求的累計數量
cmd_set 儲存請求的累計數量
get_hits 已請求且找到的鍵的數量
get_misses 已請求但找不到的項目的數量
bytes_read 此伺服器從網路讀取的位元組總數
bytes_written 此伺服器傳送到網路的位元組總數
limit_maxbytes 允許此伺服器用於儲存的位元組數。
Amiangshu S. Bosu
15 年前
這是一個 memcache 統計分析器方法,可用於以簡潔易懂的表格格式列印 memcache 統計資訊。

<?php

function printDetails($status){

echo
"<table border='1'>";

echo
"<tr><td>Memcache Server version:</td><td> ".$status ["version"]."</td></tr>";
echo
"<tr><td>Process id of this server process </td><td>".$status ["pid"]."</td></tr>";
echo
"<tr><td>Number of seconds this server has been running </td><td>".$status ["uptime"]."</td></tr>";
echo
"<tr><td>Accumulated user time for this process </td><td>".$status ["rusage_user"]." seconds</td></tr>";
echo
"<tr><td>Accumulated system time for this process </td><td>".$status ["rusage_system"]." seconds</td></tr>";
echo
"<tr><td>Total number of items stored by this server ever since it started </td><td>".$status ["total_items"]."</td></tr>";
echo
"<tr><td>Number of open connections </td><td>".$status ["curr_connections"]."</td></tr>";
echo
"<tr><td>Total number of connections opened since the server started running </td><td>".$status ["total_connections"]."</td></tr>";
echo
"<tr><td>Number of connection structures allocated by the server </td><td>".$status ["connection_structures"]."</td></tr>";
echo
"<tr><td>Cumulative number of retrieval requests </td><td>".$status ["cmd_get"]."</td></tr>";
echo
"<tr><td> Cumulative number of storage requests </td><td>".$status ["cmd_set"]."</td></tr>";

$percCacheHit=((real)$status ["get_hits"]/ (real)$status ["cmd_get"] *100);
$percCacheHit=round($percCacheHit,3);
$percCacheMiss=100-$percCacheHit;

echo
"<tr><td>Number of keys that have been requested and found present </td><td>".$status ["get_hits"]." ($percCacheHit%)</td></tr>";
echo
"<tr><td>Number of items that have been requested and not found </td><td>".$status ["get_misses"]."($percCacheMiss%)</td></tr>";

$MBRead= (real)$status["bytes_read"]/(1024*1024);

echo
"<tr><td>Total number of bytes read by this server from network </td><td>".$MBRead." Mega Bytes</td></tr>";
$MBWrite=(real) $status["bytes_written"]/(1024*1024) ;
echo
"<tr><td>Total number of bytes sent by this server to network </td><td>".$MBWrite." Mega Bytes</td></tr>";
$MBSize=(real) $status["limit_maxbytes"]/(1024*1024) ;
echo
"<tr><td>Number of bytes this server is allowed to use for storage.</td><td>".$MBSize." Mega Bytes</td></tr>";
echo
"<tr><td>Number of valid items removed from cache to free memory for new items.</td><td>".$status ["evictions"]."</td></tr>";

echo
"</table>";

}

?>

範例用法
<?php

$memcache_obj
= new Memcache;
$memcache_obj->addServer('memcache_host', 11211);
printDetails($memcache_obj->getStats());
?>
niktriant89 at gmail dot com
1 年前
GitHub 頁面上最新的官方 Memcached 統計指令輸出說明

https://github.com/memcached/memcached/blob/master/doc/protocol.txt

請檢查您目前的版本
匿名
18 年前
這個函數的統計輸出和 getExtendedStats() 的輸出相同,差別在於 getExtendedStats() 會提供所有使用中伺服器的資訊。
To Top