/**
 * Builds the HTML td elements for one database to display in the list
 * of databases from server_databases.php (which can be modified by
 * db_create.php)
 *
 * @param array   $current           current database
 * @param boolean $is_superuser      user status
 * @param string  $url_query         url query
 * @param array   $column_order      column order
 * @param array   $replication_types replication types
 * @param array   $replication_info  replication info
 *
 * @return array $column_order, $out
 */
function PMA_buildHtmlForDb($current, $is_superuser, $url_query, $column_order, $replication_types, $replication_info)
{
    $out = '';
    if ($is_superuser || $GLOBALS['cfg']['AllowUserDropDatabase']) {
        $out .= '<td class="tool">';
        $out .= '<input type="checkbox" name="selected_dbs[]" class="checkall" ' . 'title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" ' . 'value="' . htmlspecialchars($current['SCHEMA_NAME']) . '"';
        if ($GLOBALS['dbi']->isSystemSchema($current['SCHEMA_NAME'], true)) {
            $out .= ' disabled="disabled"';
        }
        $out .= ' /></td>';
    }
    $out .= '<td class="name">' . '<a href="' . PMA_Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database') . $url_query . '&amp;db=' . urlencode($current['SCHEMA_NAME']) . '" title="' . sprintf(__('Jump to database'), htmlspecialchars($current['SCHEMA_NAME'])) . '">' . ' ' . htmlspecialchars($current['SCHEMA_NAME']) . '</a>' . '</td>';
    foreach ($column_order as $stat_name => $stat) {
        if (array_key_exists($stat_name, $current)) {
            $unit = '';
            if (is_numeric($stat['footer'])) {
                $column_order[$stat_name]['footer'] += $current[$stat_name];
            }
            if ($stat['format'] === 'byte') {
                list($value, $unit) = PMA_Util::formatByteDown($current[$stat_name], 3, 1);
            } elseif ($stat['format'] === 'number') {
                $value = PMA_Util::formatNumber($current[$stat_name], 0);
            } else {
                $value = htmlentities($current[$stat_name], 0);
            }
            $out .= '<td class="value">';
            if (isset($stat['description_function'])) {
                $out .= '<dfn title="' . $stat['description_function']($current[$stat_name]) . '">';
            }
            $out .= $value;
            if (isset($stat['description_function'])) {
                $out .= '</dfn>';
            }
            $out .= '</td>';
            if ($stat['format'] === 'byte') {
                $out .= '<td class="unit">' . $unit . '</td>';
            }
        }
    }
    foreach ($replication_types as $type) {
        if ($replication_info[$type]['status']) {
            $out .= '<td class="tool" style="text-align: center;">';
            $key = array_search($current["SCHEMA_NAME"], $replication_info[$type]['Ignore_DB']);
            if (mb_strlen($key) > 0) {
                $out .= PMA_Util::getIcon('s_cancel.png', __('Not replicated'));
            } else {
                $key = array_search($current["SCHEMA_NAME"], $replication_info[$type]['Do_DB']);
                if (mb_strlen($key) > 0 || isset($replication_info[$type]['Do_DB'][0]) && $replication_info[$type]['Do_DB'][0] == "" && count($replication_info[$type]['Do_DB']) == 1) {
                    // if ($key != null) did not work for index "0"
                    $out .= PMA_Util::getIcon('s_success.png', __('Replicated'));
                }
            }
            $out .= '</td>';
        }
    }
    if ($is_superuser && !PMA_DRIZZLE) {
        $out .= '<td class="tool">' . '<a onclick="' . 'PMA_commonActions.setDb(\'' . PMA_jsFormat($current['SCHEMA_NAME']) . '\');' . '" href="server_privileges.php' . $url_query . '&amp;db=' . urlencode($current['SCHEMA_NAME']) . '&amp;checkprivsdb=' . urlencode($current['SCHEMA_NAME']) . '" title="' . sprintf(__('Check privileges for database "%s".'), htmlspecialchars($current['SCHEMA_NAME'])) . '">' . ' ' . PMA_Util::getIcon('s_rights.png', __('Check Privileges')) . '</a></td>';
    }
    return array($column_order, $out);
}
 /**
  * format number test, globals are defined
  * @dataProvider formatNumberDataProvider
  */
 public function testFormatNumber($a, $b, $c, $d)
 {
     $this->assertEquals(
         $d,
         (string) PMA_Util::formatNumber(
             $a, $b, $c, false
         )
     );
 }
/**
 * Format Variable
 *
 * @param string $name               variable name
 * @param number $value              variable value
 * @param array  $variable_doc_links documentation links
 *
 * @return string formatted string
 */
function PMA_formatVariable($name, $value, $variable_doc_links)
{
    if (is_numeric($value)) {
        if (isset($variable_doc_links[$name][3]) && $variable_doc_links[$name][3] == 'byte') {
            return '<abbr title="' . PMA_Util::formatNumber($value, 0) . '">' . implode(' ', PMA_Util::formatByteDown($value, 3, 3)) . '</abbr>';
        } else {
            return PMA_Util::formatNumber($value, 0);
        }
    }
    return htmlspecialchars($value);
}
 /**
  * returns html tables with stats over inno db buffer pool
  *
  * @return string  html table with stats
  */
 public function getPageBufferpool()
 {
     // The following query is only possible because we know
     // that we are on MySQL 5 here (checked above)!
     // side note: I love MySQL 5 for this. :-)
     $sql = '
          SHOW STATUS
         WHERE Variable_name LIKE \'Innodb\\_buffer\\_pool\\_%\'
            OR Variable_name = \'Innodb_page_size\';';
     $status = $GLOBALS['dbi']->fetchResult($sql, 0, 1);
     $output = '<table class="data" id="table_innodb_bufferpool_usage">' . "\n" . '    <caption class="tblHeaders">' . "\n" . '        ' . __('Buffer Pool Usage') . "\n" . '    </caption>' . "\n" . '    <tfoot>' . "\n" . '        <tr>' . "\n" . '            <th colspan="2">' . "\n" . '                ' . __('Total') . "\n" . '                : ' . PMA_Util::formatNumber($status['Innodb_buffer_pool_pages_total'], 0) . '&nbsp;' . __('pages') . ' / ' . join('&nbsp;', PMA_Util::formatByteDown($status['Innodb_buffer_pool_pages_total'] * $status['Innodb_page_size'])) . "\n" . '            </th>' . "\n" . '        </tr>' . "\n" . '    </tfoot>' . "\n" . '    <tbody>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Free pages') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_pages_free'], 0) . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="even">' . "\n" . '            <th>' . __('Dirty pages') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_pages_dirty'], 0) . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Pages containing data') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_pages_data'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="even">' . "\n" . '            <th>' . __('Pages to be flushed') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_pages_flushed'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Busy pages') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_pages_misc'], 0) . "\n" . '</td>' . "\n" . '        </tr>';
     // not present at least since MySQL 5.1.40
     if (isset($status['Innodb_buffer_pool_pages_latched'])) {
         $output .= '        <tr class="even">' . '            <th>' . __('Latched pages') . '</th>' . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_pages_latched'], 0) . '</td>' . '        </tr>';
     }
     $output .= '    </tbody>' . "\n" . '</table>' . "\n\n" . '<table class="data" id="table_innodb_bufferpool_activity">' . "\n" . '    <caption class="tblHeaders">' . "\n" . '        ' . __('Buffer Pool Activity') . "\n" . '    </caption>' . "\n" . '    <tbody>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Read requests') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_read_requests'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="even">' . "\n" . '            <th>' . __('Write requests') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_write_requests'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Read misses') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_reads'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="even">' . "\n" . '            <th>' . __('Write waits') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_wait_free'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Read misses in %') . '</th>' . "\n" . '            <td class="value">' . ($status['Innodb_buffer_pool_read_requests'] == 0 ? '---' : htmlspecialchars(PMA_Util::formatNumber($status['Innodb_buffer_pool_reads'] * 100 / $status['Innodb_buffer_pool_read_requests'], 3, 2)) . ' %') . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="even">' . "\n" . '            <th>' . __('Write waits in %') . '</th>' . "\n" . '            <td class="value">' . ($status['Innodb_buffer_pool_write_requests'] == 0 ? '---' : htmlspecialchars(PMA_Util::formatNumber($status['Innodb_buffer_pool_wait_free'] * 100 / $status['Innodb_buffer_pool_write_requests'], 3, 2)) . ' %') . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '    </tbody>' . "\n" . '</table>' . "\n";
     return $output;
 }
 * DB search optimisation
 *
 * @package PhpMyAdmin
 */
require_once 'libraries/common.inc.php';
require_once 'libraries/Util.class.php';
$db = $_GET['db'];
$table_term = $_GET['table'];
$common_url_query = PMA_generate_common_url($GLOBALS['db']);
$tables_full = PMA_Util::getTableList($db);
$tables_response = array();
foreach ($tables_full as $key => $table) {
    if (strpos($key, $table_term) !== false) {
        $link = '<li class="ajax_table"><a class="tableicon" title="' . htmlspecialchars($link_title) . ': ' . htmlspecialchars($table['Comment']) . ' (' . PMA_Util::formatNumber($table['Rows'], 0) . ' ' . __('Rows') . ')"' . ' id="quick_' . htmlspecialchars($table_db . '.' . $table['Name']) . '"' . ' href="' . $GLOBALS['cfg']['LeftDefaultTabTable'] . '?' . $common_url_query . '&amp;table=' . urlencode($table['Name']) . '&amp;goto=' . $GLOBALS['cfg']['LeftDefaultTabTable'] . '" >';
        $attr = array('id' => 'icon_' . htmlspecialchars($table_db . '.' . $table['Name']));
        if (PMA_Table::isView($table_db, $table['Name'])) {
            $link .= PMA_Util::getImage('s_views.png', htmlspecialchars($link_title), $attr);
        } else {
            $link .= PMA_Util::getImage('b_browse.png', htmlspecialchars($link_title), $attr);
        }
        $link .= '</a>';
        // link for the table name itself
        $href = $GLOBALS['cfg']['DefaultTabTable'] . '?' . $common_url_query . '&amp;table=' . urlencode($table['Name']) . '&amp;pos=0';
        $link .= '<a href="' . $href . '" title="' . htmlspecialchars(PMA_Util::getTitleForTarget($GLOBALS['cfg']['DefaultTabTable']) . ': ' . $table['Comment'] . ' (' . PMA_Util::formatNumber($table['Rows'], 0) . ' ' . __('Rows') . ')') . '" id="' . htmlspecialchars($table_db . '.' . $table['Name']) . '">' . str_replace(' ', '&nbsp;', htmlspecialchars($table['disp_name'])) . '</a>';
        $link .= '</li>' . "\n";
        $table['line'] = $link;
        $tables_response[] = $table;
    }
}
$response = PMA_Response::getInstance();
$response->addJSON('tables', $tables_response);
 }
 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
     echo "\n";
     echo '<tr>';
     echo '<td>' . __('Row size') . '&nbsp;&oslash;</td>';
     echo '<td class="right">';
     echo $avg_size . ' ' . $avg_unit;
     echo '</td>';
     echo '</tr>';
 }
 if (isset($showtable['Auto_increment'])) {
     echo "\n";
     echo '<tr>';
     echo '<td>' . __('Next autoindex') . ' </td>';
     echo '<td class="right">';
     echo PMA_Util::formatNumber($showtable['Auto_increment'], 0);
     echo '</td>';
     echo '</tr>';
 }
 if (isset($showtable['Create_time'])) {
     echo "\n";
     echo '<tr>';
     echo '<td>' . __('Creation') . '</td>';
     echo '<td class="right">';
     echo PMA_Util::localisedDate(strtotime($showtable['Create_time']));
     echo '</td>';
     echo '</tr>';
 }
 if (isset($showtable['Update_time'])) {
     echo "\n";
     echo '<tr>';
/**
 * Returns the html content for the query details
 *
 * @param PMA_ServerStatusData $ServerStatusData Server status data
 *
 * @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;
    //(- $ServerStatusData->status['Connections']);
    $perc_factor = 100 / $total_queries;
    $retval = '<table id="serverstatusqueriesdetails" ' . 'class="data sortable noclick">';
    $retval .= '<col class="namecol" />';
    $retval .= '<col class="valuecol" span="3" />';
    $retval .= '<thead>';
    $retval .= '<tr><th>' . __('Statements') . '</th>';
    $retval .= '<th>';
    /* l10n: # = Amount of queries */
    $retval .= __('#');
    $retval .= '</th>';
    $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
    $retval .= '<th>%</div></th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $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 .= '<tr class="';
        $retval .= $odd_row ? 'odd' : 'even';
        $retval .= '">';
        $retval .= '<th class="name">' . htmlspecialchars($name) . '</th>';
        $retval .= '<td class="value">';
        $retval .= htmlspecialchars(PMA_Util::formatNumber($value, 5, 0, true));
        $retval .= '</td>';
        $retval .= '<td class="value">';
        $retval .= htmlspecialchars(PMA_Util::formatNumber($value * $hour_factor, 4, 1, true));
        $retval .= '</td>';
        $retval .= '<td class="value">';
        $retval .= htmlspecialchars(PMA_Util::formatNumber($value * $perc_factor, 0, 2));
        $retval .= '</td>';
        $retval .= '</tr>';
    }
    $retval .= '</tbody>';
    $retval .= '</table>';
    $retval .= '<div id="serverstatusquerieschart"></div>';
    $retval .= '<div id="serverstatusquerieschart_data" style="display:none;">';
    if ($other_sum > 0) {
        $chart_json[__('Other')] = $other_sum;
    }
    $retval .= htmlspecialchars(json_encode($chart_json));
    $retval .= '</div>';
    return $retval;
}
Beispiel #8
0
/**
 * Returns the html for Column Order
 *
 * @param array $column_order   Column order
 * @param array $first_database The first display database
 *
 * @return string
 */
function PMA_getHtmlForColumnOrder($column_order, $first_database)
{
    $html = "";
    foreach ($column_order as $stat_name => $stat) {
        if (array_key_exists($stat_name, $first_database)) {
            if ($stat['format'] === 'byte') {
                list($value, $unit) = PMA_Util::formatByteDown($stat['footer'], 3, 1);
            } elseif ($stat['format'] === 'number') {
                $value = PMA_Util::formatNumber($stat['footer'], 0);
            } else {
                $value = htmlentities($stat['footer'], 0);
            }
            $html .= '    <th class="value">';
            if (isset($stat['description_function'])) {
                $html .= '<dfn title="' . $stat['description_function']($stat['footer']) . '">';
            }
            $html .= $value;
            if (isset($stat['description_function'])) {
                $html .= '</dfn>';
            }
            $html .= '</th>' . "\n";
            if ($stat['format'] === 'byte') {
                $html .= '    <th class="unit">' . $unit . '</th>' . "\n";
            }
        }
    }
    return $html;
}
/**
 * Returns a table with variables information
 *
 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
 *
 * @return string
 */
function getVariablesTableHtml($ServerStatusData)
{
    $retval = '';
    $strShowStatus = getStatusVariablesDescriptions();
    /**
     * define some alerts
     */
    // name => max value before alert
    $alerts = array('Aborted_clients' => 0, 'Aborted_connects' => 0, 'Binlog_cache_disk_use' => 0, 'Created_tmp_disk_tables' => 0, 'Handler_read_rnd' => 0, 'Handler_read_rnd_next' => 0, 'Innodb_buffer_pool_pages_dirty' => 0, 'Innodb_buffer_pool_reads' => 0, 'Innodb_buffer_pool_wait_free' => 0, 'Innodb_log_waits' => 0, 'Innodb_row_lock_time_avg' => 10, 'Innodb_row_lock_time_max' => 50, 'Innodb_row_lock_waits' => 0, 'Slow_queries' => 0, 'Delayed_errors' => 0, 'Select_full_join' => 0, 'Select_range_check' => 0, 'Sort_merge_passes' => 0, 'Opened_tables' => 0, 'Table_locks_waited' => 0, 'Qcache_lowmem_prunes' => 0, 'Qcache_free_blocks' => isset($ServerStatusData->server_status['Qcache_total_blocks']) ? $ServerStatusData->server_status['Qcache_total_blocks'] / 5 : 0, 'Slow_launch_threads' => 0, 'Key_reads' => isset($ServerStatusData->status['Key_read_requests']) ? 0.01 * $ServerStatusData->status['Key_read_requests'] : 0, 'Key_writes' => isset($ServerStatusData->status['Key_write_requests']) ? 0.9 * $ServerStatusData->status['Key_write_requests'] : 0, 'Key_buffer_fraction' => 0.5, 'Threads_cached' => isset($ServerStatusData->variables['thread_cache_size']) ? 0.95 * $ServerStatusData->variables['thread_cache_size'] : 0);
    $retval .= '<table class="data sortable noclick" id="serverstatusvariables">';
    $retval .= '<col class="namecol" />';
    $retval .= '<col class="valuecol" />';
    $retval .= '<col class="descrcol" />';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th>' . __('Variable') . '</th>';
    $retval .= '<th>' . __('Value') . '</th>';
    $retval .= '<th>' . __('Description') . '</th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $odd_row = false;
    foreach ($ServerStatusData->status as $name => $value) {
        $odd_row = !$odd_row;
        $retval .= '<tr class="' . ($odd_row ? 'odd' : 'even') . (isset($ServerStatusData->allocationMap[$name]) ? ' s_' . $ServerStatusData->allocationMap[$name] : '') . '">';
        $retval .= '<th class="name">';
        $retval .= htmlspecialchars(str_replace('_', ' ', $name));
        /* Fields containing % are calculated, they can not be described in MySQL documentation */
        if (strpos($name, '%') === false) {
            $retval .= PMA_Util::showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_' . $name);
        }
        $retval .= '</th>';
        $retval .= '<td class="value"><span class="formatted">';
        if (isset($alerts[$name])) {
            if ($value > $alerts[$name]) {
                $retval .= '<span class="attention">';
            } else {
                $retval .= '<span class="allfine">';
            }
        }
        if ('%' === substr($name, -1, 1)) {
            $retval .= htmlspecialchars(PMA_Util::formatNumber($value, 0, 2)) . ' %';
        } elseif (strpos($name, 'Uptime') !== false) {
            $retval .= htmlspecialchars(PMA_Util::timespanFormat($value));
        } elseif (is_numeric($value) && $value == (int) $value && $value > 1000) {
            $retval .= '<abbr title="' . htmlspecialchars(PMA_Util::formatNumber($value, 0)) . '">' . htmlspecialchars(PMA_Util::formatNumber($value, 3, 1));
        } elseif (is_numeric($value) && $value == (int) $value) {
            $retval .= htmlspecialchars(PMA_Util::formatNumber($value, 3, 0));
        } elseif (is_numeric($value)) {
            $retval .= htmlspecialchars(PMA_Util::formatNumber($value, 3, 1));
        } else {
            $retval .= htmlspecialchars($value);
        }
        if (isset($alerts[$name])) {
            $retval .= '</span>';
        }
        $retval .= '</span>';
        $retval .= '<span style="display:none;" class="original">';
        $retval .= $value;
        $retval .= '</span>';
        $retval .= '</td>';
        $retval .= '<td class="descr">';
        if (isset($strShowStatus[$name])) {
            $retval .= $strShowStatus[$name];
        }
        if (isset($ServerStatusData->links[$name])) {
            foreach ($ServerStatusData->links[$name] as $link_name => $link_url) {
                if ('doc' == $link_name) {
                    $retval .= PMA_Util::showMySQLDocu($link_url, $link_url);
                } else {
                    $retval .= ' <a href="' . $link_url . '">' . $link_name . '</a>';
                }
            }
            unset($link_url, $link_name);
        }
        $retval .= '</td>';
        $retval .= '</tr>';
    }
    $retval .= '</tbody>';
    $retval .= '</table>';
    return $retval;
}
/**
 * Returns HTML for render variables list
 *
 * @param PMA_ServerStatusData $ServerStatusData Server status data
 * @param Array                $alerts           Alert Array
 * @param Array                $strShowStatus    Status Array
 *
 * @return string
 */
function PMA_getHtmlForRenderVariables($ServerStatusData, $alerts, $strShowStatus)
{
    $retval = '<table class="data sortable noclick" id="serverstatusvariables">';
    $retval .= '<col class="namecol" />';
    $retval .= '<col class="valuecol" />';
    $retval .= '<col class="descrcol" />';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th>' . __('Variable') . '</th>';
    $retval .= '<th>' . __('Value') . '</th>';
    $retval .= '<th>' . __('Description') . '</th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $odd_row = false;
    foreach ($ServerStatusData->status as $name => $value) {
        $odd_row = !$odd_row;
        $retval .= '<tr class="' . ($odd_row ? 'odd' : 'even') . (isset($ServerStatusData->allocationMap[$name]) ? ' s_' . $ServerStatusData->allocationMap[$name] : '') . '">';
        $retval .= '<th class="name">';
        $retval .= htmlspecialchars(str_replace('_', ' ', $name));
        // Fields containing % are calculated,
        // they can not be described in MySQL documentation
        if (strpos($name, '%') === false) {
            $retval .= PMA_Util::showMySQLDocu('server-status-variables', false, 'statvar_' . $name);
        }
        $retval .= '</th>';
        $retval .= '<td class="value"><span class="formatted">';
        if (isset($alerts[$name])) {
            if ($value > $alerts[$name]) {
                $retval .= '<span class="attention">';
            } else {
                $retval .= '<span class="allfine">';
            }
        }
        if ('%' === substr($name, -1, 1)) {
            $retval .= htmlspecialchars(PMA_Util::formatNumber($value, 0, 2)) . ' %';
        } elseif (strpos($name, 'Uptime') !== false) {
            $retval .= htmlspecialchars(PMA_Util::timespanFormat($value));
        } elseif (is_numeric($value) && $value > 1000) {
            $retval .= '<abbr title="' . htmlspecialchars(PMA_Util::formatNumber($value, 0)) . '">' . htmlspecialchars(PMA_Util::formatNumber($value, 3, 1)) . '</abbr>';
        } elseif (is_numeric($value)) {
            $retval .= htmlspecialchars(PMA_Util::formatNumber($value, 3, 1));
        } else {
            $retval .= htmlspecialchars($value);
        }
        if (isset($alerts[$name])) {
            $retval .= '</span>';
        }
        $retval .= '</span>';
        $retval .= '<span style="display:none;" class="original">';
        if (isset($alerts[$name])) {
            if ($value > $alerts[$name]) {
                $retval .= '<span class="attention">';
            } else {
                $retval .= '<span class="allfine">';
            }
        }
        $retval .= $value;
        if (isset($alerts[$name])) {
            $retval .= '</span>';
        }
        $retval .= '</span>';
        $retval .= '</td>';
        $retval .= '<td class="descr">';
        if (isset($strShowStatus[$name])) {
            $retval .= $strShowStatus[$name];
        }
        if (isset($ServerStatusData->links[$name])) {
            foreach ($ServerStatusData->links[$name] as $link_name => $link_url) {
                if ('doc' == $link_name) {
                    $retval .= PMA_Util::showMySQLDocu($link_url);
                } else {
                    $retval .= ' <a href="' . $link_url . '">' . $link_name . '</a>';
                }
            }
            unset($link_url, $link_name);
        }
        $retval .= '</td>';
        $retval .= '</tr>';
    }
    $retval .= '</tbody>';
    $retval .= '</table>';
    return $retval;
}
 /**
  * Tests for PMA_getHtmlForRowStatistics() method.
  *
  * @return void
  * @test
  */
 public function testPMAGetHtmlForRowStatistics()
 {
     $showtable = array('Row_format' => "Fixed", 'Rows' => 10, 'Avg_row_length' => 123, 'Data_length' => 345, 'Auto_increment' => 1234, 'Create_time' => "today", 'Update_time' => "time2", 'Check_time' => "yesterday");
     $cell_align_left = "cell_align_left";
     $avg_size = 12;
     $avg_unit = 45;
     $mergetable = false;
     $html = PMA_getHtmlForRowStatistics($showtable, $cell_align_left, $avg_size, $avg_unit, $mergetable);
     $this->assertContains(__('Row Statistics:'), $html);
     //validation 1 : Row_format
     $this->assertContains(__('Format'), $html);
     $this->assertContains($cell_align_left, $html);
     //$showtable['Row_format'] == 'Fixed'
     $this->assertContains(__('static'), $html);
     //validation 2 : Avg_row_length
     $length = PMA_Util::formatNumber($showtable['Avg_row_length'], 0);
     $this->assertContains($length, $html);
     $this->assertContains(__('Row size'), $html);
     $this->assertContains($avg_size . ' ' . $avg_unit, $html);
     //validation 3 : Auto_increment
     $average = PMA_Util::formatNumber($showtable['Auto_increment'], 0);
     $this->assertContains($average, $html);
     $this->assertContains(__('Next autoindex'), $html);
     //validation 4 : Create_time
     $time = PMA_Util::localisedDate(strtotime($showtable['Create_time']));
     $this->assertContains(__('Creation'), $html);
     $this->assertContains($time, $html);
     //validation 5 : Update_time
     $time = PMA_Util::localisedDate(strtotime($showtable['Update_time']));
     $this->assertContains(__('Last update'), $html);
     $this->assertContains($time, $html);
     //validation 6 : Check_time
     $time = PMA_Util::localisedDate(strtotime($showtable['Check_time']));
     $this->assertContains(__('Last check'), $html);
     $this->assertContains($time, $html);
 }
Beispiel #12
0
/**
 * Function to get HTML for summary by state table
 *
 * @param array $profiling_stats profiling stats
 *
 * @return string $table html for the table
 */
function PMA_getTableHtmlForProfilingSummaryByState($profiling_stats)
{
    $table = '';
    foreach ($profiling_stats['states'] as $name => $stats) {
        $table .= ' <tr>' . "\n";
        $table .= '<td>' . $name . '</td>' . "\n";
        $table .= '<td align="right">' . PMA_Util::formatNumber($stats['total_time'], 3, 1) . 's<span style="display:none;" class="rawvalue">' . $stats['total_time'] . '</span></td>' . "\n";
        $table .= '<td align="right">' . PMA_Util::formatNumber(100 * ($stats['total_time'] / $profiling_stats['total_time']), 0, 2) . '%</td>' . "\n";
        $table .= '<td align="right">' . $stats['calls'] . '</td>' . "\n";
        $table .= '<td align="right">' . PMA_Util::formatNumber($stats['total_time'] / $stats['calls'], 3, 1) . 's<span style="display:none;" class="rawvalue">' . number_format($stats['total_time'] / $stats['calls'], 8, '.', '') . '</span></td>' . "\n";
        $table .= ' </tr>' . "\n";
    }
    return $table;
}
/**
 * Prints server traffic information
 *
 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
 *
 * @return string
 */
function getServerTrafficHtml($ServerStatusData)
{
    $hour_factor = 3600 / $ServerStatusData->status['Uptime'];
    $start_time = PMA_DBI_fetch_value('SELECT UNIX_TIMESTAMP() - ' . $ServerStatusData->status['Uptime']);
    $retval = '<h3>';
    $retval .= sprintf(__('Network traffic since startup: %s'), implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent'], 3, 1)));
    $retval .= '</h3>';
    $retval .= '<p>';
    $retval .= sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'), PMA_Util::timespanFormat($ServerStatusData->status['Uptime']), PMA_Util::localisedDate($start_time)) . "\n";
    $retval .= '</p>';
    if ($GLOBALS['server_master_status'] || $GLOBALS['server_slave_status']) {
        $retval .= '<p class="notice">';
        if ($GLOBALS['server_master_status'] && $GLOBALS['server_slave_status']) {
            $retval .= __('This MySQL server works as <b>master</b> and ' . '<b>slave</b> in <b>replication</b> process.');
        } elseif ($GLOBALS['server_master_status']) {
            $retval .= __('This MySQL server works as <b>master</b> ' . 'in <b>replication</b> process.');
        } elseif ($GLOBALS['server_slave_status']) {
            $retval .= __('This MySQL server works as <b>slave</b> ' . 'in <b>replication</b> process.');
        }
        $retval .= ' ';
        $retval .= __('For further information about replication status on the server, ' . 'please visit the <a href="#replication">replication section</a>.');
        $retval .= '</p>';
    }
    /*
     * if the server works as master or slave in replication process,
     * display useful information
     */
    if ($GLOBALS['server_master_status'] || $GLOBALS['server_slave_status']) {
        $retval .= '<hr class="clearfloat" />';
        $retval .= '<h3><a name="replication">';
        $retval .= __('Replication status');
        $retval .= '</a></h3>';
        foreach ($GLOBALS['replication_types'] as $type) {
            if (isset(${"server_{$type}_status"}) && ${"server_{$type}_status"}) {
                PMA_replication_print_status_table($type);
            }
        }
    }
    $retval .= '<table id="serverstatustraffic" class="data noclick">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th colspan="2">';
    $retval .= __('Traffic') . '&nbsp;';
    $retval .= PMA_Util::showHint(__('On a busy server, the byte counters may overrun, so those statistics ' . 'as reported by the MySQL server may be incorrect.'));
    $retval .= '</th>';
    $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Received') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'] * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Sent') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_sent'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value"><?php echo';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_sent'] * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Total') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown(($ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent']) * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '</tbody>';
    $retval .= '</table>';
    $retval .= '<table id="serverstatusconnections" class="data noclick">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th colspan="2">' . __('Connections') . '</th>';
    $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
    $retval .= '<th>%</th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('max. concurrent connections') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Max_used_connections'], 0);
    $retval .= '</td>';
    $retval .= '<td class="value">--- </td>';
    $retval .= '<td class="value">--- </td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Failed attempts') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'], 4, 1, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'] * $hour_factor, 4, 2, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    if ($ServerStatusData->status['Connections'] > 0) {
        $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'] * 100 / $ServerStatusData->status['Connections'], 0, 2, true);
        $retval .= '%';
    } else {
        $retval .= '--- ';
    }
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Aborted') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'], 4, 1, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'] * $hour_factor, 4, 2, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    if ($ServerStatusData->status['Connections'] > 0) {
        $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'] * 100 / $ServerStatusData->status['Connections'], 0, 2, true);
        $retval .= '%';
    } else {
        $retval .= '--- ';
    }
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Total') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Connections'], 4, 0);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Connections'] * $hour_factor, 4, 2);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber(100, 0, 2);
    $retval .= '%</td>';
    $retval .= '</tr>';
    $retval .= '</tbody>';
    $retval .= '</table>';
    $url_params = array();
    $show_full_sql = !empty($_REQUEST['full']);
    if ($show_full_sql) {
        $url_params['full'] = 1;
        $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
    } else {
        $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
    }
    // This array contains display name and real column name of each
    // sortable column in the table
    $sortable_columns = array(array('column_name' => __('ID'), 'order_by_field' => 'Id'), array('column_name' => __('User'), 'order_by_field' => 'User'), array('column_name' => __('Host'), 'order_by_field' => 'Host'), array('column_name' => __('Database'), 'order_by_field' => 'db'), array('column_name' => __('Command'), 'order_by_field' => 'Command'), array('column_name' => __('Time'), 'order_by_field' => 'Time'), array('column_name' => __('Status'), 'order_by_field' => 'State'), array('column_name' => __('SQL query'), 'order_by_field' => 'Info'));
    $sortable_columns_count = count($sortable_columns);
    if (PMA_DRIZZLE) {
        $sql_query = "SELECT\n                p.id       AS Id,\n                p.username AS User,\n                p.host     AS Host,\n                p.db       AS db,\n                p.command  AS Command,\n                p.time     AS Time,\n                p.state    AS State,\n                " . ($show_full_sql ? 's.query' : 'left(p.info, ' . (int) $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')') . " AS Info\n            FROM data_dictionary.PROCESSLIST p\n                " . ($show_full_sql ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id' : '');
        if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
            $sql_query .= ' ORDER BY p.' . $_REQUEST['order_by_field'] . ' ' . $_REQUEST['sort_order'];
        }
    } else {
        $sql_query = $show_full_sql ? 'SHOW FULL PROCESSLIST' : 'SHOW PROCESSLIST';
        if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
            $sql_query = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` ORDER BY `' . $_REQUEST['order_by_field'] . '` ' . $_REQUEST['sort_order'];
        }
    }
    $result = PMA_DBI_query($sql_query);
    /**
     * Displays the page
     */
    $retval .= '<table id="tableprocesslist" class="data clearfloat noclick sortable">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th>' . __('Processes') . '</th>';
    foreach ($sortable_columns as $column) {
        $is_sorted = !empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order']) && $_REQUEST['order_by_field'] == $column['order_by_field'];
        $column['sort_order'] = 'ASC';
        if ($is_sorted && $_REQUEST['sort_order'] === 'ASC') {
            $column['sort_order'] = 'DESC';
        }
        if ($is_sorted) {
            if ($_REQUEST['sort_order'] == 'ASC') {
                $asc_display_style = 'inline';
                $desc_display_style = 'none';
            } elseif ($_REQUEST['sort_order'] == 'DESC') {
                $desc_display_style = 'inline';
                $asc_display_style = 'none';
            }
        }
        $retval .= '<th>';
        $retval .= '<a href="server_status.php' . PMA_generate_common_url($column) . '" ';
        if ($is_sorted) {
            $retval .= 'onmouseout="$(\'.soimg\').toggle()" ' . 'onmouseover="$(\'.soimg\').toggle()"';
        }
        $retval .= '>';
        $retval .= $column['column_name'];
        if ($is_sorted) {
            $retval .= '<img class="icon ic_s_desc soimg" alt="' . __('Descending') . '" title="" src="themes/dot.gif" ' . 'style="display: ' . $desc_display_style . '" />';
            $retval .= '<img class="icon ic_s_asc soimg hide" alt="' . __('Ascending') . '" title="" src="themes/dot.gif" ' . 'style="display: ' . $asc_display_style . '" />';
        }
        $retval .= '</a>';
        if (!PMA_DRIZZLE && 0 === --$sortable_columns_count) {
            $retval .= '<a href="' . $full_text_link . '">';
            if ($show_full_sql) {
                $retval .= PMA_Util::getImage('s_partialtext.png', __('Truncate Shown Queries'));
            } else {
                $retval .= PMA_Util::getImage('s_fulltext.png', __('Show Full Queries'));
            }
            $retval .= '</a>';
        }
        $retval .= '</th>';
    }
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $odd_row = true;
    while ($process = PMA_DBI_fetch_assoc($result)) {
        // Array keys need to modify due to the way it has used
        // to display column values
        if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
            foreach (array_keys($process) as $key) {
                $new_key = ucfirst(strtolower($key));
                $process[$new_key] = $process[$key];
                unset($process[$key]);
            }
        }
        $url_params['kill'] = $process['Id'];
        $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
        $retval .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
        $retval .= '<td><a href="' . $kill_process . '">' . __('Kill') . '</a></td>';
        $retval .= '<td class="value">' . $process['Id'] . '</td>';
        $retval .= '<td>' . htmlspecialchars($process['User']) . '</td>';
        $retval .= '<td>' . htmlspecialchars($process['Host']) . '</td>';
        $retval .= '<td>' . (!isset($process['db']) || !strlen($process['db']) ? '<i>' . __('None') . '</i>' : htmlspecialchars($process['db'])) . '</td>';
        $retval .= '<td>' . htmlspecialchars($process['Command']) . '</td>';
        $retval .= '<td class="value">' . $process['Time'] . '</td>';
        $retval .= '<td>' . (empty($process['State']) ? '---' : $process['State']) . '</td>';
        $retval .= '<td>';
        if (empty($process['Info'])) {
            $retval .= '---';
        } else {
            if (!$show_full_sql && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
                $retval .= htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
            } else {
                $retval .= PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
            }
        }
        $retval .= '</td>';
        $retval .= '</tr>';
        $odd_row = !$odd_row;
    }
    $retval .= '</tbody>';
    $retval .= '</table>';
    return $retval;
}
Beispiel #14
0
/**
 * Get HTML snippet for display Row statistics table
 *
 * @param array   $showtable     show table array
 * @param string  $tbl_collation table collation
 * @param boolean $is_innodb     whether table is innob or not
 * @param boolean $mergetable    Checks if current table is a merge table
 * @param integer $avg_size      average size
 * @param string  $avg_unit      average unit
 *
 * @return string $html_output
 */
function getHtmlForRowStatsTable($showtable, $tbl_collation, $is_innodb, $mergetable, $avg_size, $avg_unit)
{
    $odd_row = false;
    $html_output = '<table id="tablerowstats" class="data">';
    $html_output .= '<caption class="tblHeaders">' . __('Row statistics') . '</caption>';
    $html_output .= '<tbody>';
    if (isset($showtable['Row_format'])) {
        if ($showtable['Row_format'] == 'Fixed') {
            $value = __('static');
        } elseif ($showtable['Row_format'] == 'Dynamic') {
            $value = __('dynamic');
        } else {
            $value = $showtable['Row_format'];
        }
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Format'), $value);
        $odd_row = !$odd_row;
    }
    if (!empty($showtable['Create_options'])) {
        if ($showtable['Create_options'] == 'partitioned') {
            $value = __('partitioned');
        } else {
            $value = $showtable['Create_options'];
        }
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Options'), $value);
        $odd_row = !$odd_row;
    }
    if (!empty($tbl_collation)) {
        $value = '<dfn title="' . PMA_getCollationDescr($tbl_collation) . '">' . $tbl_collation . '</dfn>';
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Collation'), $value);
        $odd_row = !$odd_row;
    }
    if (!$is_innodb && isset($showtable['Rows'])) {
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Rows'), PMA_Util::formatNumber($showtable['Rows'], 0));
        $odd_row = !$odd_row;
    }
    if (!$is_innodb && isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
        list($avg_row_length_value, $avg_row_length_unit) = PMA_Util::formatByteDown($showtable['Avg_row_length'], 6, 1);
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Row length'), $avg_row_length_value . ' ' . $avg_row_length_unit);
        unset($avg_row_length_value, $avg_row_length_unit);
        $odd_row = !$odd_row;
    }
    if (!$is_innodb && isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Row size'), $avg_size . ' ' . $avg_unit);
        $odd_row = !$odd_row;
    }
    if (isset($showtable['Auto_increment'])) {
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Next autoindex'), PMA_Util::formatNumber($showtable['Auto_increment'], 0));
        $odd_row = !$odd_row;
    }
    if (isset($showtable['Create_time'])) {
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Creation'), PMA_Util::localisedDate(strtotime($showtable['Create_time'])));
        $odd_row = !$odd_row;
    }
    if (isset($showtable['Update_time'])) {
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Last update'), PMA_Util::localisedDate(strtotime($showtable['Update_time'])));
        $odd_row = !$odd_row;
    }
    if (isset($showtable['Check_time'])) {
        $html_output .= PMA_getHtmlForRowStatsTableRow($odd_row, __('Last check'), PMA_Util::localisedDate(strtotime($showtable['Check_time'])));
    }
    $html_output .= '</tbody>' . '</table>';
    return $html_output;
}
Beispiel #15
0
        echo '</tr>' . "\n";
    } // end foreach ($databases as $key => $current)
    unset($current, $odd_row);

    echo '</tbody><tfoot><tr>' . "\n";
    if ($is_superuser || $cfg['AllowUserDropDatabase']) {
        echo '    <th></th>' . "\n";
    }
    echo '    <th>' . __('Total') . ': <span id="databases_count">' . $databases_count . '</span></th>' . "\n";
    foreach ($column_order as $stat_name => $stat) {
        if (array_key_exists($stat_name, $first_database)) {
            if ($stat['format'] === 'byte') {
                list($value, $unit) = PMA_Util::formatByteDown($stat['footer'], 3, 1);
            } elseif ($stat['format'] === 'number') {
                $value = PMA_Util::formatNumber($stat['footer'], 0);
            } else {
                $value = htmlentities($stat['footer'], 0);
            }
            echo '    <th class="value">';
            if (isset($stat['description_function'])) {
                echo '<dfn title="' . $stat['description_function']($stat['footer']) . '">';
            }
            echo $value;
            if (isset($stat['description_function'])) {
                echo '</dfn>';
            }
            echo '</th>' . "\n";
            if ($stat['format'] === 'byte') {
                echo '    <th class="unit">' . $unit . '</th>' . "\n";
            }
 /**
  * Set the content need to be show in message
  *
  * @param string  $sorted_column_message the message for sorted column
  * @param string  $limit_clause          the limit clause of analyzed query
  * @param integer $total                 the total number of rows returned by
  *                                       the SQL query without any
  *                                       programmatically appended LIMIT clause
  * @param integer $pos_next              the offset for next page
  * @param string  $pre_count             the string renders before row count
  * @param string  $after_count           the string renders after row count
  *
  * @return PMA_Message $message an object of PMA_Message
  *
  * @access  private
  *
  * @see     getTable()
  */
 private function _setMessageInformation($sorted_column_message, $limit_clause, $total, $pos_next, $pre_count, $after_count)
 {
     $unlim_num_rows = $this->__get('unlim_num_rows');
     // To use in isset()
     if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
         $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query');
     } else {
         $selectstring = '';
     }
     if (!empty($limit_clause)) {
         $limit_data = PMA_Util::analyzeLimitClause($limit_clause);
         $first_shown_rec = $limit_data['start'];
         if ($limit_data['length'] < $total) {
             $last_shown_rec = $limit_data['start'] + $limit_data['length'] - 1;
         } else {
             $last_shown_rec = $limit_data['start'] + $total - 1;
         }
     } elseif ($_SESSION['tmp_user_values']['max_rows'] == self::ALL_ROWS || $pos_next > $total) {
         $first_shown_rec = $_SESSION['tmp_user_values']['pos'];
         $last_shown_rec = $total - 1;
     } else {
         $first_shown_rec = $_SESSION['tmp_user_values']['pos'];
         $last_shown_rec = $pos_next - 1;
     }
     if (PMA_Table::isView($this->__get('db'), $this->__get('table')) && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
         $message = PMA_Message::notice(__('This view has at least this number of rows. ' . 'Please refer to %sdocumentation%s.'));
         $message->addParam('[doc@cfg_MaxExactCount]');
         $message->addParam('[/doc]');
         $message_view_warning = PMA_Util::showHint($message);
     } else {
         $message_view_warning = false;
     }
     $message = PMA_Message::success(__('Showing rows'));
     $message->addMessage($first_shown_rec);
     if ($message_view_warning) {
         $message->addMessage('...', ' - ');
         $message->addMessage($message_view_warning);
         $message->addMessage('(');
     } else {
         $message->addMessage($last_shown_rec, ' - ');
         $message->addMessage(' (');
         $message->addMessage($pre_count . PMA_Util::formatNumber($total, 0));
         $message->addString(__('total'));
         if (!empty($after_count)) {
             $message->addMessage($after_count);
         }
         $message->addMessage($selectstring, '');
         $message->addMessage(', ', '');
     }
     $messagge_qt = PMA_Message::notice(__('Query took %01.4f sec') . ')');
     $messagge_qt->addParam($this->__get('querytime'));
     $message->addMessage($messagge_qt, '');
     if (!is_null($sorted_column_message)) {
         $message->addMessage($sorted_column_message, '');
     }
     return $message;
 }
Beispiel #17
0
/**
 * Prints table with variables information
 *
 * @return void
 */
function printVariablesTable()
{
    global $server_status, $server_variables, $allocationMap, $links;

    /**
     * Messages are built using the message name
     */
    $strShowStatus = array(
        'Aborted_clients' => __('The number of connections that were aborted because the client died without closing the connection properly.'),
        'Aborted_connects' => __('The number of failed attempts to connect to the MySQL server.'),
        'Binlog_cache_disk_use' => __('The number of transactions that used the temporary binary log cache but that exceeded the value of binlog_cache_size and used a temporary file to store statements from the transaction.'),
        'Binlog_cache_use' => __('The number of transactions that used the temporary binary log cache.'),
        'Connections' => __('The number of connection attempts (successful or not) to the MySQL server.'),
        'Created_tmp_disk_tables' => __('The number of temporary tables on disk created automatically by the server while executing statements. If Created_tmp_disk_tables is big, you may want to increase the tmp_table_size  value to cause temporary tables to be memory-based instead of disk-based.'),
        'Created_tmp_files' => __('How many temporary files mysqld has created.'),
        'Created_tmp_tables' => __('The number of in-memory temporary tables created automatically by the server while executing statements.'),
        'Delayed_errors' => __('The number of rows written with INSERT DELAYED for which some error occurred (probably duplicate key).'),
        'Delayed_insert_threads' => __('The number of INSERT DELAYED handler threads in use. Every different table on which one uses INSERT DELAYED gets its own thread.'),
        'Delayed_writes' => __('The number of INSERT DELAYED rows written.'),
        'Flush_commands'  => __('The number of executed FLUSH statements.'),
        'Handler_commit' => __('The number of internal COMMIT statements.'),
        'Handler_delete' => __('The number of times a row was deleted from a table.'),
        'Handler_discover' => __('The MySQL server can ask the NDB Cluster storage engine if it knows about a table with a given name. This is called discovery. Handler_discover indicates the number of time tables have been discovered.'),
        'Handler_read_first' => __('The number of times the first entry was read from an index. If this is high, it suggests that the server is doing a lot of full index scans; for example, SELECT col1 FROM foo, assuming that col1 is indexed.'),
        'Handler_read_key' => __('The number of requests to read a row based on a key. If this is high, it is a good indication that your queries and tables are properly indexed.'),
        'Handler_read_next' => __('The number of requests to read the next row in key order. This is incremented if you are querying an index column with a range constraint or if you are doing an index scan.'),
        'Handler_read_prev' => __('The number of requests to read the previous row in key order. This read method is mainly used to optimize ORDER BY ... DESC.'),
        'Handler_read_rnd' => __('The number of requests to read a row based on a fixed position. This is high if you are doing a lot of queries that require sorting of the result. You probably have a lot of queries that require MySQL to scan whole tables or you have joins that don\'t use keys properly.'),
        'Handler_read_rnd_next' => __('The number of requests to read the next row in the data file. This is high if you are doing a lot of table scans. Generally this suggests that your tables are not properly indexed or that your queries are not written to take advantage of the indexes you have.'),
        'Handler_rollback' => __('The number of internal ROLLBACK statements.'),
        'Handler_update' => __('The number of requests to update a row in a table.'),
        'Handler_write' => __('The number of requests to insert a row in a table.'),
        'Innodb_buffer_pool_pages_data' => __('The number of pages containing data (dirty or clean).'),
        'Innodb_buffer_pool_pages_dirty' => __('The number of pages currently dirty.'),
        'Innodb_buffer_pool_pages_flushed' => __('The number of buffer pool pages that have been requested to be flushed.'),
        'Innodb_buffer_pool_pages_free' => __('The number of free pages.'),
        'Innodb_buffer_pool_pages_latched' => __('The number of latched pages in InnoDB buffer pool. These are pages currently being read or written or that can\'t be flushed or removed for some other reason.'),
        'Innodb_buffer_pool_pages_misc' => __('The number of pages busy because they have been allocated for administrative overhead such as row locks or the adaptive hash index. This value can also be calculated as Innodb_buffer_pool_pages_total - Innodb_buffer_pool_pages_free - Innodb_buffer_pool_pages_data.'),
        'Innodb_buffer_pool_pages_total' => __('Total size of buffer pool, in pages.'),
        'Innodb_buffer_pool_read_ahead_rnd' => __('The number of "random" read-aheads InnoDB initiated. This happens when a query is to scan a large portion of a table but in random order.'),
        'Innodb_buffer_pool_read_ahead_seq' => __('The number of sequential read-aheads InnoDB initiated. This happens when InnoDB does a sequential full table scan.'),
        'Innodb_buffer_pool_read_requests' => __('The number of logical read requests InnoDB has done.'),
        'Innodb_buffer_pool_reads' => __('The number of logical reads that InnoDB could not satisfy from buffer pool and had to do a single-page read.'),
        'Innodb_buffer_pool_wait_free' => __('Normally, writes to the InnoDB buffer pool happen in the background. However, if it\'s necessary to read or create a page and no clean pages are available, it\'s necessary to wait for pages to be flushed first. This counter counts instances of these waits. If the buffer pool size was set properly, this value should be small.'),
        'Innodb_buffer_pool_write_requests' => __('The number writes done to the InnoDB buffer pool.'),
        'Innodb_data_fsyncs' => __('The number of fsync() operations so far.'),
        'Innodb_data_pending_fsyncs' => __('The current number of pending fsync() operations.'),
        'Innodb_data_pending_reads' => __('The current number of pending reads.'),
        'Innodb_data_pending_writes' => __('The current number of pending writes.'),
        'Innodb_data_read' => __('The amount of data read so far, in bytes.'),
        'Innodb_data_reads' => __('The total number of data reads.'),
        'Innodb_data_writes' => __('The total number of data writes.'),
        'Innodb_data_written' => __('The amount of data written so far, in bytes.'),
        'Innodb_dblwr_pages_written' => __('The number of pages that have been written for doublewrite operations.'),
        'Innodb_dblwr_writes' => __('The number of doublewrite operations that have been performed.'),
        'Innodb_log_waits' => __('The number of waits we had because log buffer was too small and we had to wait for it to be flushed before continuing.'),
        'Innodb_log_write_requests' => __('The number of log write requests.'),
        'Innodb_log_writes' => __('The number of physical writes to the log file.'),
        'Innodb_os_log_fsyncs' => __('The number of fsync() writes done to the log file.'),
        'Innodb_os_log_pending_fsyncs' => __('The number of pending log file fsyncs.'),
        'Innodb_os_log_pending_writes' => __('Pending log file writes.'),
        'Innodb_os_log_written' => __('The number of bytes written to the log file.'),
        'Innodb_pages_created' => __('The number of pages created.'),
        'Innodb_page_size' => __('The compiled-in InnoDB page size (default 16KB). Many values are counted in pages; the page size allows them to be easily converted to bytes.'),
        'Innodb_pages_read' => __('The number of pages read.'),
        'Innodb_pages_written' => __('The number of pages written.'),
        'Innodb_row_lock_current_waits' => __('The number of row locks currently being waited for.'),
        'Innodb_row_lock_time_avg' => __('The average time to acquire a row lock, in milliseconds.'),
        'Innodb_row_lock_time' => __('The total time spent in acquiring row locks, in milliseconds.'),
        'Innodb_row_lock_time_max' => __('The maximum time to acquire a row lock, in milliseconds.'),
        'Innodb_row_lock_waits' => __('The number of times a row lock had to be waited for.'),
        'Innodb_rows_deleted' => __('The number of rows deleted from InnoDB tables.'),
        'Innodb_rows_inserted' => __('The number of rows inserted in InnoDB tables.'),
        'Innodb_rows_read' => __('The number of rows read from InnoDB tables.'),
        'Innodb_rows_updated' => __('The number of rows updated in InnoDB tables.'),
        'Key_blocks_not_flushed' => __('The number of key blocks in the key cache that have changed but haven\'t yet been flushed to disk. It used to be known as Not_flushed_key_blocks.'),
        'Key_blocks_unused' => __('The number of unused blocks in the key cache. You can use this value to determine how much of the key cache is in use.'),
        'Key_blocks_used' => __('The number of used blocks in the key cache. This value is a high-water mark that indicates the maximum number of blocks that have ever been in use at one time.'),
        'Key_buffer_fraction_%' => __('Percentage of used key cache (calculated value)'),
        'Key_read_requests' => __('The number of requests to read a key block from the cache.'),
        'Key_reads' => __('The number of physical reads of a key block from disk. If Key_reads is big, then your key_buffer_size value is probably too small. The cache miss rate can be calculated as Key_reads/Key_read_requests.'),
        'Key_read_ratio_%' => __('Key cache miss calculated as rate of physical reads compared to read requests (calculated value)'),
        'Key_write_requests' => __('The number of requests to write a key block to the cache.'),
        'Key_writes' => __('The number of physical writes of a key block to disk.'),
        'Key_write_ratio_%' => __('Percentage of physical writes compared to write requests (calculated value)'),
        'Last_query_cost' => __('The total cost of the last compiled query as computed by the query optimizer. Useful for comparing the cost of different query plans for the same query. The default value of 0 means that no query has been compiled yet.'),
        'Max_used_connections' => __('The maximum number of connections that have been in use simultaneously since the server started.'),
        'Not_flushed_delayed_rows' => __('The number of rows waiting to be written in INSERT DELAYED queues.'),
        'Opened_tables' => __('The number of tables that have been opened. If opened tables is big, your table cache value is probably too small.'),
        'Open_files' => __('The number of files that are open.'),
        'Open_streams' => __('The number of streams that are open (used mainly for logging).'),
        'Open_tables' => __('The number of tables that are open.'),
        'Qcache_free_blocks' => __('The number of free memory blocks in query cache. High numbers can indicate fragmentation issues, which may be solved by issuing a FLUSH QUERY CACHE statement.'),
        'Qcache_free_memory' => __('The amount of free memory for query cache.'),
        'Qcache_hits' => __('The number of cache hits.'),
        'Qcache_inserts' => __('The number of queries added to the cache.'),
        'Qcache_lowmem_prunes' => __('The number of queries that have been removed from the cache to free up memory for caching new queries. This information can help you tune the query cache size. The query cache uses a least recently used (LRU) strategy to decide which queries to remove from the cache.'),
        'Qcache_not_cached' => __('The number of non-cached queries (not cachable, or not cached due to the query_cache_type setting).'),
        'Qcache_queries_in_cache' => __('The number of queries registered in the cache.'),
        'Qcache_total_blocks' => __('The total number of blocks in the query cache.'),
        'Rpl_status' => __('The status of failsafe replication (not yet implemented).'),
        'Select_full_join' => __('The number of joins that do not use indexes. If this value is not 0, you should carefully check the indexes of your tables.'),
        'Select_full_range_join' => __('The number of joins that used a range search on a reference table.'),
        'Select_range_check' => __('The number of joins without keys that check for key usage after each row. (If this is not 0, you should carefully check the indexes of your tables.)'),
        'Select_range' => __('The number of joins that used ranges on the first table. (It\'s normally not critical even if this is big.)'),
        'Select_scan' => __('The number of joins that did a full scan of the first table.'),
        'Slave_open_temp_tables' => __('The number of temporary tables currently open by the slave SQL thread.'),
        'Slave_retried_transactions' => __('Total (since startup) number of times the replication slave SQL thread has retried transactions.'),
        'Slave_running' => __('This is ON if this server is a slave that is connected to a master.'),
        'Slow_launch_threads' => __('The number of threads that have taken more than slow_launch_time seconds to create.'),
        'Slow_queries' => __('The number of queries that have taken more than long_query_time seconds.'),
        'Sort_merge_passes' => __('The number of merge passes the sort algorithm has had to do. If this value is large, you should consider increasing the value of the sort_buffer_size system variable.'),
        'Sort_range' => __('The number of sorts that were done with ranges.'),
        'Sort_rows' => __('The number of sorted rows.'),
        'Sort_scan' => __('The number of sorts that were done by scanning the table.'),
        'Table_locks_immediate' => __('The number of times that a table lock was acquired immediately.'),
        'Table_locks_waited' => __('The number of times that a table lock could not be acquired immediately and a wait was needed. If this is high, and you have performance problems, you should first optimize your queries, and then either split your table or tables or use replication.'),
        'Threads_cached' => __('The number of threads in the thread cache. The cache hit rate can be calculated as Threads_created/Connections. If this value is red you should raise your thread_cache_size.'),
        'Threads_connected' => __('The number of currently open connections.'),
        'Threads_created' => __('The number of threads created to handle connections. If Threads_created is big, you may want to increase the thread_cache_size value. (Normally this doesn\'t give a notable performance improvement if you have a good thread implementation.)'),
        'Threads_cache_hitrate_%' => __('Thread cache hit rate (calculated value)'),
        'Threads_running' => __('The number of threads that are not sleeping.')
    );

    /**
     * define some alerts
     */
    // name => max value before alert
    $alerts = array(
        // lower is better
        // variable => max value
        'Aborted_clients' => 0,
        'Aborted_connects' => 0,

        'Binlog_cache_disk_use' => 0,

        'Created_tmp_disk_tables' => 0,

        'Handler_read_rnd' => 0,
        'Handler_read_rnd_next' => 0,

        'Innodb_buffer_pool_pages_dirty' => 0,
        'Innodb_buffer_pool_reads' => 0,
        'Innodb_buffer_pool_wait_free' => 0,
        'Innodb_log_waits' => 0,
        'Innodb_row_lock_time_avg' => 10, // ms
        'Innodb_row_lock_time_max' => 50, // ms
        'Innodb_row_lock_waits' => 0,

        'Slow_queries' => 0,
        'Delayed_errors' => 0,
        'Select_full_join' => 0,
        'Select_range_check' => 0,
        'Sort_merge_passes' => 0,
        'Opened_tables' => 0,
        'Table_locks_waited' => 0,
        'Qcache_lowmem_prunes' => 0,

        'Qcache_free_blocks' => isset($server_status['Qcache_total_blocks'])
            ? $server_status['Qcache_total_blocks'] / 5 : 0,
        'Slow_launch_threads' => 0,

        // depends on Key_read_requests
        // normaly lower then 1:0.01
        'Key_reads' => isset($server_status['Key_read_requests'])
            ? (0.01 * $server_status['Key_read_requests']) : 0,
        // depends on Key_write_requests
        // normaly nearly 1:1
        'Key_writes' => isset($server_status['Key_write_requests'])
            ? (0.9 * $server_status['Key_write_requests']) : 0,

        'Key_buffer_fraction' => 0.5,

        // alert if more than 95% of thread cache is in use
        'Threads_cached' => isset($server_variables['thread_cache_size'])
            ? 0.95 * $server_variables['thread_cache_size'] : 0

        // higher is better
        // variable => min value
        //'Handler read key' => '> ',
    );

?>
<table class="data sortable noclick" id="serverstatusvariables">
    <col class="namecol" />
    <col class="valuecol" />
    <col class="descrcol" />
    <thead>
        <tr>
            <th><?php echo __('Variable'); ?></th>
            <th><?php echo __('Value'); ?></th>
            <th><?php echo __('Description'); ?></th>
        </tr>
    </thead>
    <tbody>
    <?php

    $odd_row = false;
    foreach ($server_status as $name => $value) {
        $odd_row = !$odd_row;
        echo '<tr class="' . ($odd_row ? 'odd' : 'even')
            . (isset($allocationMap[$name])?' s_' . $allocationMap[$name] : '')
            . '">';

        echo '<th class="name">';
        echo htmlspecialchars(str_replace('_', ' ', $name));
        /* Fields containing % are calculated, they can not be described in MySQL documentation */
        if (strpos($name, '%') === false) {
             echo PMA_Util::showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_' . $name);
        }
        echo '</th>';

        echo '<td class="value"><span class="formatted">';
        if (isset($alerts[$name])) {
            if ($value > $alerts[$name]) {
                echo '<span class="attention">';
            } else {
                echo '<span class="allfine">';
            }
        }
        if ('%' === substr($name, -1, 1)) {
            echo htmlspecialchars(PMA_Util::formatNumber($value, 0, 2)) . ' %';
        } elseif (strpos($name, 'Uptime') !== false) {
            echo htmlspecialchars(
                PMA_Util::timespanFormat($value)
            );
        } elseif (is_numeric($value) && $value == (int) $value && $value > 1000) {
            echo htmlspecialchars(PMA_Util::formatNumber($value, 3, 1));
        } elseif (is_numeric($value) && $value == (int) $value) {
            echo htmlspecialchars(PMA_Util::formatNumber($value, 3, 0));
        } elseif (is_numeric($value)) {
            echo htmlspecialchars(PMA_Util::formatNumber($value, 3, 1));
        } else {
            echo htmlspecialchars($value);
        }
        if (isset($alerts[$name])) {
            echo '</span>';
        }
        echo '</span>';
        echo '<span style="display:none;" class="original">';
        echo $value;
        echo '</span>';
        echo '</td>';
        echo '<td class="descr">';

        if (isset($strShowStatus[$name ])) {
            echo $strShowStatus[$name];
        }

        if (isset($links[$name])) {
            foreach ($links[$name] as $link_name => $link_url) {
                if ('doc' == $link_name) {
                    echo PMA_Util::showMySQLDocu($link_url, $link_url);
                } else {
                    echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
                    "\n";
                }
            }
            unset($link_url, $link_name);
        }
        echo '</td>';
        echo '</tr>';
    }
    echo '</tbody>';
    echo '</table>';
}
Beispiel #18
0
/**
 * Format Variable
 *
 * @param string  $name  variable name
 * @param numeric $value variable value
 *
 * @return formatted string
 */
function formatVariable($name, $value)
{
    global $VARIABLE_DOC_LINKS;
    if (is_numeric($value)) {
        if (isset($VARIABLE_DOC_LINKS[$name][3]) && $VARIABLE_DOC_LINKS[$name][3] == 'byte') {
            return '<abbr title="' . PMA_Util::formatNumber($value, 0) . '">' . implode(' ', PMA_Util::formatByteDown($value, 3, 3)) . '</abbr>';
        } else {
            return PMA_Util::formatNumber($value, 0);
        }
    }
    return htmlspecialchars($value);
}
Beispiel #19
0
        }
        ?>
    </td>
</tr>
        <?php 
    }
    ?>
<tr>
    <th class="center">
        <?php 
    echo sprintf(_ngettext('%s table', '%s tables', $num_tables), PMA_Util::formatNumber($num_tables, 0));
    ?>
    </th>
    <th class="right nowrap">
        <?php 
    echo PMA_Util::formatNumber($sum_entries, 0);
    ?>
    </th>
    <th class="center">
        --
    </th>
    <?php 
    if ($cfg['ShowStats']) {
        list($sum_formated, $unit) = PMA_Util::formatByteDown($sum_size, 3, 1);
        ?>
    <th class="right nowrap">
        <?php 
        echo $sum_formated . ' ' . $unit;
        ?>
    </th>
        <?php 
Beispiel #20
0
/**
 * Handles request for real row count on database level view page.
 *
 * @return boolean true
 */
function PMA_handleRealRowCountRequest()
{
    $ajax_response = PMA_Response::getInstance();
    // If there is a request to update all table's row count.
    if (isset($_REQUEST['real_row_count_all'])) {
        $real_row_count_all = PMA_getRealRowCountDb($GLOBALS['db'], $GLOBALS['tables']);
        $ajax_response->addJSON('real_row_count_all', json_encode($real_row_count_all));
        return true;
    }
    // Get the real row count for the table.
    $real_row_count = PMA_getRealRowCountTable($GLOBALS['db'], $_REQUEST['table']);
    // Format the number.
    $real_row_count = PMA_Util::formatNumber($real_row_count, 0);
    $ajax_response->addJSON('real_row_count', $real_row_count);
    return true;
}
/**
 * Prints server state connections information
 *
 * @param PMA_ServerStatusData $ServerStatusData Server status data
 *
 * @return string
 */
function PMA_getHtmlForServerStateConnections($ServerStatusData)
{
    $hour_factor = 3600 / $ServerStatusData->status['Uptime'];
    $retval = '<table id="serverstatusconnections" class="data noclick">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th colspan="2">' . __('Connections') . '</th>';
    $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
    $retval .= '<th>%</th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Max. concurrent connections') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Max_used_connections'], 0);
    $retval .= '</td>';
    $retval .= '<td class="value">--- </td>';
    $retval .= '<td class="value">--- </td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Failed attempts') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'], 4, 1, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'] * $hour_factor, 4, 2, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    if ($ServerStatusData->status['Connections'] > 0) {
        $abortNum = $ServerStatusData->status['Aborted_connects'];
        $connectNum = $ServerStatusData->status['Connections'];
        $retval .= PMA_Util::formatNumber($abortNum * 100 / $connectNum, 0, 2, true);
        $retval .= '%';
    } else {
        $retval .= '--- ';
    }
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Aborted') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'], 4, 1, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'] * $hour_factor, 4, 2, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    if ($ServerStatusData->status['Connections'] > 0) {
        $abortNum = $ServerStatusData->status['Aborted_clients'];
        $connectNum = $ServerStatusData->status['Connections'];
        $retval .= PMA_Util::formatNumber($abortNum * 100 / $connectNum, 0, 2, true);
        $retval .= '%';
    } else {
        $retval .= '--- ';
    }
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Total') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Connections'], 4, 0);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Connections'] * $hour_factor, 4, 2);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber(100, 0, 2);
    $retval .= '%</td>';
    $retval .= '</tr>';
    $retval .= '</tbody>';
    $retval .= '</table>';
    return $retval;
}
 /**
  * returns as HTML table of the engine's server variables
  *
  * @return string The table that was generated based on the retrieved
  *                information
  */
 function getHtmlVariables()
 {
     $odd_row = false;
     $ret = '';
     foreach ($this->getVariablesStatus() as $details) {
         $ret .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n" . '    <td>' . "\n";
         if (!empty($details['desc'])) {
             $ret .= '        ' . PMA_Util::showHint($details['desc']) . "\n";
         }
         $ret .= '    </td>' . "\n" . '    <th>' . htmlspecialchars($details['title']) . '</th>' . "\n" . '    <td class="value">';
         switch ($details['type']) {
             case PMA_ENGINE_DETAILS_TYPE_SIZE:
                 $parsed_size = $this->resolveTypeSize($details['value']);
                 $ret .= $parsed_size[0] . '&nbsp;' . $parsed_size[1];
                 unset($parsed_size);
                 break;
             case PMA_ENGINE_DETAILS_TYPE_NUMERIC:
                 $ret .= PMA_Util::formatNumber($details['value']) . ' ';
                 break;
             default:
                 $ret .= htmlspecialchars($details['value']) . '   ';
         }
         $ret .= '</td>' . "\n" . '</tr>' . "\n";
         $odd_row = !$odd_row;
     }
     if (!$ret) {
         $ret = '<p>' . "\n" . '    ' . __('There is no detailed status information available for this storage engine.') . "\n" . '</p>' . "\n";
     } else {
         $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
     }
     return $ret;
 }
Beispiel #23
0
 echo 'pma_token = \'' . $_SESSION[' PMA_token '] . '\';';
 echo 'url_query = \'' . (isset($url_query) ? $url_query : PMA_generate_common_url($db)) . '\';';
 echo 'AJAX.registerOnload(\'sql.js\',makeProfilingChart);';
 echo '</script>';
 echo '<fieldset><legend>' . __('Profiling') . '</legend>' . "\n";
 echo '<div style="float: left;">';
 echo '<table>' . "\n";
 echo ' <tr>' . "\n";
 echo '  <th>' . __('Status') . PMA_Util::showMySQLDocu('general-thread-states', 'general-thread-states') . '</th>' . "\n";
 echo '  <th>' . __('Time') . '</th>' . "\n";
 echo ' </tr>' . "\n";
 $chart_json = array();
 foreach ($profiling_results as $one_result) {
     echo ' <tr>' . "\n";
     echo '<td>' . ucwords($one_result['Status']) . '</td>' . "\n";
     echo '<td class="right">' . PMA_Util::formatNumber($one_result['Duration'], 3, 1) . 's</td>' . "\n";
     if (isset($chart_json[ucwords($one_result['Status'])])) {
         $chart_json[ucwords($one_result['Status'])] += $one_result['Duration'];
     } else {
         $chart_json[ucwords($one_result['Status'])] = $one_result['Duration'];
     }
 }
 echo '</table>' . "\n";
 echo '</div>';
 //require_once 'libraries/chart.lib.php';
 echo '<div id="profilingChartData" style="display:none;">';
 echo json_encode($chart_json);
 echo '</div>';
 echo '<div id="profilingchart" style="display:none;">';
 echo '</div>';
 echo '<script type="text/javascript">';
Beispiel #24
0
/**
 * display unordered list of tables
 * calls itself recursively if table in given list
 * is a list itself
 *
 * @param array   $tables         array of tables/tablegroups
 * @param boolean $visible        whether the list is visible or not
 * @param string  $tab_group_full full tab group name
 * @param string  $table_db       db of this table
 *
 * @return void
 *
 * @global  integer the element counter
 * @global  string  html code for '-' image
 * @global  string  html code for '+' image
 * @global  string  html code for self link
 */
function PMA_displayTableList(
    $tables, $visible = false,
    $tab_group_full = '', $table_db = ''
) {
    if (! is_array($tables) || count($tables) === 0) {
        return;
    }

    global $element_counter, $img_minus, $img_plus, $href_left;
    $sep = $GLOBALS['cfg']['LeftFrameTableSeparator'];

    if ($visible) {
        echo '<ul id="subel' . $element_counter . '">';
    } else {
        echo '<ul id="subel' . $element_counter . '" style="display: none">';
    }
    foreach ($tables as $group => $table) {
        // only allow grouping if the group has more than 1 table
        if (isset($table['is' . $sep . 'group'])
            && $table['tab' . $sep . 'count'] > 1
        ) {
            $common_url_query = $GLOBALS['common_url_query']
                . '&amp;tbl_group=' . urlencode($tab_group_full . $group);

            $element_counter++;
            echo '<li>' . "\n";
            if ($visible
                && ((isset($_REQUEST['tbl_group'])
                && (strpos($_REQUEST['tbl_group'], $group) === 0
                || strpos($_REQUEST['tbl_group'], $sep . $group) !== false))
                || strpos($GLOBALS['table'], $group) === 0)
            ) {
                printf(
                    $href_left,
                    $element_counter,
                    $GLOBALS['common_url_query'] . '&amp;tbl_group=' . $tab_group_full
                );
                printf($img_minus, $element_counter);
            } else {
                printf($href_left, $element_counter, $common_url_query);
                printf($img_plus, $element_counter);
            }
            echo '</a>';
            ?>
            <a href="index.php?<?php echo $common_url_query; ?>"
                target="_parent"
                onclick="
                    if (! toggle('<?php echo $element_counter; ?>', true))
                        window.parent.goTo('navigation.php?<?php echo $common_url_query; ?>');
                    window.parent.goTo('<?php echo $GLOBALS['cfg']['DefaultTabDatabase']
                        . '?' . $common_url_query; ?>', 'main');
                    return false;">
                <?php
                if ($GLOBALS['text_dir'] === 'rtl') {
                    echo ' <bdo dir="ltr">(' . $table['tab' . $sep . 'count'] . ')</bdo> ';
                }
                echo htmlspecialchars(substr($group, 0, strlen($group) - strlen($sep)));
                if ($GLOBALS['text_dir'] === 'ltr') {
                    echo ' <bdo dir="ltr">(' . $table['tab' . $sep . 'count'] . ')</bdo> ';
                }
                ?>
            </a>
            <?php

            unset($table['is' . $sep . 'group']);
            unset($table['tab' . $sep . 'group']);
            unset($table['tab' . $sep . 'count']);

            if ($visible
                && ((isset($_REQUEST['tbl_group'])
                && (strpos($_REQUEST['tbl_group'], $group) === 0
                || strpos($_REQUEST['tbl_group'], $sep . $group) !== false))
                || strpos($GLOBALS['table'], $group) === 0)
            ) {
                PMA_displayTableList(
                    $table, true, $tab_group_full . $group, $table_db
                );
            } else {
                PMA_displayTableList($table, false, '', $table_db);
            }
            echo '</li>' . "\n";
        } elseif (is_array($table)) {
            // the table was not grouped because it is the only one with its prefix
            while (isset($table['is' . $sep . 'group'])) {
                // get the array with the actual table information
                foreach ($table as $value) {
                    if (is_array($value)) {
                        $table = $value;
                    }
                }
            }
            $link_title = PMA_Util::getTitleForTarget(
                $GLOBALS['cfg']['LeftDefaultTabTable']
            );
            // quick access icon next to each table name
            echo '<li>' . "\n";
            echo '<a target="frame_content" class="tableicon" title="'
                . htmlspecialchars($link_title)
                . ': ' . htmlspecialchars($table['Comment'])
                .' ('
                . PMA_Util::formatNumber($table['Rows'], 0)
                . ' ' . __('Rows') . ')"'
                .' id="quick_' . htmlspecialchars($table_db . '.' . $table['Name']) . '"'
                .' href="' . $GLOBALS['cfg']['LeftDefaultTabTable'] . '?'
                . $GLOBALS['common_url_query']
                .'&amp;table=' . urlencode($table['Name'])
                .'&amp;goto=' . $GLOBALS['cfg']['LeftDefaultTabTable']
                . '" >';
            $attr = array(
                'id' => 'icon_' . htmlspecialchars($table_db . '.' . $table['Name'])
            );
            if (PMA_Table::isView($table_db, $table['Name'])) {
                echo PMA_Util::getImage(
                    's_views.png',
                    htmlspecialchars($link_title),
                    $attr
                );
            } else {
                echo PMA_Util::getImage(
                    'b_browse.png',
                    htmlspecialchars($link_title),
                    $attr
                );
            }
            echo '</a>';

            // link for the table name itself
            $href = $GLOBALS['cfg']['DefaultTabTable'] . '?'
                .$GLOBALS['common_url_query'] . '&amp;table='
                .urlencode($table['Name']) . '&amp;pos=0';
            echo '<a target="frame_content" href="' . $href . '" title="'
                . htmlspecialchars(
                    PMA_Util::getTitleForTarget(
                        $GLOBALS['cfg']['DefaultTabTable']
                    )
                    . ': ' . $table['Comment']
                    .' ('
                    . PMA_Util::formatNumber(
                        $table['Rows'], 0
                    )
                    . ' ' . __('Rows') . ')'
                )
                .'" id="' . htmlspecialchars($table_db . '.' . $table['Name']) . '">'
                // preserve spaces in table name
                . str_replace(' ', '&nbsp;', htmlspecialchars($table['disp_name']))
                . '</a>';
            echo '</li>' . "\n";
        }
    }
    echo '</ul>';
}
 /**
  * Test for PMA_getHtmlForQueryStatistics
  *
  * @return void
  */
 public function testPMAGetHtmlForQueryStatistics()
 {
     //Call the test function
     $html = PMA_getHtmlForQueryStatistics($this->ServerStatusData);
     $hour_factor = 3600 / $this->ServerStatusData->status['Uptime'];
     $used_queries = $this->ServerStatusData->used_queries;
     $total_queries = array_sum($used_queries);
     $questions_from_start = sprintf(__('Questions since startup: %s'), PMA_Util::formatNumber($total_queries, 0));
     //validate 1: PMA_getHtmlForQueryStatistics
     $this->assertContains('<h3 id="serverstatusqueries">', $html);
     $this->assertContains($questions_from_start, $html);
     //validate 2: per hour
     $this->assertContains(__('per hour:'), $html);
     $this->assertContains(PMA_Util::formatNumber($total_queries * $hour_factor, 0), $html);
     //validate 3:per minute
     $value_per_minute = PMA_Util::formatNumber($total_queries * 60 / $this->ServerStatusData->status['Uptime'], 0);
     $this->assertContains(__('per minute:'), $html);
     $this->assertContains($value_per_minute, $html);
 }
/**
 * return html for Row Statistic
 *
 * @param array $showtable       showing table information
 * @param int   $cell_align_left cell align left
 * @param int   $avg_size        avg size
 * @param int   $avg_unit        avg unit
 * @param bool  $mergetable      is merge table?
 *
 * @return string
 */
function PMA_getHtmlForRowStatistics($showtable, $cell_align_left, $avg_size, $avg_unit, $mergetable)
{
    $html = '<td width="20">&nbsp;</td>';
    // Rows Statistic
    $html .= "\n";
    $html .= '<td class="vtop">';
    $html .= '<big>' . __('Row Statistics:') . '</big>';
    $html .= '<table width="100%">';
    if (isset($showtable['Row_format'])) {
        $html .= "\n";
        $html .= '<tr>';
        $html .= '<td>' . __('Format') . '</td>';
        $html .= '<td class="' . $cell_align_left . '">';
        if ($showtable['Row_format'] == 'Fixed') {
            $html .= __('static');
        } elseif ($showtable['Row_format'] == 'Dynamic') {
            $html .= __('dynamic');
        } else {
            $html .= $showtable['Row_format'];
        }
        $html .= '</td>';
        $html .= '</tr>';
    }
    if (isset($showtable['Rows'])) {
        $html .= "\n";
        $html .= '<tr>';
        $html .= '<td>' . __('Rows') . '</td>';
        $html .= '<td class="right">';
        $html .= PMA_Util::formatNumber($showtable['Rows'], 0);
        $html .= '</td>';
        $html .= '</tr>';
    }
    if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
        $html .= "\n";
        $html .= '<tr>';
        $html .= '<td>' . __('Row length') . '&nbsp;&oslash;</td>';
        $html .= '<td>';
        $html .= PMA_Util::formatNumber($showtable['Avg_row_length'], 0);
        $html .= '</td>';
        $html .= '</tr>';
    }
    if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
        $html .= "\n";
        $html .= '<tr>';
        $html .= '<td>' . __('Row size') . '&nbsp;&oslash;</td>';
        $html .= '<td class="right">';
        $html .= $avg_size . ' ' . $avg_unit;
        $html .= '</td>';
        $html .= '</tr>';
    }
    if (isset($showtable['Auto_increment'])) {
        $html .= "\n";
        $html .= '<tr>';
        $html .= '<td>' . __('Next autoindex') . ' </td>';
        $html .= '<td class="right">';
        $html .= PMA_Util::formatNumber($showtable['Auto_increment'], 0);
        $html .= '</td>';
        $html .= '</tr>';
    }
    if (isset($showtable['Create_time'])) {
        $html .= "\n";
        $html .= '<tr>';
        $html .= '<td>' . __('Creation') . '</td>';
        $html .= '<td class="right">';
        $html .= PMA_Util::localisedDate(strtotime($showtable['Create_time']));
        $html .= '</td>';
        $html .= '</tr>';
    }
    if (isset($showtable['Update_time'])) {
        $html .= "\n";
        $html .= '<tr>';
        $html .= '<td>' . __('Last update') . '</td>';
        $html .= '<td class="right">';
        $html .= PMA_Util::localisedDate(strtotime($showtable['Update_time']));
        $html .= '</td>';
        $html .= '</tr>';
    }
    if (isset($showtable['Check_time'])) {
        $html .= "\n";
        $html .= '<tr>';
        $html .= '<td>' . __('Last check') . '</td>';
        $html .= '<td class="right">';
        $html .= PMA_Util::localisedDate(strtotime($showtable['Check_time']));
        $html .= '</td>';
        $html .= '</tr>';
    }
    return $html;
}
Beispiel #27
0
        echo '<table>' . "\n";
        echo ' <tr>' .  "\n";
        echo '  <th>' . __('Status')
            . PMA_Util::showMySQLDocu(
                'general-thread-states', 'general-thread-states'
            )
            .  '</th>' . "\n";
        echo '  <th>' . __('Time') . '</th>' . "\n";
        echo ' </tr>' .  "\n";

        $chart_json = Array();
        foreach ($profiling_results as $one_result) {
            echo ' <tr>' .  "\n";
            echo '<td>' . ucwords($one_result['Status']) . '</td>' .  "\n";
            echo '<td class="right">'
                . (PMA_Util::formatNumber($one_result['Duration'], 3, 1))
                . 's</td>' .  "\n";
            if (isset($chart_json[ucwords($one_result['Status'])])) {
                $chart_json[ucwords($one_result['Status'])] += $one_result['Duration'];
            } else {
                $chart_json[ucwords($one_result['Status'])] = $one_result['Duration'];
            }
        }

        echo '</table>' . "\n";
        echo '</div>';
        //require_once 'libraries/chart.lib.php';
        echo '<div id="profilingchart" style="display:none;">';
        echo json_encode($chart_json);
        echo '</div>';
        echo '</fieldset>' . "\n";