Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. <?php
  2.  
  3. function sec2hms($num_secs) {
  4. $str = '';
  5.  
  6. $days = intval(intval($num_secs) / 86400);
  7. $num_secs -= 86400 * $days;
  8. $str .= $days.'d ';
  9.  
  10. $hours = intval(intval($num_secs) / 3600);
  11. $str .= $hours.':';
  12.  
  13. $minutes = intval(((intval($num_secs) / 60) % 60));
  14. if ($minutes < 10) $str .= '0';
  15. $str .= $minutes.':';
  16.  
  17. $seconds = intval(intval(($num_secs % 60)));
  18. if ($seconds < 10) $str .= '0';
  19. $str .= $seconds;
  20.  
  21. return($str);
  22. }
  23.  
  24. function printDetails($status)
  25. {
  26. $precision = ini_get('precision');
  27. @ini_set('precision', 16);
  28. $Bytes= sprintf('%0.2f', $status["bytes"] / (1024*1024));
  29. $MBSize= sprintf('%0.2f', $status["limit_maxbytes"] / (1024*1024));
  30. $percCacheHit=0;
  31. if ($status["cmd_get"])
  32. $percCacheHit = sprintf('%0.2f', (real)$status["get_hits"] / (real)$status["cmd_get"] * 100);
  33.  
  34. $repl = sprintf('%0.2f', $status["cmd_set"] / ($status["cmd_get"] - $status["get_hits"]));
  35. $getPerSec = sprintf('%0.2f', $status['cmd_get'] / $status["uptime"]);
  36.  
  37. $percCacheHit= sprintf('%0.3f', round($percCacheHit,3));
  38. $percCacheMiss= sprintf('%0.3f', 100 - $percCacheHit);
  39. $MBRead= sprintf('%0.2f', $status["bytes_read"] / (1024*1024));
  40. $MBWrite= sprintf('%0.2f', $status["bytes_written"] / (1024*1024));
  41.  
  42. echo "<table border='1' width='100%'>\n";
  43. echo "<tr><td>Memcache Server version:</td><td align='right'> ".$status["version"]."</td></tr>\n";
  44. //echo "<tr><td>Process id of this server process </td><td>".$status["pid"]."</td></tr>\n";
  45. echo "<tr><td>Server uptime </td><td align='right'>".sec2hms($status["uptime"])."</td></tr>\n";
  46. echo "<tr><td>Open connections </td><td align='right'>".$status["curr_connections"]."</td></tr>\n";
  47. echo "<tr><td>Total connection </td><td align='right'>".$status["total_connections"]."</td></tr>\n";
  48. echo "<tr><td>Bytes written </td><td align='right'>".$MBWrite." MB</td></tr>\n";
  49. echo "<tr><td>Bytes read </td><td align='right'>".$MBRead." MB</td></tr>\n";
  50. //echo "<tr><td>Accumulated user time for this process </td><td>".$status["rusage_user"]." seconds</td></tr>\n";
  51. //echo "<tr><td>Accumulated system time for this process </td><td>".$status["rusage_system"]." seconds</td></tr>\n";
  52. echo "<tr><td>Total cache items </td><td align='right'>".$status["total_items"]."</td></tr>\n";
  53.  
  54. echo "<tr><td>Memory Usage </td><td align='right'>".$Bytes." MB</td></tr>\n";
  55. echo "<tr><td>Memory Limit </td><td align='right'>".$MBSize." MB</td></tr>\n";
  56.  
  57. //echo "<tr><td>Number of connection structures allocated by the server </td><td>".$status["connection_structures"]."</td></tr>\n";
  58. echo "<tr><td>get's / sec </td><td align='right'>".$getPerSec."</td></tr>\n";
  59. echo "<tr><td>Spackled </td><td align='right'>".$repl."</td></tr>\n";
  60. echo "<tr><td># get's </td><td align='right'>".$status["cmd_get"]."</td></tr>\n";
  61. echo "<tr><td># put's </td><td align='right'>".$status["cmd_set"]."</td></tr>\n";
  62.  
  63. echo "<tr><td>Cache Hit </td><td align='right'>".$percCacheHit."%</td></tr>\n";
  64. echo "<tr><td>Cache Miss </td><td align='right'>".$percCacheMiss."%</td></tr>\n";
  65.  
  66. echo "<tr><td>Evictions </td><td align='right'>".$status["evictions"]."</td></tr>\n";
  67.  
  68. echo "</table>\n";
  69.  
  70. @ini_set('precision', $precision);
  71. }
  72.  
  73.  
  74. //$version = $memcache->getVersion();
  75. //echo "Server's version: ".$version."<br/>\n";
  76.  
  77. $server = array();
  78. $server[] = array('bin'=>'default','host'=>'localhost','port'=>11211);
  79. $server[] = array('bin'=>'default','host'=>'localhost','port'=>11212);
  80. $server[] = array('bin'=>'page','host'=>'localhost','port'=>11213);
  81. $server[] = array('bin'=>'gaits','host'=>'localhost','port'=>11214);
  82. $server[] = array('bin'=>'filter','host'=>'localhost','port'=>11215);
  83.  
  84. $memcache = new Memcache;
  85.  
  86. echo "<html><head><title>memcached Status</title></head><body>\n";
  87. echo "<div style='font-size: 20pt;'>";
  88. echo "<table width='100%' align='center'>";
  89. echo " <tr valign='top' align='center'>";
  90. foreach ($server as $s)
  91. {
  92. $h = $s['host'];
  93. $p = $s['port'];
  94. $b = $s['bin'];
  95.  
  96. echo " <td>";
  97. echo " <table width='100%'>";
  98. echo " <tr>";
  99. echo " <td align='center'>$h:$p<br/>($b)</td>";
  100. echo " </tr>";
  101. echo " <tr>";
  102. echo " <td>";
  103. if (!@$memcache->connect($h, $p))
  104. echo " <table width='100%'><tr><td>could not connect to $h:$p</td></tr></table>";
  105. else
  106. printDetails($memcache->getStats());
  107. echo " </td>";
  108. echo " </tr>";
  109. echo " </table>";
  110. echo " </td>";
  111. $memcache->close();
  112. }
  113. echo "</tr></table>";
  114.  
  115. //phpinfo();
  116. echo "</div>";
  117.  
  118. echo "</body></html>";
  119.  
  120. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement