server_status_queries.lib.php 4.8 KB

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