Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function sec2hms($num_secs) {
- $str = '';
- $days = intval(intval($num_secs) / 86400);
- $num_secs -= 86400 * $days;
- $str .= $days.'d ';
- $hours = intval(intval($num_secs) / 3600);
- $str .= $hours.':';
- $minutes = intval(((intval($num_secs) / 60) % 60));
- if ($minutes < 10) $str .= '0';
- $str .= $minutes.':';
- $seconds = intval(intval(($num_secs % 60)));
- if ($seconds < 10) $str .= '0';
- $str .= $seconds;
- return($str);
- }
- function printDetails($status)
- {
- $precision = ini_get('precision');
- @ini_set('precision', 16);
- $Bytes= sprintf('%0.2f', $status["bytes"] / (1024*1024));
- $MBSize= sprintf('%0.2f', $status["limit_maxbytes"] / (1024*1024));
- $percCacheHit=0;
- if ($status["cmd_get"])
- $percCacheHit = sprintf('%0.2f', (real)$status["get_hits"] / (real)$status["cmd_get"] * 100);
- $repl = sprintf('%0.2f', $status["cmd_set"] / ($status["cmd_get"] - $status["get_hits"]));
- $getPerSec = sprintf('%0.2f', $status['cmd_get'] / $status["uptime"]);
- $percCacheHit= sprintf('%0.3f', round($percCacheHit,3));
- $percCacheMiss= sprintf('%0.3f', 100 - $percCacheHit);
- $MBRead= sprintf('%0.2f', $status["bytes_read"] / (1024*1024));
- $MBWrite= sprintf('%0.2f', $status["bytes_written"] / (1024*1024));
- echo "<table border='1' width='100%'>\n";
- echo "<tr><td>Memcache Server version:</td><td align='right'> ".$status["version"]."</td></tr>\n";
- //echo "<tr><td>Process id of this server process </td><td>".$status["pid"]."</td></tr>\n";
- echo "<tr><td>Server uptime </td><td align='right'>".sec2hms($status["uptime"])."</td></tr>\n";
- echo "<tr><td>Open connections </td><td align='right'>".$status["curr_connections"]."</td></tr>\n";
- echo "<tr><td>Total connection </td><td align='right'>".$status["total_connections"]."</td></tr>\n";
- echo "<tr><td>Bytes written </td><td align='right'>".$MBWrite." MB</td></tr>\n";
- echo "<tr><td>Bytes read </td><td align='right'>".$MBRead." MB</td></tr>\n";
- //echo "<tr><td>Accumulated user time for this process </td><td>".$status["rusage_user"]." seconds</td></tr>\n";
- //echo "<tr><td>Accumulated system time for this process </td><td>".$status["rusage_system"]." seconds</td></tr>\n";
- echo "<tr><td>Total cache items </td><td align='right'>".$status["total_items"]."</td></tr>\n";
- echo "<tr><td>Memory Usage </td><td align='right'>".$Bytes." MB</td></tr>\n";
- echo "<tr><td>Memory Limit </td><td align='right'>".$MBSize." MB</td></tr>\n";
- //echo "<tr><td>Number of connection structures allocated by the server </td><td>".$status["connection_structures"]."</td></tr>\n";
- echo "<tr><td>get's / sec </td><td align='right'>".$getPerSec."</td></tr>\n";
- echo "<tr><td>Spackled </td><td align='right'>".$repl."</td></tr>\n";
- echo "<tr><td># get's </td><td align='right'>".$status["cmd_get"]."</td></tr>\n";
- echo "<tr><td># put's </td><td align='right'>".$status["cmd_set"]."</td></tr>\n";
- echo "<tr><td>Cache Hit </td><td align='right'>".$percCacheHit."%</td></tr>\n";
- echo "<tr><td>Cache Miss </td><td align='right'>".$percCacheMiss."%</td></tr>\n";
- echo "<tr><td>Evictions </td><td align='right'>".$status["evictions"]."</td></tr>\n";
- echo "</table>\n";
- @ini_set('precision', $precision);
- }
- //$version = $memcache->getVersion();
- //echo "Server's version: ".$version."<br/>\n";
- $server = array();
- $server[] = array('bin'=>'default','host'=>'localhost','port'=>11211);
- $server[] = array('bin'=>'default','host'=>'localhost','port'=>11212);
- $server[] = array('bin'=>'page','host'=>'localhost','port'=>11213);
- $server[] = array('bin'=>'gaits','host'=>'localhost','port'=>11214);
- $server[] = array('bin'=>'filter','host'=>'localhost','port'=>11215);
- $memcache = new Memcache;
- echo "<html><head><title>memcached Status</title></head><body>\n";
- echo "<div style='font-size: 20pt;'>";
- echo "<table width='100%' align='center'>";
- echo " <tr valign='top' align='center'>";
- foreach ($server as $s)
- {
- $h = $s['host'];
- $p = $s['port'];
- $b = $s['bin'];
- echo " <td>";
- echo " <table width='100%'>";
- echo " <tr>";
- echo " <td align='center'>$h:$p<br/>($b)</td>";
- echo " </tr>";
- echo " <tr>";
- echo " <td>";
- if (!@$memcache->connect($h, $p))
- echo " <table width='100%'><tr><td>could not connect to $h:$p</td></tr></table>";
- else
- printDetails($memcache->getStats());
- echo " </td>";
- echo " </tr>";
- echo " </table>";
- echo " </td>";
- $memcache->close();
- }
- echo "</tr></table>";
- //phpinfo();
- echo "</div>";
- echo "</body></html>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement