Monitor: Log table filtering and summation

This commit is contained in:
Tyron Madlener 2011-07-18 13:13:40 +03:00
parent fb4b175586
commit a4064cd8ab
2 changed files with 84 additions and 15 deletions

View File

@ -982,7 +982,7 @@ $(function() {
}
if(msg.length == 0) {
icon = 'ic_s_success';
icon = 'ic_s_error';
msg = PMA_messages['strBothLogOff'];
}
@ -1528,9 +1528,11 @@ $(function() {
tableStr += '<td>' + formatValue(cols[j], rows[i][cols[j]]) + '</td>';
tableStr += '</tr>';
}
tableStr+='</tbody></table>';
tableStr += '</tbody><tfoot>';
tableStr += '<tr><th colspan="' + (cols.length - 1) + '">Sum of grouped rows: '+ data.numRows +'<span style="float:right">Total:</span></th><th align="right">' + data.sum.TOTAL + '</th></tr>';
tableStr += '</tfoot></table>';
$('#logTable').html(tableStr);
// Append a tooltip to the count column, if there exist one
@ -1553,6 +1555,8 @@ $(function() {
})
}
$('div#logTable table').tablesorter({
sortList: [[0,1]],
widgets: ['zebra']
@ -1569,6 +1573,64 @@ $(function() {
$('#loadingLogsDialog').append(key + ': ' + value + '<br/>');
});
if(data.numRows > 12) {
$('div#logTable').prepend(
'<fieldset id="logDataFilter">' +
' <legend>Filters</legend>' +
' <div class="formelement">' +
' <label for="filterQueryText">Filter queries by word/regexp:</label>' +
' <input name="filterQueryText" type="text" id="filterQueryText" style="vertical-align: baseline;" />' +
((data.numRows > 250) ? ' <button name="startFilterQueryText" id="startFilterQueryText">Filter</button>' : '') +
' </div>' +
'</fieldset>'
);
if(data.numRows > 250) {
$('div#logTable button#startFilterQueryText').click(filterQueries);
} else {
$('div#logTable input#filterQueryText').keyup(filterQueries);
}
function filterQueries() {
var odd_row=false, cell, textFilter;
var val = $('div#logTable input#filterQueryText').val();
if(val.length == 0) textFilter = null;
else textFilter = new RegExp(val, 'i');
var rowSum = 0, totalSum = 0;
$('div#logTable table tbody tr').each(function() {
// We just assume the sql text is always in the second last column
cell = $(this).children(':nth-child(' + (cols.length - 1) + ')');
if(textFilter==null || textFilter.exec(cell.text())) {
// And that total count is right of the sql text
totalSum += parseInt(cell.next().text());
rowSum ++;
odd_row = !odd_row;
$(this).css('display','');
if(odd_row) {
$(this).addClass('odd');
$(this).removeClass('even');
} else {
$(this).addClass('even');
$(this).removeClass('odd');
}
} else {
$(this).css('display','none');
}
});
$('div#logTable table tfoot tr')
.html('<th colspan="' + (cols.length - 1) +
'">Sum of grouped rows: '+ rowSum +'<span style="float:right">Total:</span></th><th align="right">' +
totalSum + '</th>');
};
}
var dlgBtns = {};
dlgBtns[PMA_messages['strJumpToTable']] = function() {
$(this).dialog("close");

View File

@ -210,7 +210,8 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
preg_match('/^(\w+)\s/',$row['argument'],$match);
$type = strtolower($match[1]);
// Ignore undefined index warning, just increase counter by one
@$return['sum'][$type]++;
@$return['sum'][$type] += $row['#'];
if($type=='insert' || $type=='update') {
// Group inserts if selected
if($type=='insert' && isset($_REQUEST['groupInserts']) && $_REQUEST['groupInserts'] && preg_match('/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i',$row['argument'],$matches)) {
@ -219,8 +220,8 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
$return['rows'][$insertTablesFirst]['#'] = $insertTables[$matches[2]];
// Add a ... to the end of this query to indicate that there's been other queries
$return['rows'][$insertTablesFirst]['argument'][strlen($return['rows'][$insertTablesFirst]['argument'])-1] != '.';
$return['rows'][$insertTablesFirst]['argument'] .= '<br/>...';
if($return['rows'][$insertTablesFirst]['argument'][strlen($return['rows'][$insertTablesFirst]['argument'])-1] != '.')
$return['rows'][$insertTablesFirst]['argument'] .= '<br/>...';
// Group this value, thus do not add to the result list
continue;
@ -240,6 +241,7 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
}
$return['sum']['TOTAL'] = array_sum($return['sum']);
$return['numRows'] = count($return['rows']);
PMA_DBI_free_result($result);
@ -571,7 +573,7 @@ echo __('Runtime Information');
?></h2>
<div id="serverStatusTabs">
<ul>
<li><a href="#statustabs_traffic"><?php echo __('Server traffic'); ?></a></li>
<li><a href="#statustabs_traffic"><?php echo __('Server'); ?></a></li>
<li><a href="#statustabs_queries"><?php echo __('Query statistics'); ?></a></li>
<li><a href="#statustabs_allvars"><?php echo __('All status variables'); ?></a></li>
<li><a href="#statustabs_charting"><?php echo __('Monitor'); ?></a></li>
@ -805,7 +807,7 @@ function printServerTraffic() {
?>
</h3>
<p class="notice">
<p>
<?php
echo sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'),
PMA_timespanFormat($server_status['Uptime']),
@ -1320,7 +1322,8 @@ function printMonitor() {
<div id="monitorInstructionsDialog" title="<?php echo __('Monitor Instructions'); ?>" style="display:none;">
<?php echo __('The phpMyAdmin Monitor can assist you in optimizing the server configuration and track down time intensive
queries. For the latter you will need to log_output set to \'TABLE\' and have either the slow_query_log or general_log enabled.'); ?>
queries. For the latter you will need to set log_output to \'TABLE\' and have either the slow_query_log or general_log enabled. Note however, that the
general_log produces a lot of data and increases server load by up to 15%'); ?>
<p></p>
<img class="ajaxIcon" src="<?php echo $GLOBALS['pmaThemeImage']; ?>ajax_clock_small.gif" alt="Loading">
<div class="ajaxContent">
@ -1333,11 +1336,15 @@ function printMonitor() {
using the cog icon on each respective chart.
<p>When you get to see a sudden spike in activity, select the relevant time span on any chart by holding down the
left mouse button and panning over the chart. This will load statistics from the logs helping you find what caused the
activity spike.</p>
<p><b>Please note:</b>
Enabling the general_log may increase the server load by up to 5-15%. Also be aware that generating statistics out of the logs is a
very load intensive task, thus it is advisable to select only a small time span.
</p>'); ?>
activity spike.</p>');
?>
<p>
<img class="icon ic_s_attention" src="themes/dot.gif" alt="">
<?php echo __('<b>Please note:</b>
Enabling the general_log may increase the server load by 5-15%. Also be aware that generating statistics from the logs is a
load intensive task, so it is advisable to select only a small time span and to disable the general_log and empty its table once monitoring is not required any more.
'); ?>
</p>
</div>
</div>