server_status_queries.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Displays query statistics for the server
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. require_once 'libraries/common.inc.php';
  9. require_once 'libraries/server_common.inc.php';
  10. require_once 'libraries/ServerStatusData.class.php';
  11. if (PMA_DRIZZLE) {
  12. $server_master_status = false;
  13. $server_slave_status = false;
  14. } else {
  15. include_once 'libraries/replication.inc.php';
  16. include_once 'libraries/replication_gui.lib.php';
  17. }
  18. $ServerStatusData = new PMA_ServerStatusData();
  19. $response = PMA_Response::getInstance();
  20. $header = $response->getHeader();
  21. $scripts = $header->getScripts();
  22. $scripts->addFile('server_status_queries.js');
  23. /* < IE 9 doesn't support canvas natively */
  24. if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) {
  25. $scripts->addFile('jqplot/excanvas.js');
  26. }
  27. // for charting
  28. $scripts->addFile('jqplot/jquery.jqplot.js');
  29. $scripts->addFile('jqplot/plugins/jqplot.pieRenderer.js');
  30. $scripts->addFile('jqplot/plugins/jqplot.canvasTextRenderer.js');
  31. $scripts->addFile('jqplot/plugins/jqplot.canvasAxisLabelRenderer.js');
  32. $scripts->addFile('jqplot/plugins/jqplot.dateAxisRenderer.js');
  33. $scripts->addFile('jqplot/plugins/jqplot.highlighter.js');
  34. $scripts->addFile('jqplot/plugins/jqplot.cursor.js');
  35. $scripts->addFile('jquery/jquery.tablesorter.js');
  36. $scripts->addFile('server_status_sorter.js');
  37. // Add the html content to the response
  38. $response->addHTML('<div>');
  39. $response->addHTML($ServerStatusData->getMenuHtml());
  40. $response->addHTML(getQueryStatisticsHtml($ServerStatusData));
  41. $response->addHTML('</div>');
  42. exit;
  43. /**
  44. * Returns the html content for the query statistics
  45. *
  46. * @param object $ServerStatusData An instance of the PMA_ServerStatusData class
  47. *
  48. * @return string
  49. */
  50. function getQueryStatisticsHtml($ServerStatusData)
  51. {
  52. $retval = '';
  53. $hour_factor = 3600 / $ServerStatusData->status['Uptime'];
  54. $used_queries = $ServerStatusData->used_queries;
  55. $total_queries = array_sum($used_queries);
  56. $retval .= '<h3 id="serverstatusqueries">';
  57. /* l10n: Questions is the name of a MySQL Status variable */
  58. $retval .= sprintf(
  59. __('Questions since startup: %s'),
  60. PMA_Util::formatNumber($total_queries, 0)
  61. );
  62. $retval .= ' ';
  63. $retval .= PMA_Util::showMySQLDocu(
  64. 'server-status-variables',
  65. 'server-status-variables',
  66. false,
  67. 'statvar_Questions'
  68. );
  69. $retval .= '<br />';
  70. $retval .= '<span>';
  71. $retval .= '&oslash; ' . __('per hour') . ': ';
  72. $retval .= PMA_Util::formatNumber($total_queries * $hour_factor, 0);
  73. $retval .= '<br />';
  74. $retval .= '&oslash; ' . __('per minute') . ': ';
  75. $retval .= PMA_Util::formatNumber($total_queries * 60 / $ServerStatusData->status['Uptime'], 0);
  76. $retval .= '<br />';
  77. if ($total_queries / $ServerStatusData->status['Uptime'] >= 1) {
  78. $retval .= '&oslash; ' . __('per second') . ': ';
  79. $retval .= PMA_Util::formatNumber($total_queries / $ServerStatusData->status['Uptime'], 0);
  80. }
  81. $retval .= '</span>';
  82. $retval .= '</h3>';
  83. // reverse sort by value to show most used statements first
  84. arsort($used_queries);
  85. $odd_row = true;
  86. $perc_factor = 100 / $total_queries; //(- $ServerStatusData->status['Connections']);
  87. $retval .= '<table id="serverstatusqueriesdetails" class="data sortable noclick">';
  88. $retval .= '<col class="namecol" />';
  89. $retval .= '<col class="valuecol" span="3" />';
  90. $retval .= '<thead>';
  91. $retval .= '<tr><th>' . __('Statements') . '</th>';
  92. $retval .= '<th>';
  93. /* l10n: # = Amount of queries */
  94. $retval .= __('#');
  95. $retval .= '</th>';
  96. $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
  97. $retval .= '<th>%</th>';
  98. $retval .= '</tr>';
  99. $retval .= '</thead>';
  100. $retval .= '<tbody>';
  101. $chart_json = array();
  102. $query_sum = array_sum($used_queries);
  103. $other_sum = 0;
  104. foreach ($used_queries as $name => $value) {
  105. $odd_row = !$odd_row;
  106. // For the percentage column, use Questions - Connections, because
  107. // the number of connections is not an item of the Query types
  108. // but is included in Questions. Then the total of the percentages is 100.
  109. $name = str_replace(array('Com_', '_'), array('', ' '), $name);
  110. // Group together values that make out less than 2% into "Other", but only
  111. // if we have more than 6 fractions already
  112. if ($value < $query_sum * 0.02 && count($chart_json)>6) {
  113. $other_sum += $value;
  114. } else {
  115. $chart_json[$name] = $value;
  116. }
  117. $retval .= '<tr class="';
  118. $retval .= $odd_row ? 'odd' : 'even';
  119. $retval .= '">';
  120. $retval .= '<th class="name">' . htmlspecialchars($name) . '</th>';
  121. $retval .= '<td class="value">';
  122. $retval .= htmlspecialchars(PMA_Util::formatNumber($value, 5, 0, true));
  123. $retval .= '</td>';
  124. $retval .= '<td class="value">';
  125. $retval .= htmlspecialchars(
  126. PMA_Util::formatNumber($value * $hour_factor, 4, 1, true)
  127. );
  128. $retval .= '</td>';
  129. $retval .= '<td class="value">';
  130. $retval .= htmlspecialchars(
  131. PMA_Util::formatNumber($value * $perc_factor, 0, 2)
  132. );
  133. $retval .= '</td>';
  134. $retval .= '</tr>';
  135. }
  136. $retval .= '</tbody>';
  137. $retval .= '</table>';
  138. $retval .= '<div id="serverstatusquerieschart"></div>';
  139. $retval .= '<div id="serverstatusquerieschart_data" style="display:none;">';
  140. if ($other_sum > 0) {
  141. $chart_json[__('Other')] = $other_sum;
  142. }
  143. $retval .= htmlspecialchars(json_encode($chart_json));
  144. $retval .= '</div>';
  145. return $retval;
  146. }
  147. ?>