diff --git a/libraries/server_status_queries.lib.php b/libraries/server_status_queries.lib.php new file mode 100644 index 0000000000..c77da248c2 --- /dev/null +++ b/libraries/server_status_queries.lib.php @@ -0,0 +1,145 @@ +status['Uptime']; + $used_queries = $ServerStatusData->used_queries; + $total_queries = array_sum($used_queries); + + $retval .= '

'; + /* l10n: Questions is the name of a MySQL Status variable */ + $retval .= sprintf( + __('Questions since startup: %s'), + PMA_Util::formatNumber($total_queries, 0) + ); + $retval .= ' '; + $retval .= PMA_Util::showMySQLDocu( + 'server-status-variables', + 'server-status-variables', + false, + 'statvar_Questions' + ); + $retval .= '
'; + $retval .= ''; + $retval .= 'ø ' . __('per hour:') . ' '; + $retval .= PMA_Util::formatNumber($total_queries * $hour_factor, 0); + $retval .= '
'; + $retval .= 'ø ' . __('per minute:') . ' '; + $retval .= PMA_Util::formatNumber($total_queries * 60 / $ServerStatusData->status['Uptime'], 0); + $retval .= '
'; + if ($total_queries / $ServerStatusData->status['Uptime'] >= 1) { + $retval .= 'ø ' . __('per second:') . ' '; + $retval .= PMA_Util::formatNumber($total_queries / $ServerStatusData->status['Uptime'], 0); + } + $retval .= '
'; + $retval .= '

'; + + $retval .= PMA_getHtmlForServerStatusQueriesDetails($ServerStatusData); + + return $retval; +} + +/** + * Returns the html content for the query details + * + * @param object $ServerStatusData An instance of the PMA_ServerStatusData class + * + * @return string + */ +function PMA_getHtmlForServerStatusQueriesDetails($ServerStatusData) +{ + $hour_factor = 3600 / $ServerStatusData->status['Uptime']; + $used_queries = $ServerStatusData->used_queries; + $total_queries = array_sum($used_queries); + // reverse sort by value to show most used statements first + arsort($used_queries); + + $odd_row = true; + $perc_factor = 100 / $total_queries; //(- $ServerStatusData->status['Connections']); + + $retval = ''; + $retval .= ''; + $retval .= ''; + $retval .= ''; + $retval .= ''; + $retval .= ''; + $retval .= ''; + $retval .= ''; + $retval .= ''; + $retval .= ''; + $retval .= ''; + + $chart_json = array(); + $query_sum = array_sum($used_queries); + $other_sum = 0; + foreach ($used_queries as $name => $value) { + $odd_row = !$odd_row; + // For the percentage column, use Questions - Connections, because + // the number of connections is not an item of the Query types + // but is included in Questions. Then the total of the percentages is 100. + $name = str_replace(array('Com_', '_'), array('', ' '), $name); + // Group together values that make out less than 2% into "Other", but only + // if we have more than 6 fractions already + if ($value < $query_sum * 0.02 && count($chart_json)>6) { + $other_sum += $value; + } else { + $chart_json[$name] = $value; + } + $retval .= ''; + $retval .= ''; + $retval .= ''; + $retval .= ''; + $retval .= ''; + $retval .= ''; + } + $retval .= ''; + $retval .= '
' . __('Statements') . ''; + /* l10n: # = Amount of queries */ + $retval .= __('#'); + $retval .= 'ø ' . __('per hour') . '%
' . htmlspecialchars($name) . ''; + $retval .= htmlspecialchars(PMA_Util::formatNumber($value, 5, 0, true)); + $retval .= ''; + $retval .= htmlspecialchars( + PMA_Util::formatNumber($value * $hour_factor, 4, 1, true) + ); + $retval .= ''; + $retval .= htmlspecialchars( + PMA_Util::formatNumber($value * $perc_factor, 0, 2) + ); + $retval .= '
'; + + $retval .= '
'; + $retval .= ''; + + return $retval; +} + +?> diff --git a/server_status_queries.php b/server_status_queries.php index febdbb85b6..8f2e00d9cb 100644 --- a/server_status_queries.php +++ b/server_status_queries.php @@ -9,6 +9,8 @@ require_once 'libraries/common.inc.php'; require_once 'libraries/server_common.inc.php'; require_once 'libraries/ServerStatusData.class.php'; +require_once 'libraries/server_status_queries.lib.php'; + if (PMA_DRIZZLE) { $server_master_status = false; $server_slave_status = false; @@ -42,138 +44,8 @@ $scripts->addFile('server_status_sorter.js'); // Add the html content to the response $response->addHTML('
'); $response->addHTML($ServerStatusData->getMenuHtml()); -$response->addHTML(PMA_getQueryStatisticsHtml($ServerStatusData)); +$response->addHTML(PMA_getHtmlForQueryStatistics($ServerStatusData)); $response->addHTML('
'); exit; -/** - * Returns the html content for the query statistics - * - * @param object $ServerStatusData An instance of the PMA_ServerStatusData class - * - * @return string - */ -function PMA_getQueryStatisticsHtml($ServerStatusData) -{ - $retval = ''; - - $hour_factor = 3600 / $ServerStatusData->status['Uptime']; - $used_queries = $ServerStatusData->used_queries; - $total_queries = array_sum($used_queries); - - $retval .= '

'; - /* l10n: Questions is the name of a MySQL Status variable */ - $retval .= sprintf( - __('Questions since startup: %s'), - PMA_Util::formatNumber($total_queries, 0) - ); - $retval .= ' '; - $retval .= PMA_Util::showMySQLDocu( - 'server-status-variables', - 'server-status-variables', - false, - 'statvar_Questions' - ); - $retval .= '
'; - $retval .= ''; - $retval .= 'ø ' . __('per hour:') . ' '; - $retval .= PMA_Util::formatNumber($total_queries * $hour_factor, 0); - $retval .= '
'; - $retval .= 'ø ' . __('per minute:') . ' '; - $retval .= PMA_Util::formatNumber($total_queries * 60 / $ServerStatusData->status['Uptime'], 0); - $retval .= '
'; - if ($total_queries / $ServerStatusData->status['Uptime'] >= 1) { - $retval .= 'ø ' . __('per second:') . ' '; - $retval .= PMA_Util::formatNumber($total_queries / $ServerStatusData->status['Uptime'], 0); - } - $retval .= '
'; - $retval .= '

'; - - $retval .= PMA_getServerStatusQueriesDetailsHtml($ServerStatusData); - - return $retval; -} - -/** - * Returns the html content for the query details - * - * @param object $ServerStatusData An instance of the PMA_ServerStatusData class - * - * @return string - */ -function PMA_getServerStatusQueriesDetailsHtml($ServerStatusData) -{ - $hour_factor = 3600 / $ServerStatusData->status['Uptime']; - $used_queries = $ServerStatusData->used_queries; - $total_queries = array_sum($used_queries); - // reverse sort by value to show most used statements first - arsort($used_queries); - - $odd_row = true; - $perc_factor = 100 / $total_queries; //(- $ServerStatusData->status['Connections']); - - $retval = ''; - $retval .= ''; - $retval .= ''; - $retval .= ''; - $retval .= ''; - $retval .= ''; - $retval .= ''; - $retval .= ''; - $retval .= ''; - $retval .= ''; - $retval .= ''; - - $chart_json = array(); - $query_sum = array_sum($used_queries); - $other_sum = 0; - foreach ($used_queries as $name => $value) { - $odd_row = !$odd_row; - // For the percentage column, use Questions - Connections, because - // the number of connections is not an item of the Query types - // but is included in Questions. Then the total of the percentages is 100. - $name = str_replace(array('Com_', '_'), array('', ' '), $name); - // Group together values that make out less than 2% into "Other", but only - // if we have more than 6 fractions already - if ($value < $query_sum * 0.02 && count($chart_json)>6) { - $other_sum += $value; - } else { - $chart_json[$name] = $value; - } - $retval .= ''; - $retval .= ''; - $retval .= ''; - $retval .= ''; - $retval .= ''; - $retval .= ''; - } - $retval .= ''; - $retval .= '
' . __('Statements') . ''; - /* l10n: # = Amount of queries */ - $retval .= __('#'); - $retval .= 'ø ' . __('per hour') . '%
' . htmlspecialchars($name) . ''; - $retval .= htmlspecialchars(PMA_Util::formatNumber($value, 5, 0, true)); - $retval .= ''; - $retval .= htmlspecialchars( - PMA_Util::formatNumber($value * $hour_factor, 4, 1, true) - ); - $retval .= ''; - $retval .= htmlspecialchars( - PMA_Util::formatNumber($value * $perc_factor, 0, 2) - ); - $retval .= '
'; - - $retval .= '
'; - $retval .= ''; - - return $retval; -} - ?>