From ab4bf6d737fac886e022fa159c8e5d15c2d0b25d Mon Sep 17 00:00:00 2001 From: Tyron Madlener Date: Sat, 9 Jul 2011 19:01:06 +0300 Subject: [PATCH] Monitor Log analyzer: This change should hopefully reduce insert length and group together inserts into same table --- js/server_status.js | 67 ++++++++++++++++++++++----------------------- server_status.php | 27 ++++++++++++++---- 2 files changed, 55 insertions(+), 39 deletions(-) diff --git a/js/server_status.js b/js/server_status.js index c32b5096aa..16b10c5193 100644 --- a/js/server_status.js +++ b/js/server_status.js @@ -951,9 +951,9 @@ $(function() { $('#logAnalyseDialog').html( '

Selected time range: ' + Highcharts.dateFormat('%H:%M:%S',new Date(min)) + ' - ' + Highcharts.dateFormat('%H:%M:%S',new Date(max)) + '

' + - '

Results are currently group by query text

'+ - '

Choose from which log you want the statistics to be generated from.

' /*+ - ' '*/ + ' ' + + '

Choose from which log you want the statistics to be generated from.

' + + 'Results are grouped by query text.' ); $('#logAnalyseDialog').dialog({ @@ -961,12 +961,12 @@ $(function() { height: 'auto', buttons: { 'From slow log': function() { - loadLogStatistics({src: 'slow', start: min, end: max}); + loadLogStatistics({src: 'slow', start: min, end: max, groupInserts: $('input#groupInserts').attr('checked') }); $( this ).dialog( "close" ); }, 'From general log': function() { - loadLogStatistics({src: 'general', start: min, end: max}); + loadLogStatistics({src: 'general', start: min, end: max, groupInserts: $('input#groupInserts').attr('checked') }); $( this ).dialog( "close" ); } @@ -1151,37 +1151,34 @@ $(function() { var rows = data.rows; var cols = new Array(); - tableStr = ''; - - for(var i=0; i < rows.length; i++) { - if(i == 0) { - tableStr += ''; - $.each(rows[0],function(key, value) { - cols.push(key); - }); - tableStr += ''; - tableStr += ''; + if(rows.length != 0) { + tableStr = '
' + cols.join('') + '
'; + + for(var i=0; i < rows.length; i++) { + if(i == 0) { + tableStr += ''; + $.each(rows[0],function(key, value) { + cols.push(key); + }); + tableStr += ''; + tableStr += ''; + } + + tableStr += ''; + for(var j=0; j < cols.length; j++) + tableStr += ''; + tableStr += ''; } - tableStr += ''; - for(var j=0; j < cols.length; j++) - tableStr += ''; - tableStr += ''; - } - - tableStr+='
' + cols.join('') + '
' + formatValue(cols[j], rows[i][cols[j]]) + '
' + formatValue(cols[j], rows[i][cols[j]]) + '
'; - - if(rows.length == 0) - tableStr = 'No results found'; - - $('#logTable').html(tableStr); - - $('div#logTable table').tablesorter({ - sortList: [[0,1]], - widgets: ['zebra'] - }); - - if(rows.length != 0) { + tableStr+=''; + + $('#logTable').html(tableStr); + + $('div#logTable table').tablesorter({ + sortList: [[0,1]], + widgets: ['zebra'] + }); + $('#loadingLogsDialog').html('

Log data loaded. Queries executed in this time span:

'); $.each(data.sum, function(key, value) { key = key.charAt(0).toUpperCase() + key.slice(1).toLowerCase(); @@ -1195,10 +1192,12 @@ $(function() { } } ); } else { + $('#loadingLogsDialog').html('

Log analysed, but not data found in this time span.

'); $('#loadingLogsDialog').dialog( "option", "buttons", { "Close": function() { $(this).dialog("close"); } } ); + } } ); diff --git a/server_status.php b/server_status.php index 1e6e45968b..7801fedad2 100644 --- a/server_status.php +++ b/server_status.php @@ -202,13 +202,30 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $return = array( 'rows' => array(), 'sum' => array()); $type = ''; + $insertTables = array(); + $insertTablesFirst = array(); + $i = 0; while ($row = PMA_DBI_fetch_assoc($result)) { - $type = substr($row['argument'],0,strpos($row['argument'],' ')); + preg_match('/^(\w+)\s/',$row['argument'],$match); + $type = $match[1]; $return['sum'][$type]++; - if($type=='INSERT' && strlen($row['argument'] > 300)) - $row['argument'] = substr($row['argument'],0,301) . '...'; + if($type=='INSERT') { + if(isset($_REQUEST['groupInserts']) && $_REQUEST['groupInserts'] && preg_match('/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i',$row['argument'],$matches)) { + $insertTables[$matches[2]]++; + if ($insertTables[$matches[2]] > 1) + $returns['rows'][$insertTablesFirst]['count'] = $insertTables[$matches[2]]; + else { + $insertTablesFirst = $i; + $insertTables[$matches[2]] += $returns['rows'][$insertTablesFirst]['count'] - 1; + } + } + + if(strlen($row['argument']) > 300) + $row['argument'] = substr($row['argument'],0,301) . '...'; + } $return['rows'][] = $row; + $i++; } $return['sum']['TOTAL'] = array_sum($return['sum']); @@ -1240,7 +1257,7 @@ function printMonitor() {
Start Start Monitor Settings Settings - Instructions Instructions + Instructions Instructions/Setup
+