note 89603 added to function.memcache-getstats

From: Date: Mon, 16 Mar 2009 11:58:35 +0000
Subject: note 89603 added to function.memcache-getstats
Groups: php.notes 
Request: Send a blank email to php-notes+get-151987@lists.php.net to get a copy of this message
Here is a memcache stats analyzer method that can be used to print memcache stats in a nice informative tabular format. <?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>"; } ?> Sample usage: <?php $memcache_obj = new Memcache; $memcache_obj->addServer('memcache_host', 11211); printDetails($memcache_obj->getStats()); ?> ---- Server IP: 208.69.120.35 Probable Submitter: 75.150.178.125 ---- Manual Page -- http://www.php.net/manual/en/function.memcache-getstats.php Edit -- https://master.php.net/note/edit/89603 Del: integrated -- https://master.php.net/note/delete/89603/integrated Del: useless -- https://master.php.net/note/delete/89603/useless Del: bad code -- https://master.php.net/note/delete/89603/bad+code Del: spam -- https://master.php.net/note/delete/89603/spam Del: non-english -- https://master.php.net/note/delete/89603/non-english Del: in docs -- https://master.php.net/note/delete/89603/in+docs Del: other reasons-- https://master.php.net/note/delete/89603 Reject -- https://master.php.net/note/reject/89603 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#151987) next »