PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/mysql_stats.php

https://github.com/Bigjoos/U-232
PHP | 320 lines | 238 code | 65 blank | 17 comment | 29 complexity | f3ebfc2fbb803e38a5d9eb541ed514b9 MD5 | raw file
  1. <?php
  2. /**
  3. * http://btdev.net:1337/svn/test/Installer09_Beta
  4. * Licence Info: GPL
  5. * Copyright (C) 2010 BTDev Installer v.1
  6. * A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
  7. * Project Leaders: Mindless,putyn.
  8. **/
  9. if ( ! defined( 'IN_TBDEV_ADMIN' ) )
  10. {
  11. $HTMLOUT='';
  12. $HTMLOUT .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
  13. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
  14. <html xmlns='http://www.w3.org/1999/xhtml'>
  15. <head>
  16. <title>Error!</title>
  17. </head>
  18. <body>
  19. <div style='font-size:33px;color:white;background-color:red;text-align:center;'>Incorrect access<br />You cannot access this file directly.</div>
  20. </body></html>";
  21. print $HTMLOUT;
  22. exit();
  23. }
  24. require_once(INCL_DIR.'user_functions.php');
  25. if (!min_class(UC_SYSOP)) // or just simply: if (!min_class(UC_STAFF))
  26. header( "Location: {$INSTALLER09['baseurl']}/index.php");
  27. $GLOBALS["byteUnits"] = array('Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB');
  28. $day_of_week = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
  29. $month = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
  30. // See http://www.php.net/manual/en/function.strftime.php to define the
  31. // variable below
  32. $datefmt = '%B %d, %Y at %I:%M %p';
  33. $timespanfmt = '%s days, %s hours, %s minutes and %s seconds';
  34. ////////////////// FUNCTION LIST /////////////////////////
  35. function byteformat($value, $limes = 2, $comma = 0) {
  36. $dh = pow(10, $comma);
  37. $li = pow(10, $limes);
  38. $return_value = $value;
  39. $unit = $GLOBALS['byteUnits'][0];
  40. for ( $d = 6, $ex = 15; $d >= 1; $d--, $ex-=3 )
  41. {
  42. if (isset($GLOBALS['byteUnits'][$d]) && $value >= $li * pow(10, $ex))
  43. {
  44. $value = round($value / ( pow(1024, $d) / $dh) ) /$dh;
  45. $unit = $GLOBALS['byteUnits'][$d];
  46. break 1;
  47. } // end if
  48. } // end for
  49. if ($unit != $GLOBALS['byteUnits'][0]) {
  50. $return_value = number_format($value, $comma, '.', ',');
  51. }
  52. else
  53. {
  54. $return_value = number_format($value, 0, '.', ',');
  55. }
  56. return array($return_value, $unit);
  57. } // end of the 'formatByteDown' function
  58. function timespanFormat($seconds) {
  59. $return_string = '';
  60. $days = floor($seconds / 86400);
  61. if ($days > 0)
  62. {
  63. $seconds -= $days * 86400;
  64. }
  65. $hours = floor($seconds / 3600);
  66. if ($days > 0 || $hours > 0)
  67. {
  68. $seconds -= $hours * 3600;
  69. }
  70. $minutes = floor($seconds / 60);
  71. if ($days > 0 || $hours > 0 || $minutes > 0)
  72. {
  73. $seconds -= $minutes * 60;
  74. }
  75. return (string)$days." Days ". (string)$hours." Hours ". (string)$minutes." Minutes ". (string)$seconds." Seconds ";
  76. }
  77. function localisedDate($timestamp = -1, $format = '') {
  78. global $datefmt, $month, $day_of_week;
  79. if ($format == '')
  80. {
  81. $format = $datefmt;
  82. }
  83. if ($timestamp == -1)
  84. {
  85. $timestamp = time();
  86. }
  87. $date = preg_replace('@%[aA]@', $day_of_week[(int)strftime('%w', $timestamp)], $format);
  88. $date = preg_replace('@%[bB]@', $month[(int)strftime('%m', $timestamp)-1], $date);
  89. return strftime($date, $timestamp);
  90. } // end of the 'localisedDate()' function
  91. ////////////////////// END FUNCTION LIST /////////////////////////////////////
  92. $HTMLOUT = '';
  93. $HTMLOUT .="<h2>Mysql Server Status</h2>";
  94. //$res = sql_query('SHOW STATUS') or sqlerr(__FILE__,__LINE__);
  95. $res = sql_query('SHOW GLOBAL STATUS') or sqlerr(__FILE__,__LINE__);
  96. while ($row = mysqli_fetch_row($res))
  97. {
  98. $serverStatus[$row[0]] = $row[1];
  99. }
  100. @((mysqli_free_result($res) || (is_object($res) && (get_class($res) == "mysqli_result"))) ? true : false);
  101. unset($res);
  102. unset($row);
  103. $res = sql_query('SELECT UNIX_TIMESTAMP() - ' . $serverStatus['Uptime']);
  104. $row = mysqli_fetch_row($res);
  105. $HTMLOUT .= "<table class='torrenttable' border='1'>
  106. <tr>
  107. <td>This MySQL server has been running for ". timespanFormat($serverStatus['Uptime']) .". It started up on ". localisedDate($row[0]) . "
  108. </td>
  109. </tr>
  110. </table><br />";
  111. ((mysqli_free_result($res) || (is_object($res) && (get_class($res) == "mysqli_result"))) ? true : false);
  112. unset($res);
  113. unset($row);
  114. //Get query statistics
  115. $queryStats = array();
  116. $tmp_array = $serverStatus;
  117. foreach($tmp_array AS $name => $value)
  118. {
  119. if (substr($name, 0, 4) == 'Com_')
  120. {
  121. $queryStats[str_replace('_', ' ', substr($name, 4))] = $value;
  122. unset($serverStatus[$name]);
  123. }
  124. }
  125. unset($tmp_array);
  126. $TRAFFIC_STATS = '';
  127. $TRAFFIC_STATS_HEAD = "<!-- Server Traffic -->
  128. <b>Server traffic:</b> These tables show the network traffic statistics of this MySQL server since its startup";
  129. $TRAFFIC_STATS .= "<table class='torrenttable' width='100%' border='0'>
  130. <tr>
  131. <td colspan='3' bgcolor='lightgrey'>&nbsp;Traffic&nbsp;&nbsp;&nbsp;Per Hour&nbsp;</td>
  132. </tr>
  133. <tr>
  134. <td bgcolor='#EFF3FF'>&nbsp;Received&nbsp;</td>
  135. <td bgcolor='#EFF3FF' align='right'>&nbsp;". join(' ', byteformat($serverStatus['Bytes_received']))."&nbsp;</td>
  136. <td bgcolor='#EFF3FF' align='right'>&nbsp;". join(' ', byteformat($serverStatus['Bytes_received'] * 3600 / $serverStatus['Uptime']))."&nbsp;</td>
  137. </tr>
  138. <tr>
  139. <td bgcolor='#EFF3FF'>&nbsp;Sent&nbsp;</td>
  140. <td bgcolor='#EFF3FF' align='right'>&nbsp;". join(' ', byteformat($serverStatus['Bytes_sent']))."&nbsp;</td>
  141. <td bgcolor='#EFF3FF' align='right'>&nbsp;". join(' ', byteformat($serverStatus['Bytes_sent'] * 3600 / $serverStatus['Uptime']))."&nbsp;</td>
  142. </tr>
  143. <tr>
  144. <td bgcolor='lightgrey'>&nbsp;Total&nbsp;</td>
  145. <td bgcolor='lightgrey' align='right'>&nbsp;". join(' ', byteformat($serverStatus['Bytes_received'] + $serverStatus['Bytes_sent']))."&nbsp;</td>
  146. <td bgcolor='lightgrey' align='right'>&nbsp;". join(' ', byteformat(($serverStatus['Bytes_received'] + $serverStatus['Bytes_sent']) * 3600 / $serverStatus['Uptime']))."&nbsp;</td>
  147. </tr>
  148. </table>";
  149. $TRAFFIC_STATS2 = "<table class='torrenttable' width='100%' border='0'>
  150. <tr>
  151. <td colspan='4' bgcolor='lightgrey'>&nbsp;Connections&nbsp;&nbsp;&oslash;&nbsp;Per Hour&nbsp;</td>
  152. </tr>
  153. <tr>
  154. <td bgcolor='#EFF3FF'>&nbsp;Failed Attempts&nbsp;</td>
  155. <td bgcolor='#EFF3FF' align='right'>&nbsp;". number_format($serverStatus['Aborted_connects'], 0, '.', ',')."&nbsp;</td>
  156. <td bgcolor='#EFF3FF' align='right'>&nbsp;". number_format(($serverStatus['Aborted_connects'] * 3600 / $serverStatus['Uptime']), 2, '.', ',')."&nbsp;</td>
  157. <td bgcolor='#EFF3FF' align='right'>&nbsp;". (($serverStatus['Connections'] > 0 ) ? number_format(($serverStatus['Aborted_connects'] * 100 / $serverStatus['Connections']), 2, '.', ',') . "&nbsp;%" : "---"."&nbsp;")."</td>
  158. </tr>
  159. <tr>
  160. <td bgcolor='#EFF3FF'>&nbsp;Aborted Clients&nbsp;</td>
  161. <td bgcolor='#EFF3FF' align='right'>&nbsp;". number_format($serverStatus['Aborted_clients'], 0, '.', ',')."&nbsp;</td>
  162. <td bgcolor='#EFF3FF' align='right'>&nbsp;". number_format(($serverStatus['Aborted_clients'] * 3600 / $serverStatus['Uptime']), 2, '.', ',')."&nbsp;</td>
  163. <td bgcolor='#EFF3FF' align='right'>&nbsp;". (($serverStatus['Connections'] > 0 ) ? number_format(($serverStatus['Aborted_clients'] * 100 / $serverStatus['Connections']), 2 , '.', ',') . '&nbsp;%' : '---')."&nbsp;</td>
  164. </tr>
  165. <tr>
  166. <td bgcolor='lightgrey'>&nbsp;Total&nbsp;</td>
  167. <td bgcolor='lightgrey' align='right'>&nbsp;". number_format($serverStatus['Connections'], 0, '.', ',')."&nbsp;</td>
  168. <td bgcolor='lightgrey' align='right'>&nbsp;". number_format(($serverStatus['Connections'] * 3600 / $serverStatus['Uptime']), 2, '.', ',')."&nbsp;</td>
  169. <td bgcolor='lightgrey' align='right'>&nbsp;". number_format(100, 2, '.', ',')."&nbsp;%&nbsp;</td>
  170. </tr>
  171. </table>";
  172. $QUERY_STATS = '';
  173. $QUERY_STATS .= "<!-- Queries -->
  174. <b>Query Statistics:</b> Since it's start up, ". number_format($serverStatus['Questions'], 0, '.', ',')." queries have been sent to the server.<br />
  175. <table class='torrenttable' width='100%' border='0'>
  176. <tr>
  177. <td bgcolor='lightgrey'>&nbsp;Total&nbsp;</td>
  178. <td bgcolor='lightgrey'>&nbsp;&oslash;&nbsp;Per&nbsp;Hour&nbsp;</td>
  179. <td bgcolor='lightgrey'>&nbsp;&oslash;&nbsp;Per&nbsp;Minute&nbsp;</td>
  180. <td bgcolor='lightgrey'>&nbsp;&oslash;&nbsp;Per&nbsp;Second&nbsp;</td>
  181. </tr>
  182. <tr>
  183. <td bgcolor='#EFF3FF' align='right'>&nbsp;". number_format($serverStatus['Questions'], 0, '.', ',')."&nbsp;</td>
  184. <td bgcolor='#EFF3FF' align='right'>&nbsp;". number_format(($serverStatus['Questions'] * 3600 / $serverStatus['Uptime']), 2, '.', ',')."&nbsp;</td>
  185. <td bgcolor='#EFF3FF' align='right'>&nbsp;". number_format(($serverStatus['Questions'] * 60 / $serverStatus['Uptime']), 2, '.', ',')."&nbsp;</td>
  186. <td bgcolor='#EFF3FF' align='right'>&nbsp;". number_format(($serverStatus['Questions'] / $serverStatus['Uptime']), 2, '.', ',')."&nbsp;</td>
  187. </tr>
  188. </table><br />";
  189. $QUERY_STATS .= "<table class='torrenttable' width='100%' border='0'>
  190. <tr>
  191. <td colspan='2' bgcolor='lightgrey'>&nbsp;Query&nbsp;Type&nbsp;</td>
  192. <td bgcolor='lightgrey'>&nbsp;&oslash;&nbsp;Per&nbsp;Hour&nbsp;</td>
  193. <td bgcolor='lightgrey'>&nbsp;%&nbsp;</td>
  194. </tr>";
  195. $useBgcolorOne = TRUE;
  196. $countRows = 0;
  197. foreach ($queryStats as $name => $value)
  198. {
  199. // For the percentage column, use Questions - Connections, because
  200. // the number of connections is not an item of the Query types
  201. // but is included in Questions. Then the total of the percentages is 100.
  202. $QUERY_STATS .= "<tr>
  203. <td bgcolor='#EFF3FF'>&nbsp;". htmlspecialchars($name)."&nbsp;</td>
  204. <td bgcolor='#EFF3FF' align='right'>&nbsp;". number_format($value, 0, '.', ',')."&nbsp;</td>
  205. <td bgcolor='#EFF3FF' align='right'>&nbsp;". number_format(($value * 3600 / $serverStatus['Uptime']), 2, '.', ',')."&nbsp;</td>
  206. <td bgcolor='#EFF3FF' align='right'>&nbsp;". number_format(($value * 100 / ($serverStatus['Questions'] - $serverStatus['Connections'])), 2, '.', ',')."&nbsp;%&nbsp;</td>
  207. </tr>";
  208. }
  209. unset($countRows);
  210. unset($useBgcolorOne);
  211. $QUERY_STATS .= "</table>";
  212. //Unset used variables
  213. unset($serverStatus['Aborted_clients']);
  214. unset($serverStatus['Aborted_connects']);
  215. unset($serverStatus['Bytes_received']);
  216. unset($serverStatus['Bytes_sent']);
  217. unset($serverStatus['Connections']);
  218. unset($serverStatus['Questions']);
  219. unset($serverStatus['Uptime']);
  220. $STATUS_TABLE = '';
  221. if (!empty($serverStatus))
  222. {
  223. $STATUS_TABLE .= "<!-- Other status variables -->
  224. <b>More status variables</b><br />
  225. <table class='torrenttable' border='0' width='100%'>
  226. <tr>
  227. <td bgcolor='lightgrey'>&nbsp;Variable&nbsp;</td>
  228. <td bgcolor='lightgrey'>&nbsp;Value&nbsp;</td>
  229. </tr>";
  230. $useBgcolorOne = TRUE;
  231. $countRows = 0;
  232. foreach($serverStatus AS $name => $value)
  233. {
  234. $STATUS_TABLE .= "<tr>
  235. <td bgcolor='#EFF3FF'>&nbsp;". htmlspecialchars(str_replace('_', ' ', $name))."&nbsp;</td>
  236. <td bgcolor='#EFF3FF' align='right'>&nbsp;". htmlspecialchars($value)."&nbsp;</td>
  237. </tr>";
  238. }
  239. unset($useBgcolorOne);
  240. $STATUS_TABLE .= "</table>";
  241. }
  242. $HTMLOUT .= "<table class='torrenttable' width='80%' cellpadding='4px'>
  243. <tr>
  244. <td colspan='2' class='colhead'>$TRAFFIC_STATS_HEAD</td>
  245. </tr>
  246. <tr>
  247. <td valign='top'>$TRAFFIC_STATS</td><td valign='top'>$TRAFFIC_STATS2</td>
  248. </tr>
  249. <tr>
  250. <td width='50%' valign='top'>$QUERY_STATS</td><td valign='top'>$STATUS_TABLE</td>
  251. </tr>
  252. </table>";
  253. echo stdhead("Stats Overview") . $HTMLOUT . stdfoot();
  254. ?>