3 $('div#statustabs_charting div.tabLinks').show();
4 $('div#statustabs_charting img#loadingMonitorIcon').remove();
5 // Codemirror is loaded on demand so we might need to initialize it
6 if (! codemirror_editor) {
7 var elm = $('#sqlquery');
8 if (elm.length > 0 && typeof CodeMirror != 'undefined') {
9 codemirror_editor = CodeMirror.fromTextArea(elm[0], { lineNumbers: true, matchBrackets: true, indentUnit: 4, mode: "text/x-mysql" });
12 // Timepicker is loaded on demand so we need to initialize datetime fields from the 'load log' dialog
13 $('div#logAnalyseDialog .datetimefield').each(function() {
14 PMA_addDatepicker($(this));
17 /**** Monitor charting implementation ****/
18 /* Saves the previous ajax response for differential values */
19 var oldChartData = null;
20 // Holds about to created chart
24 // Whenever the monitor object (runtime.charts) or the settings object (monitorSettings)
25 // changes in a way incompatible to the previous version, increase this number
26 // It will reset the users monitor and settings object in his localStorage to the default configuration
27 var monitorProtocolVersion = '1.0';
29 // Runtime parameter of the monitor, is being fully set in initGrid()
31 // Holds all visible charts in the grid
33 // Stores the timeout handler so it can be cleared
35 // Stores the GET request to refresh the charts
37 // Chart auto increment
39 // To play/pause the monitor
41 // Object that contains a list of nodes that need to be retrieved from the server for chart updates
43 // Current max points per chart (needed for auto calculation)
45 // displayed time frame
50 var monitorSettings = null;
52 var defaultMonitorSettings = {
54 chartSize: { width: 295, height: 250 },
55 // Max points in each chart. Settings it to 'auto' sets gridMaxPoints to (chartwidth - 40) / 12
56 gridMaxPoints: 'auto',
57 /* Refresh rate of all grid charts in ms */
61 // Allows drag and drop rearrange and print/edit icons on charts
64 /* List of preconfigured charts that the user may select */
66 // Query cache efficiency
68 title: PMA_messages['strQueryCacheEfficiency'],
70 name: PMA_messages['strQueryCacheEfficiency'],
71 dataPoints: [{type: 'statusvar', name: 'Qcache_hits'}, {type: 'statusvar', name: 'Com_select'}],
78 title: PMA_messages['strQueryCacheUsage'],
80 name: PMA_messages['strQueryCacheUsed'],
81 dataPoints: [{type: 'statusvar', name: 'Qcache_free_memory'}, {type: 'servervar', name: 'query_cache_size'}],
88 /* Add OS specific system info charts to the preset chart list */
91 $.extend(presetCharts, {
93 title: PMA_messages['strSystemCPUUsage'],
95 name: PMA_messages['strAverageLoad'],
96 dataPoints: [{ type: 'cpu', name: 'loadavg'}],
102 title: PMA_messages['strSystemMemory'],
104 name: PMA_messages['strTotalMemory'],
105 dataPoints: [{ type: 'memory', name: 'MemTotal' }],
107 unit: PMA_messages['strMiB']
110 name: PMA_messages['strUsedMemory'],
111 dataPoints: [{ type: 'memory', name: 'MemUsed' }],
113 unit: PMA_messages['strMiB']
118 title: PMA_messages['strSystemSwap'],
120 name: PMA_messages['strTotalSwap'],
121 dataPoints: [{ type: 'memory', name: 'SwapTotal' }],
123 unit: PMA_messages['strMiB']
125 name: PMA_messages['strUsedSwap'],
126 dataPoints: [{ type: 'memory', name: 'SwapUsed' }],
128 unit: PMA_messages['strMiB']
135 $.extend(presetCharts, {
137 title: PMA_messages['strSystemCPUUsage'],
139 name: PMA_messages['strAverageLoad'],
140 dataPoints: [{ type: 'cpu', name: 'irrelevant' }],
142 transformFn: 'cpu-linux'
146 title: PMA_messages['strSystemMemory'],
148 { name: PMA_messages['strUsedMemory'], dataPoints: [{ type: 'memory', name: 'MemUsed' }], valueDivisor: 1024, unit: PMA_messages['strMiB'] },
149 { name: PMA_messages['strCachedMemory'], dataPoints: [{ type: 'memory', name: 'Cached' }], valueDivisor: 1024, unit: PMA_messages['strMiB'] },
150 { name: PMA_messages['strBufferedMemory'], dataPoints: [{ type: 'memory', name: 'Buffers' }], valueDivisor: 1024, unit: PMA_messages['strMiB'] },
151 { name: PMA_messages['strFreeMemory'], dataPoints: [{ type: 'memory', name: 'MemFree' }], valueDivisor: 1024, unit: PMA_messages['strMiB'] }
166 title: PMA_messages['strSystemSwap'],
168 { name: PMA_messages['strUsedSwap'], dataPoints: [{ type: 'memory', name: 'SwapUsed' }], valueDivisor: 1024, unit: PMA_messages['strMiB'] },
169 { name: PMA_messages['strCachedSwap'], dataPoints: [{ type: 'memory', name: 'SwapCached' }], valueDivisor: 1024, unit: PMA_messages['strMiB'] },
170 { name: PMA_messages['strFreeSwap'], dataPoints: [{ type: 'memory', name: 'SwapFree' }], valueDivisor: 1024, unit: PMA_messages['strMiB'] }
188 // Default setting for the chart grid
190 'c0': { title: PMA_messages['strQuestions'],
191 nodes: [{name: PMA_messages['strQuestions'], dataPoints: [{ type: 'statusvar', name: 'Questions' }], display: 'differential' }]
194 title: PMA_messages['strChartConnectionsTitle'],
195 nodes: [ { name: PMA_messages['strConnections'], dataPoints: [{ type: 'statusvar', name: 'Connections' }], display: 'differential' },
196 { name: PMA_messages['strProcesses'], dataPoints: [{ type: 'proc', name: 'processes' }] } ]
199 title: PMA_messages['strTraffic'],
201 { name: PMA_messages['strBytesSent'], dataPoints: [{ type: 'statusvar', name: 'Bytes_sent' }], display: 'differential', valueDivisor: 1024, unit: PMA_messages['strKiB'] },
202 { name: PMA_messages['strBytesReceived'], dataPoints: [{ type: 'statusvar', name: 'Bytes_received' }], display: 'differential', valueDivisor: 1024, unit: PMA_messages['strKiB'] }
207 // Server is localhost => We can add cpu/memory/swap to the default chart
208 if (server_db_isLocal) {
209 defaultChartGrid['c3'] = presetCharts['cpu'];
210 defaultChartGrid['c4'] = presetCharts['memory'];
211 defaultChartGrid['c5'] = presetCharts['swap'];
214 /* Buttons that are on the top right corner of each chart */
218 symbol: 'url(' + pmaThemeImage + 's_cog.png)',
220 symbolFill: '#B5C9DF',
221 hoverSymbolFill: '#779ABF',
222 _titleKey: 'settings',
223 menuName: 'gridsettings',
225 textKey: 'editChart',
226 onclick: function() {
230 textKey: 'removeChart',
231 onclick: function() {
238 Highcharts.setOptions({
240 settings: PMA_messages['strSettings'],
241 removeChart: PMA_messages['strRemoveChart'],
242 editChart: PMA_messages['strEditChart']
246 $('a[href="#rearrangeCharts"], a[href="#endChartEditMode"]').click(function() {
247 editMode = !editMode;
248 if ($(this).attr('href') == '#endChartEditMode') {
252 // Icon graphics have zIndex 19, 20 and 21. Let's just hope nothing else has the same zIndex
253 $('table#chartGrid div svg').find('*[zIndex=20], *[zIndex=21], *[zIndex=19]').toggle(editMode)
255 $('a[href="#endChartEditMode"]').toggle(editMode);
258 // Close the settings popup
259 $('#statustabs_charting .popupContent').hide().removeClass('openedPopup');
261 $("#chartGrid").sortableTable({
264 left: chartSize().width - 63,
269 // Drop event. The drag child element is moved into the drop element
270 // and vice versa. So the parameters are switched.
271 drop: function(drag, drop, pos) {
272 var dragKey, dropKey, dropRender;
273 var dragRender = $(drag).children().first().attr('id');
275 if ($(drop).children().length > 0) {
276 dropRender = $(drop).children().first().attr('id');
279 // Find the charts in the array
280 $.each(runtime.charts, function(key, value) {
281 if (value.chart.options.chart.renderTo == dragRender) {
284 if (dropRender && value.chart.options.chart.renderTo == dropRender) {
289 // Case 1: drag and drop are charts -> Switch keys
292 dragChart = runtime.charts[dragKey];
293 runtime.charts[dragKey] = runtime.charts[dropKey];
294 runtime.charts[dropKey] = dragChart;
296 // Case 2: drop is a empty cell => just completely rebuild the ids
298 var dropKeyNum = parseInt(dropKey.substr(1));
299 var insertBefore = pos.col + pos.row * monitorSettings.columns;
301 var newChartList = {};
304 $.each(runtime.charts, function(key, value) {
305 if (key != dropKey) {
312 // Rebuilds all ids, with the dragged chart correctly inserted
313 for (var i = 0; i<keys.length; i++) {
314 if (keys[i] == insertBefore) {
315 newChartList['c' + (c++)] = runtime.charts[dropKey];
316 insertBefore = -1; // Insert ok
318 newChartList['c' + (c++)] = runtime.charts[keys[i]];
321 // Not inserted => put at the end
322 if (insertBefore != -1) {
323 newChartList['c' + (c++)] = runtime.charts[dropKey];
326 runtime.charts = newChartList;
336 $("#chartGrid").sortableTable('destroy');
337 saveMonitor(); // Save settings
344 $('div#statustabs_charting div.popupContent select[name="chartColumns"]').change(function() {
345 monitorSettings.columns = parseInt(this.value);
347 var newSize = chartSize();
349 // Empty cells should keep their size so you can drop onto them
350 $('table#chartGrid tr td').css('width', newSize.width + 'px');
352 /* Reorder all charts that it fills all column cells */
354 var $tr = $('table#chartGrid tr:first');
356 while($tr.length != 0) {
358 // To many cells in one row => put into next row
359 $tr.find('td').each(function() {
360 if (numColumns > monitorSettings.columns) {
361 if ($tr.next().length == 0) {
362 $tr.after('<tr></tr>');
364 $tr.next().prepend($(this));
369 // To little cells in one row => for each cell to little, move all cells backwards by 1
370 if ($tr.next().length > 0) {
371 var cnt = monitorSettings.columns - $tr.find('td').length;
372 for (var i = 0; i < cnt; i++) {
373 $tr.append($tr.next().find('td:first'));
374 $tr.nextAll().each(function() {
375 if ($(this).next().length != 0) {
376 $(this).append($(this).next().find('td:first'));
386 /* Apply new chart size to all charts */
387 $.each(runtime.charts, function(key, value) {
395 if (monitorSettings.gridMaxPoints == 'auto') {
396 runtime.gridMaxPoints = Math.round((newSize.width - 40) / 12);
399 runtime.xmin = new Date().getTime() - server_time_diff - runtime.gridMaxPoints * monitorSettings.gridRefresh;
400 runtime.xmax = new Date().getTime() - server_time_diff + monitorSettings.gridRefresh;
403 $("#chartGrid").sortableTable('refresh');
406 saveMonitor(); // Save settings
409 $('div#statustabs_charting div.popupContent select[name="gridChartRefresh"]').change(function() {
410 monitorSettings.gridRefresh = parseInt(this.value) * 1000;
411 clearTimeout(runtime.refreshTimeout);
413 if (runtime.refreshRequest) {
414 runtime.refreshRequest.abort();
417 runtime.xmin = new Date().getTime() - server_time_diff - runtime.gridMaxPoints * monitorSettings.gridRefresh;
418 runtime.xmax = new Date().getTime() - server_time_diff + monitorSettings.gridRefresh;
420 $.each(runtime.charts, function(key, value) {
421 value.chart.xAxis[0].setExtremes(runtime.xmin, runtime.xmax, false);
424 runtime.refreshTimeout = setTimeout(refreshChartGrid, monitorSettings.gridRefresh);
426 saveMonitor(); // Save settings
429 $('a[href="#addNewChart"]').click(function() {
430 var dlgButtons = { };
432 dlgButtons[PMA_messages['strAddChart']] = function() {
433 var type = $('input[name="chartType"]:checked').val();
435 if (type == 'preset') {
436 newChart = presetCharts[$('div#addChartDialog select[name="presetCharts"]').prop('value')];
438 // If user builds his own chart, it's being set/updated each time he adds a series
439 // So here we only warn if he didn't add a series yet
440 if (! newChart || ! newChart.nodes || newChart.nodes.length == 0) {
441 alert(PMA_messages['strAddOneSeriesWarning']);
446 newChart.title = $('input[name="chartTitle"]').attr('value');
447 // Add a cloned object to the chart grid
448 addChart($.extend(true, {}, newChart));
452 saveMonitor(); // Save settings
454 $(this).dialog("close");
457 dlgButtons[PMA_messages['strClose']] = function() {
459 $('span#clearSeriesLink').hide();
460 $('#seriesPreview').html('');
461 $(this).dialog("close");
464 var $presetList = $('div#addChartDialog select[name="presetCharts"]');
465 if ($presetList.html().length == 0) {
466 $.each(presetCharts, function(key, value) {
467 $presetList.append('<option value="' + key + '">' + value.title + '</option>');
469 $presetList.change(function() {
470 $('input#chartPreset').trigger('click');
471 $('input[name="chartTitle"]').attr('value', presetCharts[$(this).prop('value')].title);
475 $('div#addChartDialog').dialog({
481 $('div#addChartDialog #seriesPreview').html('<i>' + PMA_messages['strNone'] + '</i>');
486 $('a[href="#exportMonitorConfig"]').click(function() {
489 $.each(runtime.charts, function(key, elem) {
491 gridCopy[key].nodes = elem.nodes;
492 gridCopy[key].settings = elem.settings;
493 gridCopy[key].title = elem.title;
497 monitorCharts: gridCopy,
498 monitorSettings: monitorSettings
502 $('body').append($form = $('<form method="post" action="file_echo.php?' + url_query + '&filename=1" style="display:none;"></form>'));
504 $form.append('<input type="hidden" name="monitorconfig" value="' + encodeURI($.toJSON(exportData)) + '">');
509 $('a[href="#importMonitorConfig"]').click(function() {
510 $('div#emptyDialog').attr('title', 'Import monitor configuration');
511 $('div#emptyDialog').html('Please select the file you want to import:<br/><form action="file_echo.php?' + url_query + '&import=1" method="post" enctype="multipart/form-data">' +
512 '<input type="file" name="file"> <input type="hidden" name="import" value="1"> </form>');
516 dlgBtns[PMA_messages['strImport']] = function() {
518 $('body').append($iframe = $('<iframe id="monitorConfigUpload" style="display:none;"></iframe>'));
519 var d = $iframe[0].contentWindow.document;
523 $iframe.load(function() {
526 // Try loading config
528 var data = $('body', $('iframe#monitorConfigUpload')[0].contentWindow.document).html();
529 // Chrome wraps around '<pre style="word-wrap: break-word; white-space: pre-wrap;">' to any text content -.-
530 json = $.secureEvalJSON(data.substring(data.indexOf("{"), data.lastIndexOf("}") + 1));
532 alert(PMA_messages['strFailedParsingConfig']);
533 $('div#emptyDialog').dialog('close');
537 // Basic check, is this a monitor config json?
538 if (!json || ! json.monitorCharts || ! json.monitorCharts) {
539 alert(PMA_messages['strFailedParsingConfig']);
540 $('div#emptyDialog').dialog('close');
544 // If json ok, try applying config
546 window.localStorage['monitorCharts'] = $.toJSON(json.monitorCharts);
547 window.localStorage['monitorSettings'] = $.toJSON(json.monitorSettings);
550 alert(PMA_messages['strFailedBuildingGrid']);
551 // If an exception is thrown, load default again
552 window.localStorage.removeItem('monitorCharts');
553 window.localStorage.removeItem('monitorSettings');
557 $('div#emptyDialog').dialog('close');
560 $("body", d).append($form = $('div#emptyDialog').find('form'));
562 $('div#emptyDialog').append('<img class="ajaxIcon" src="' + pmaThemeImage + 'ajax_clock_small.gif" alt="">');
565 dlgBtns[PMA_messages['strCancel']] = function() {
566 $(this).dialog('close');
570 $('div#emptyDialog').dialog({
577 $('a[href="#clearMonitorConfig"]').click(function() {
578 window.localStorage.removeItem('monitorCharts');
579 window.localStorage.removeItem('monitorSettings');
580 window.localStorage.removeItem('monitorVersion');
585 $('a[href="#pauseCharts"]').click(function() {
586 runtime.redrawCharts = ! runtime.redrawCharts;
587 if (! runtime.redrawCharts) {
588 $(this).html('<img src="themes/dot.gif" class="icon ic_play" alt="" /> ' + PMA_messages['strResumeMonitor']);
590 $(this).html('<img src="themes/dot.gif" class="icon ic_pause" alt="" /> ' + PMA_messages['strPauseMonitor']);
591 if (! runtime.charts) {
593 $('a[href="#settingsPopup"]').show();
599 $('a[href="#monitorInstructionsDialog"]').click(function() {
600 var $dialog = $('div#monitorInstructionsDialog');
605 }).find('img.ajaxIcon').show();
607 var loadLogVars = function(getvars) {
608 vars = { ajax_request: true, logging_vars: true };
610 $.extend(vars, getvars);
613 $.get('server_status.php?' + url_query, vars,
615 var logVars = $.parseJSON(data),
616 icon = 'ic_s_success', msg='', str='';
618 if (logVars['general_log'] == 'ON') {
619 if (logVars['slow_query_log'] == 'ON') {
620 msg = PMA_messages['strBothLogOn'];
622 msg = PMA_messages['strGenLogOn'];
626 if (msg.length == 0 && logVars['slow_query_log'] == 'ON') {
627 msg = PMA_messages['strSlowLogOn'];
630 if (msg.length == 0) {
632 msg = PMA_messages['strBothLogOff'];
635 str = '<b>' + PMA_messages['strCurrentSettings'] + '</b><br><div class="smallIndent">';
636 str += '<img src="themes/dot.gif" class="icon ' + icon + '" alt=""/> ' + msg + '<br />';
638 if (logVars['log_output'] != 'TABLE') {
639 str += '<img src="themes/dot.gif" class="icon ic_s_error" alt=""/> ' + PMA_messages['strLogOutNotTable'] + '<br />';
641 str += '<img src="themes/dot.gif" class="icon ic_s_success" alt=""/> ' + PMA_messages['strLogOutIsTable'] + '<br />';
644 if (logVars['slow_query_log'] == 'ON') {
645 if (logVars['long_query_time'] > 2) {
646 str += '<img src="themes/dot.gif" class="icon ic_s_attention" alt=""/> '
647 + $.sprintf(PMA_messages['strSmallerLongQueryTimeAdvice'], logVars['long_query_time'])
651 if (logVars['long_query_time'] < 2) {
652 str += '<img src="themes/dot.gif" class="icon ic_s_success" alt=""/> '
653 + $.sprintf(PMA_messages['strLongQueryTimeSet'], logVars['long_query_time'])
661 str += '<p></p><b>Change settings</b>';
662 str += '<div class="smallIndent">';
663 str += PMA_messages['strSettingsAppliedGlobal'] + '<br/>';
665 var varValue = 'TABLE';
666 if (logVars['log_output'] == 'TABLE') {
670 str += '- <a class="set" href="#log_output-' + varValue + '">'
671 + $.sprintf(PMA_messages['strSetLogOutput'], varValue)
674 if (logVars['general_log'] != 'ON') {
675 str += '- <a class="set" href="#general_log-ON">'
676 + $.sprintf(PMA_messages['strEnableVar'], 'general_log')
679 str += '- <a class="set" href="#general_log-OFF">'
680 + $.sprintf(PMA_messages['strDisableVar'], 'general_log')
684 if (logVars['slow_query_log'] != 'ON') {
685 str += '- <a class="set" href="#slow_query_log-ON">'
686 + $.sprintf(PMA_messages['strEnableVar'], 'slow_query_log')
689 str += '- <a class="set" href="#slow_query_log-OFF">'
690 + $.sprintf(PMA_messages['strDisableVar'], 'slow_query_log')
695 if (logVars['long_query_time'] > 2) {
699 str += '- <a class="set" href="#long_query_time-' + varValue + '">'
700 + $.sprintf(PMA_messages['setSetLongQueryTime'], varValue)
704 str += PMA_messages['strNoSuperUser'] + '<br/>';
709 $dialog.find('div.monitorUse').toggle(
710 logVars['log_output'] == 'TABLE' && (logVars['slow_query_log'] == 'ON' || logVars['general_log'] == 'ON')
713 $dialog.find('div.ajaxContent').html(str);
714 $dialog.find('img.ajaxIcon').hide();
715 $dialog.find('a.set').click(function() {
716 var nameValue = $(this).attr('href').split('-');
717 loadLogVars({ varName: nameValue[0].substr(1), varValue: nameValue[1]});
718 $dialog.find('img.ajaxIcon').show();
730 $('input[name="chartType"]').change(function() {
731 $('#chartVariableSettings').toggle(this.checked && this.value == 'variable');
732 var title = $('input[name="chartTitle"]').attr('value');
733 if (title == PMA_messages['strChartTitle']
734 || title == $('label[for="' + $('input[name="chartTitle"]').data('lastRadio') + '"]').text()
736 $('input[name="chartTitle"]')
737 .data('lastRadio', $(this).attr('id'))
738 .attr('value', $('label[for="' + $(this).attr('id') + '"]').text());
743 $('input[name="useDivisor"]').change(function() {
744 $('span.divisorInput').toggle(this.checked);
746 $('input[name="useUnit"]').change(function() {
747 $('span.unitInput').toggle(this.checked);
750 $('select[name="varChartList"]').change(function () {
751 if (this.selectedIndex != 0) {
752 $('#variableInput').attr('value', this.value);
756 $('a[href="#kibDivisor"]').click(function() {
757 $('input[name="valueDivisor"]').attr('value', 1024);
758 $('input[name="valueUnit"]').attr('value', PMA_messages['strKiB']);
759 $('span.unitInput').toggle(true);
760 $('input[name="useUnit"]').prop('checked', true);
764 $('a[href="#mibDivisor"]').click(function() {
765 $('input[name="valueDivisor"]').attr('value', 1024*1024);
766 $('input[name="valueUnit"]').attr('value', PMA_messages['strMiB']);
767 $('span.unitInput').toggle(true);
768 $('input[name="useUnit"]').prop('checked', true);
772 $('a[href="#submitClearSeries"]').click(function() {
773 $('#seriesPreview').html('<i>' + PMA_messages['strNone'] + '</i>');
775 $('span#clearSeriesLink').hide();
778 $('a[href="#submitAddSeries"]').click(function() {
779 if ($('input#variableInput').attr('value').length == 0) {
783 if (newChart == null) {
784 $('#seriesPreview').html('');
787 title: $('input[name="chartTitle"]').attr('value'),
793 dataPoints: [{ type: 'statusvar', name: $('input#variableInput').attr('value') }],
794 name: $('input#variableInput').attr('value'),
795 display: $('input[name="differentialValue"]').attr('checked') ? 'differential' : ''
798 if (serie.dataPoint == 'Processes') {
799 serie.dataType='proc';
802 if ($('input[name="useDivisor"]').attr('checked')) {
803 serie.valueDivisor = parseInt($('input[name="valueDivisor"]').attr('value'));
806 if ($('input[name="useUnit"]').attr('checked')) {
807 serie.unit = $('input[name="valueUnit"]').attr('value');
810 var str = serie.display == 'differential' ? ', ' + PMA_messages['strDifferential'] : '';
811 str += serie.valueDivisor ? (', ' + $.sprintf(PMA_messages['strDividedBy'], serie.valueDivisor)) : '';
813 $('#seriesPreview').append('- ' + serie.name + str + '<br>');
815 newChart.nodes.push(serie);
817 $('input#variableInput').attr('value', '');
818 $('input[name="differentialValue"]').attr('checked', true);
819 $('input[name="useDivisor"]').attr('checked', false);
820 $('input[name="useUnit"]').attr('checked', false);
821 $('input[name="useDivisor"]').trigger('change');
822 $('input[name="useUnit"]').trigger('change');
823 $('select[name="varChartList"]').get(0).selectedIndex = 0;
825 $('span#clearSeriesLink').show();
830 $("input#variableInput").autocomplete({
831 source: variableNames
834 /* Initializes the monitor, called only once */
835 function initGrid() {
839 /* Apply default values & config */
840 if (window.localStorage) {
841 if (window.localStorage['monitorCharts']) {
842 runtime.charts = $.parseJSON(window.localStorage['monitorCharts']);
844 if (window.localStorage['monitorSettings']) {
845 monitorSettings = $.parseJSON(window.localStorage['monitorSettings']);
848 $('a[href="#clearMonitorConfig"]').toggle(runtime.charts != null);
850 if (runtime.charts != null && monitorProtocolVersion != window.localStorage['monitorVersion']) {
851 $('div#emptyDialog').attr('title',PMA_messages['strIncompatibleMonitorConfig']);
852 $('div#emptyDialog').html(PMA_messages['strIncompatibleMonitorConfigDescription']);
855 dlgBtns[PMA_messages['strClose']] = function() { $(this).dialog('close'); };
857 $('div#emptyDialog').dialog({
864 if (runtime.charts == null) {
865 runtime.charts = defaultChartGrid;
867 if (monitorSettings == null) {
868 monitorSettings = defaultMonitorSettings;
871 $('select[name="gridChartRefresh"]').attr('value', monitorSettings.gridRefresh / 1000);
872 $('select[name="chartColumns"]').attr('value', monitorSettings.columns);
874 if (monitorSettings.gridMaxPoints == 'auto') {
875 runtime.gridMaxPoints = Math.round((monitorSettings.chartSize.width - 40) / 12);
877 runtime.gridMaxPoints = monitorSettings.gridMaxPoints;
880 runtime.xmin = new Date().getTime() - server_time_diff - runtime.gridMaxPoints * monitorSettings.gridRefresh;
881 runtime.xmax = new Date().getTime() - server_time_diff + monitorSettings.gridRefresh;
883 /* Calculate how much spacing there is between each chart */
884 $('table#chartGrid').html('<tr><td></td><td></td></tr><tr><td></td><td></td></tr>');
886 width: $('table#chartGrid td:nth-child(2)').offset().left
887 - $('table#chartGrid td:nth-child(1)').offset().left,
888 height: $('table#chartGrid tr:nth-child(2) td:nth-child(2)').offset().top
889 - $('table#chartGrid tr:nth-child(1) td:nth-child(1)').offset().top
891 $('table#chartGrid').html('');
893 /* Add all charts - in correct order */
895 $.each(runtime.charts, function(key, value) {
899 for (var i = 0; i<keys.length; i++)
900 addChart(runtime.charts[keys[i]], true);
902 /* Fill in missing cells */
903 var numCharts = $('table#chartGrid .monitorChart').length;
904 var numMissingCells = (monitorSettings.columns - numCharts % monitorSettings.columns) % monitorSettings.columns;
905 for (var i = 0; i < numMissingCells; i++) {
906 $('table#chartGrid tr:last').append('<td></td>');
909 // Empty cells should keep their size so you can drop onto them
910 $('table#chartGrid tr td').css('width', chartSize().width + 'px');
912 buildRequiredDataList();
916 /* Destroys all monitor related resources */
917 function destroyGrid() {
918 if (runtime.charts) {
919 $.each(runtime.charts, function(key, value) {
921 value.chart.destroy();
927 runtime.refreshRequest.abort();
930 clearTimeout(runtime.refreshTimeout);
933 $('table#chartGrid').html('');
935 runtime.charts = null;
937 monitorSettings = null;
940 /* Calls destroyGrid() and initGrid(), but before doing so it saves the chart
941 * data from each chart and restores it after the monitor is initialized again */
942 function rebuildGrid() {
944 if (runtime.charts) {
946 $.each(runtime.charts, function(key, chartObj) {
947 for (var i = 0; i < chartObj.nodes.length; i++) {
948 oldData[chartObj.nodes[i].dataPoint] = [];
949 for (var j = 0; j < chartObj.chart.series[i].data.length; j++)
950 oldData[chartObj.nodes[i].dataPoint].push([chartObj.chart.series[i].data[j].x, chartObj.chart.series[i].data[j].y]);
959 $.each(runtime.charts, function(key, chartObj) {
960 for (var j = 0; j < chartObj.nodes.length; j++) {
961 if (oldData[chartObj.nodes[j].dataPoint]) {
962 chartObj.chart.series[j].setData(oldData[chartObj.nodes[j].dataPoint]);
969 /* Calculactes the dynamic chart size that depends on the column width */
970 function chartSize() {
971 var wdt = $('div#logTable').innerWidth() / monitorSettings.columns - (monitorSettings.columns - 1) * chartSpacing.width;
978 /* Adds a chart to the chart grid */
979 function addChart(chartObj, initialize) {
981 for (var j = 0; j<chartObj.nodes.length; j++)
982 series.push(chartObj.nodes[j]);
986 renderTo: 'gridchart' + runtime.chartAI,
987 width: chartSize().width,
988 height: chartSize().height,
992 selection: function(event) {
997 var extremesObject = event.xAxis[0],
998 min = extremesObject.min,
999 max = extremesObject.max;
1001 $('#logAnalyseDialog input[name="dateStart"]')
1002 .attr('value', Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', new Date(min)));
1003 $('#logAnalyseDialog input[name="dateEnd"]')
1004 .attr('value', Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', new Date(max)));
1008 dlgBtns[PMA_messages['strFromSlowLog']] = function() {
1010 $(this).dialog("close");
1013 dlgBtns[PMA_messages['strFromGeneralLog']] = function() {
1015 $(this).dialog("close");
1018 function loadLog(type) {
1019 var dateStart = Date.parse($('#logAnalyseDialog input[name="dateStart"]').prop('value')) || min;
1020 var dateEnd = Date.parse($('#logAnalyseDialog input[name="dateEnd"]').prop('value')) || max;
1026 removeVariables: $('input#removeVariables').prop('checked'),
1027 limitTypes: $('input#limitTypes').prop('checked')
1031 $('#logAnalyseDialog').dialog({
1052 formatter: function() {
1053 var s = '<b>' + Highcharts.dateFormat('%H:%M:%S', this.x) + '</b>';
1055 $.each(this.points, function(i, point) {
1056 s += '<br/><span style="color:' + point.series.color + '">' + point.series.name + ':</span> ' +
1057 ((parseInt(point.y) == point.y) ? point.y : Highcharts.numberFormat(this.y, 2)) + ' ' + (point.series.options.unit || '');
1068 buttons: gridbuttons,
1069 title: { text: chartObj.title }
1072 if (chartObj.settings) {
1073 $.extend(true, settings, chartObj.settings);
1076 if ($('#' + settings.chart.renderTo).length == 0) {
1077 var numCharts = $('table#chartGrid .monitorChart').length;
1079 if (numCharts == 0 || !( numCharts % monitorSettings.columns)) {
1080 $('table#chartGrid').append('<tr></tr>');
1083 $('table#chartGrid tr:last').append('<td><div class="ui-state-default monitorChart" id="' + settings.chart.renderTo + '"></div></td>');
1086 chartObj.chart = PMA_createChart(settings);
1087 chartObj.numPoints = 0;
1089 if (initialize != true) {
1090 runtime.charts['c' + runtime.chartAI] = chartObj;
1091 buildRequiredDataList();
1094 // Edit, Print icon only in edit mode
1095 $('table#chartGrid div svg').find('*[zIndex=20], *[zIndex=21], *[zIndex=19]').toggle(editMode)
1100 /* Opens a dialog that allows one to edit the title and series labels of the supplied chart */
1101 function editChart(chartObj) {
1102 var htmlnode = chartObj.options.chart.renderTo;
1108 var chartKey = null;
1109 $.each(runtime.charts, function(key, value) {
1110 if (value.chart.options.chart.renderTo == htmlnode) {
1117 if (chart == null) {
1121 var htmlStr = '<p><b>Chart title: </b> <br/> <input type="text" size="35" name="chartTitle" value="' + chart.title + '" />';
1122 htmlStr += '</p><p><b>Series:</b> </p><ol>';
1123 for (var i = 0; i<chart.nodes.length; i++) {
1124 htmlStr += '<li><i>' + chart.nodes[i].dataPoints[0].name + ': </i><br/><input type="text" name="chartSerie-' + i + '" value="' + chart.nodes[i].name + '" /></li>';
1128 dlgBtns['Save'] = function() {
1129 runtime.charts[chartKey].title = $('div#emptyDialog input[name="chartTitle"]').attr('value');
1130 runtime.charts[chartKey].chart.setTitle({ text: runtime.charts[chartKey].title });
1132 $('div#emptyDialog input[name*="chartSerie"]').each(function() {
1133 var idx = $(this).attr('name').split('-')[1];
1134 runtime.charts[chartKey].nodes[idx].name = $(this).attr('value');
1135 runtime.charts[chartKey].chart.series[idx].name = $(this).attr('value');
1138 $(this).dialog('close');
1141 dlgBtns['Cancel'] = function() {
1142 $(this).dialog('close');
1145 $('div#emptyDialog').attr('title', 'Edit chart');
1146 $('div#emptyDialog').html(htmlStr + '</ol>');
1147 $('div#emptyDialog').dialog({
1154 /* Removes a chart from the grid */
1155 function removeChart(chartObj) {
1156 var htmlnode = chartObj.options.chart.renderTo;
1161 $.each(runtime.charts, function(key, value) {
1162 if (value.chart.options.chart.renderTo == htmlnode) {
1163 delete runtime.charts[key];
1168 buildRequiredDataList();
1170 // Using settimeout() because clicking the remove link fires an onclick event
1171 // which throws an error when the chart is destroyed
1172 setTimeout(function() {
1174 $('div#' + htmlnode).remove();
1177 saveMonitor(); // Save settings
1180 /* Called in regular intervalls, this function updates the values of each chart in the grid */
1181 function refreshChartGrid() {
1182 /* Send to server */
1183 runtime.refreshRequest = $.post('server_status.php?' + url_query, {
1187 requiredData: $.toJSON(runtime.dataList)
1191 chartData = $.parseJSON(data);
1193 return serverResponseError();
1198 /* Update values in each graph */
1199 $.each(runtime.charts, function(orderKey, elem) {
1200 var key = elem.chartID;
1201 // If newly added chart, we have no data for it yet
1202 if (! chartData[key]) {
1206 for (var j = 0; j < elem.nodes.length; j++) {
1208 if (i == 0 && j == 0) {
1209 if (oldChartData == null) {
1210 diff = chartData.x - runtime.xmax;
1212 diff = parseInt(chartData.x - oldChartData.x);
1215 runtime.xmin += diff;
1216 runtime.xmax += diff;
1219 elem.chart.xAxis[0].setExtremes(runtime.xmin, runtime.xmax, false);
1221 /* Calculate y value */
1223 // If transform function given, use it
1224 if (elem.nodes[j].transformFn) {
1225 value = chartValueTransform(
1226 elem.nodes[j].transformFn,
1228 // Check if first iteration (oldChartData==null), or if newly added chart oldChartData[key]==null
1229 (oldChartData == null || oldChartData[key] == null ? null : oldChartData[key][j])
1232 // Otherwise use original value and apply differential and divisor if given,
1233 // in this case we have only one data point per series - located at chartData[key][j][0]
1235 value = parseFloat(chartData[key][j][0].value);
1237 if (elem.nodes[j].display == 'differential') {
1238 if (oldChartData == null || oldChartData[key] == null) {
1241 value -= oldChartData[key][j][0].value;
1244 if (elem.nodes[j].valueDivisor) {
1245 value = value / elem.nodes[j].valueDivisor;
1249 // Set y value, if defined
1250 if (value != undefined) {
1251 elem.chart.series[j].addPoint(
1252 { x: chartData.x, y: value },
1254 elem.numPoints >= runtime.gridMaxPoints
1261 runtime.charts[orderKey].numPoints++;
1262 if (runtime.redrawCharts) {
1263 elem.chart.redraw();
1267 oldChartData = chartData;
1269 runtime.refreshTimeout = setTimeout(refreshChartGrid, monitorSettings.gridRefresh);
1273 /* Function that supplies special value transform functions for chart values */
1274 function chartValueTransform(name, cur, prev) {
1280 // cur and prev are datapoint arrays, but containing only 1 element for cpu-linux
1281 cur = cur[0], prev = prev[0];
1283 var diff_total = cur.busy + cur.idle - (prev.busy + prev.idle);
1284 var diff_idle = cur.idle - prev.idle;
1285 return 100 * (diff_total - diff_idle) / diff_total;
1287 // Query cache efficiency (%)
1292 // cur[0].value is Qcache_hits, cur[1].value is Com_select
1293 var diffQHits = cur[0].value - prev[0].value;
1294 // No NaN please :-)
1295 if (cur[1].value - prev[1].value == 0) return 0;
1297 return diffQHits / (cur[1].value - prev[1].value + diffQHits) * 100;
1299 // Query cache usage (%)
1301 if (cur[1].value == 0) return 0;
1302 // cur[0].value is Qcache_free_memory, cur[1].value is query_cache_size
1303 return 100 - cur[0].value / cur[1].value * 100;
1309 /* Build list of nodes that need to be retrieved from server.
1310 * It creates something like a stripped down version of the runtime.charts object.
1312 function buildRequiredDataList() {
1313 runtime.dataList = {};
1314 // Store an own id, because the property name is subject of reordering,
1315 // thus destroying our mapping with runtime.charts <=> runtime.dataList
1317 $.each(runtime.charts, function(key, chart) {
1318 runtime.dataList[chartID] = [];
1319 for(var i=0; i < chart.nodes.length; i++) {
1320 runtime.dataList[chartID][i] = chart.nodes[i].dataPoints;
1322 runtime.charts[key].chartID = chartID;
1327 /* Loads the log table data, generates the table and handles the filters */
1328 function loadLogStatistics(opts) {
1330 var logRequest = null;
1332 if (! opts.removeVariables) {
1333 opts.removeVariables = false;
1335 if (! opts.limitTypes) {
1336 opts.limitTypes = false;
1339 $('#emptyDialog').html(PMA_messages['strAnalysingLogs'] +
1340 ' <img class="ajaxIcon" src="' + pmaThemeImage +
1341 'ajax_clock_small.gif" alt="">');
1343 $('#emptyDialog').dialog({
1347 'Cancel request': function() {
1348 if (logRequest != null) {
1352 $(this).dialog("close");
1358 logRequest = $.get('server_status.php?' + url_query,
1359 { ajax_request: true,
1362 time_start: Math.round(opts.start / 1000),
1363 time_end: Math.round(opts.end / 1000),
1364 removeVariables: opts.removeVariables,
1365 limitTypes: opts.limitTypes
1370 logData = $.parseJSON(data);
1372 return serverResponseError();
1375 if (logData.rows.length != 0) {
1376 runtime.logDataCols = buildLogTable(logData);
1378 /* Show some stats in the dialog */
1379 $('#emptyDialog').attr('title', PMA_messages['strLoadingLogs']);
1380 $('#emptyDialog').html('<p>' + PMA_messages['strLogDataLoaded'] + '</p>');
1381 $.each(logData.sum, function(key, value) {
1382 key = key.charAt(0).toUpperCase() + key.slice(1).toLowerCase();
1383 if (key == 'Total') {
1384 key = '<b>' + key + '</b>';
1386 $('#emptyDialog').append(key + ': ' + value + '<br/>');
1389 /* Add filter options if more than a bunch of rows there to filter */
1390 if (logData.numRows > 12) {
1391 $('div#logTable').prepend(
1392 '<fieldset id="logDataFilter">' +
1393 ' <legend>' + PMA_messages['strFiltersForLogTable'] + '</legend>' +
1394 ' <div class="formelement">' +
1395 ' <label for="filterQueryText">' + PMA_messages['strFilterByWordRegexp'] + '</label>' +
1396 ' <input name="filterQueryText" type="text" id="filterQueryText" style="vertical-align: baseline;" />' +
1398 ((logData.numRows > 250) ? ' <div class="formelement"><button name="startFilterQueryText" id="startFilterQueryText">' + PMA_messages['strFilter'] + '</button></div>' : '') +
1399 ' <div class="formelement">' +
1400 ' <input type="checkbox" id="noWHEREData" name="noWHEREData" value="1" /> ' +
1401 ' <label for="noWHEREData"> ' + PMA_messages['strIgnoreWhereAndGroup'] + '</label>' +
1406 $('div#logTable input#noWHEREData').change(function() {
1407 filterQueries(true);
1410 if (logData.numRows > 250) {
1411 $('div#logTable button#startFilterQueryText').click(filterQueries);
1413 $('div#logTable input#filterQueryText').keyup(filterQueries);
1419 dlgBtns[PMA_messages['strJumpToTable']] = function() {
1420 $(this).dialog("close");
1421 $(document).scrollTop($('div#logTable').offset().top);
1424 $('#emptyDialog').dialog( "option", "buttons", dlgBtns);
1427 $('#emptyDialog').html('<p>' + PMA_messages['strNoDataFound'] + '</p>');
1430 dlgBtns[PMA_messages['strClose']] = function() {
1431 $(this).dialog("close");
1434 $('#emptyDialog').dialog( "option", "buttons", dlgBtns );
1439 /* Handles the actions performed when the user uses any of the log table filters
1440 * which are the filter by name and grouping with ignoring data in WHERE clauses
1442 * @param boolean Should be true when the users enabled or disabled to group queries ignoring data in WHERE clauses
1444 function filterQueries(varFilterChange) {
1445 var odd_row = false, cell, textFilter;
1446 var val = $('div#logTable input#filterQueryText').val();
1448 if (val.length == 0) {
1451 textFilter = new RegExp(val, 'i');
1454 var rowSum = 0, totalSum = 0, i = 0, q;
1455 var noVars = $('div#logTable input#noWHEREData').attr('checked');
1456 var equalsFilter = /([^=]+)=(\d+|((\'|"|).*?[^\\])\4((\s+)|$))/gi;
1457 var functionFilter = /([a-z0-9_]+)\(.+?\)/gi;
1458 var filteredQueries = {}, filteredQueriesLines = {};
1459 var hide = false, rowData;
1460 var queryColumnName = runtime.logDataCols[runtime.logDataCols.length - 2];
1461 var sumColumnName = runtime.logDataCols[runtime.logDataCols.length - 1];
1462 var isSlowLog = opts.src == 'slow';
1463 var columnSums = {};
1465 // For the slow log we have to count many columns (query_time, lock_time, rows_examined, rows_sent, etc.)
1466 var countRow = function(query, row) {
1467 var cells = row.match(/<td>(.*?)<\/td>/gi);
1468 if (!columnSums[query]) {
1469 columnSums[query] = [0, 0, 0, 0];
1472 // lock_time and query_time and displayed in timespan format
1473 columnSums[query][0] += timeToSec(cells[2].replace(/(<td>|<\/td>)/gi, ''));
1474 columnSums[query][1] += timeToSec(cells[3].replace(/(<td>|<\/td>)/gi, ''));
1475 // rows_examind and rows_sent are just numbers
1476 columnSums[query][2] += parseInt(cells[4].replace(/(<td>|<\/td>)/gi, ''));
1477 columnSums[query][3] += parseInt(cells[5].replace(/(<td>|<\/td>)/gi, ''));
1480 // We just assume the sql text is always in the second last column, and that the total count is right of it
1481 $('div#logTable table tbody tr td:nth-child(' + (runtime.logDataCols.length - 1) + ')').each(function() {
1482 // If query is a SELECT and user enabled or disabled to group queries ignoring data in where statements, we
1483 // need to re-calculate the sums of each row
1484 if (varFilterChange && $(this).html().match(/^SELECT/i)) {
1486 // Group on => Sum up identical columns, and hide all but 1
1488 q = $(this).text().replace(equalsFilter, '$1=...$6').trim();
1489 q = q.replace(functionFilter, ' $1(...)');
1491 // Js does not specify a limit on property name length, so we can abuse it as index :-)
1492 if (filteredQueries[q]) {
1493 filteredQueries[q] += parseInt($(this).next().text());
1494 totalSum += parseInt($(this).next().text());
1497 filteredQueries[q] = parseInt($(this).next().text());;
1498 filteredQueriesLines[q] = i;
1502 countRow(q, $(this).parent().html());
1506 // Group off: Restore original columns
1508 rowData = $(this).parent().data('query');
1510 $(this).text(rowData[queryColumnName]);
1511 // Restore total count
1512 $(this).next().text(rowData[sumColumnName]);
1513 // Restore slow log columns
1515 $(this).parent().children('td:nth-child(3)').text(rowData['query_time']);
1516 $(this).parent().children('td:nth-child(4)').text(rowData['lock_time']);
1517 $(this).parent().children('td:nth-child(5)').text(rowData['rows_sent']);
1518 $(this).parent().children('td:nth-child(6)').text(rowData['rows_examined']);
1523 // If not required to be hidden, do we need to hide because of a not matching text filter?
1524 if (! hide && (textFilter != null && ! textFilter.exec($(this).text()))) {
1528 // Now display or hide this column
1530 $(this).parent().css('display', 'none');
1532 totalSum += parseInt($(this).next().text());
1535 odd_row = ! odd_row;
1536 $(this).parent().css('display', '');
1538 $(this).parent().addClass('odd');
1539 $(this).parent().removeClass('even');
1541 $(this).parent().addClass('even');
1542 $(this).parent().removeClass('odd');
1550 // We finished summarizing counts => Update count values of all grouped entries
1551 if (varFilterChange) {
1553 var numCol, row, $table = $('div#logTable table tbody');
1554 $.each(filteredQueriesLines, function(key, value) {
1555 if (filteredQueries[key] <= 1) {
1559 row = $table.children('tr:nth-child(' + (value + 1) + ')');
1560 numCol = row.children(':nth-child(' + (runtime.logDataCols.length) + ')');
1561 numCol.text(filteredQueries[key]);
1564 row.children('td:nth-child(3)').text(secToTime(columnSums[key][0]));
1565 row.children('td:nth-child(4)').text(secToTime(columnSums[key][1]));
1566 row.children('td:nth-child(5)').text(columnSums[key][2]);
1567 row.children('td:nth-child(6)').text(columnSums[key][3]);
1572 $('div#logTable table').trigger("update");
1573 setTimeout(function() {
1574 $('div#logTable table').trigger('sorton', [[[runtime.logDataCols.length - 1, 1]]]);
1578 // Display some stats at the bottom of the table
1579 $('div#logTable table tfoot tr')
1580 .html('<th colspan="' + (runtime.logDataCols.length - 1) + '">' +
1581 PMA_messages['strSumRows'] + ' ' + rowSum + '<span style="float:right">' +
1582 PMA_messages['strTotal'] + '</span></th><th align="right">' + totalSum + '</th>');
1586 /* Turns a timespan (12:12:12) into a number */
1587 function timeToSec(timeStr) {
1588 var time = timeStr.split(':');
1589 return parseInt(time[0]*3600) + parseInt(time[1]*60) + parseInt(time[2]);
1592 /* Turns a number into a timespan (100 into 00:01:40) */
1593 function secToTime(timeInt) {
1594 hours = Math.floor(timeInt / 3600);
1595 timeInt -= hours*3600;
1596 minutes = Math.floor(timeInt / 60);
1597 timeInt -= minutes*60;
1600 hours = '0' + hours;
1603 minutes = '0' + minutes;
1606 timeInt = '0' + timeInt;
1609 return hours + ':' + minutes + ':' + timeInt;
1612 /* Constructs the log table out of the retrieved server data */
1613 function buildLogTable(data) {
1614 var rows = data.rows;
1615 var cols = new Array();
1616 var $table = $('<table border="0" class="sortable"></table>');
1617 var $tBody, $tRow, $tCell;
1619 $('#logTable').html($table);
1621 var formatValue = function(name, value) {
1624 return value.replace(/(\[.*?\])+/g, '');
1629 for (var i = 0; i < rows.length; i++) {
1631 $.each(rows[0], function(key, value) {
1634 $table.append( '<thead>' +
1635 '<tr><th class="nowrap">' + cols.join('</th><th class="nowrap">') + '</th></tr>' +
1638 $table.append($tBody = $('<tbody></tbody>'));
1641 $tBody.append($tRow = $('<tr class="noclick"></tr>'));
1643 for (var j = 0; j < cols.length; j++) {
1644 // Assuming the query column is the second last
1645 if (j == cols.length - 2 && rows[i][cols[j]].match(/^SELECT/i)) {
1646 $tRow.append($tCell = $('<td class="linkElem">' + formatValue(cols[j], rows[i][cols[j]]) + '</td>'));
1647 $tCell.click(openQueryAnalyzer);
1649 $tRow.append('<td>' + formatValue(cols[j], rows[i][cols[j]]) + '</td>');
1652 $tRow.data('query', rows[i]);
1656 $table.append('<tfoot>' +
1657 '<tr><th colspan="' + (cols.length - 1) + '">' + PMA_messages['strSumRows'] +
1658 ' ' + data.numRows + '<span style="float:right">' + PMA_messages['strTotal'] +
1659 '</span></th><th align="right">' + data.sum.TOTAL + '</th></tr></tfoot>');
1661 // Append a tooltip to the count column, if there exist one
1662 if ($('#logTable th:last').html() == '#') {
1663 $('#logTable th:last').append(' <img class="qroupedQueryInfoIcon icon ic_b_docs" src="themes/dot.gif" alt="" />');
1665 var qtipContent = PMA_messages['strCountColumnExplanation'];
1667 qtipContent += '<p>' + PMA_messages['strMoreCountColumnExplanation'] + '</p>';
1670 $('img.qroupedQueryInfoIcon').qtip({
1671 content: qtipContent,
1674 target: 'bottomMiddle',
1679 hide: { delay: 1000 }
1683 $('div#logTable table').tablesorter({
1684 sortList: [[cols.length - 1, 1]],
1685 widgets: ['fast-zebra']
1688 $('div#logTable table thead th')
1689 .append('<img class="icon sortableIcon" src="themes/dot.gif" alt="">');
1694 /* Opens the query analyzer dialog */
1695 function openQueryAnalyzer() {
1696 var rowData = $(this).parent().data('query');
1697 var query = rowData.argument || rowData.sql_text;
1699 query = PMA_SQLPrettyPrint(query);
1700 codemirror_editor.setValue(query);
1701 // Codemirror is bugged, it doesn't refresh properly sometimes. Following lines seem to fix that
1702 setTimeout(function() {
1703 codemirror_editor.refresh()
1706 var profilingChart = null;
1709 dlgBtns[PMA_messages['strAnalyzeQuery']] = function() {
1710 loadQueryAnalysis(rowData);
1712 dlgBtns[PMA_messages['strClose']] = function() {
1713 if (profilingChart != null) {
1714 profilingChart.destroy();
1716 $('div#queryAnalyzerDialog div.placeHolder').html('');
1717 codemirror_editor.setValue('');
1718 $(this).dialog("close");
1721 $('div#queryAnalyzerDialog').dialog({
1729 /* Loads and displays the analyzed query data */
1730 function loadQueryAnalysis(rowData) {
1731 var db = rowData.db || '';
1733 $('div#queryAnalyzerDialog div.placeHolder').html(
1734 'Analyzing... ' + '<img class="ajaxIcon" src="' +
1735 pmaThemeImage + 'ajax_clock_small.gif" alt="">');
1737 $.post('server_status.php?' + url_query, {
1739 query_analyzer: true,
1740 query: codemirror_editor.getValue(),
1743 data = $.parseJSON(data);
1747 $('div#queryAnalyzerDialog div.placeHolder').html('<div class="error">' + data.error + '</div>');
1751 // Float sux, I'll use table :(
1752 $('div#queryAnalyzerDialog div.placeHolder')
1753 .html('<table width="100%" border="0"><tr><td class="explain"></td><td class="chart"></td></tr></table>');
1755 var explain = '<b>Explain output</b> ' + explain_docu;
1756 if (data.explain.length > 1) {
1758 for (var i = 0; i < data.explain.length; i++) {
1762 explain += '<a href="#showExplain-' + i + '">' + i + '</a>';
1766 explain += '<p></p>';
1767 for (var i = 0; i < data.explain.length; i++) {
1768 explain += '<div class="explain-' + i + '"' + (i>0? 'style="display:none;"' : '' ) + '>';
1769 $.each(data.explain[i], function(key, value) {
1770 value = (value == null)?'null':value;
1772 if (key == 'type' && value.toLowerCase() == 'all') {
1773 value = '<span class="attention">' + value + '</span>';
1775 if (key == 'Extra') {
1776 value = value.replace(/(using (temporary|filesort))/gi, '<span class="attention">$1</span>');
1778 explain += key + ': ' + value + '<br />';
1780 explain += '</div>';
1783 explain += '<p><b>' + PMA_messages['strAffectedRows'] + '</b> ' + data.affectedRows;
1785 $('div#queryAnalyzerDialog div.placeHolder td.explain').append(explain);
1787 $('div#queryAnalyzerDialog div.placeHolder a[href*="#showExplain"]').click(function() {
1788 var id = $(this).attr('href').split('-')[1];
1789 $(this).parent().find('div[class*="explain"]').hide();
1790 $(this).parent().find('div[class*="explain-' + id + '"]').show();
1793 if (data.profiling) {
1795 var numberTable = '<table class="queryNums"><thead><tr><th>Status</th><th>Time</th></tr></thead><tbody>';
1798 for (var i = 0; i < data.profiling.length; i++) {
1799 duration = parseFloat(data.profiling[i].duration);
1801 chartData.push([data.profiling[i].state, duration]);
1802 totalTime += duration;
1804 numberTable += '<tr><td>' + data.profiling[i].state + ' </td><td> ' + PMA_prettyProfilingNum(duration, 2) + '</td></tr>';
1806 numberTable += '<tr><td><b>Total time:</b></td><td>' + PMA_prettyProfilingNum(totalTime, 2) + '</td></tr>';
1807 numberTable += '</tbody></table>';
1809 $('div#queryAnalyzerDialog div.placeHolder td.chart').append('<b>Profiling results ' + profiling_docu + '</b> (<a href="#showNums">Table</a>, <a href="#showChart">Chart</a>)<br/>' + numberTable + ' <div id="queryProfiling"></div>');
1811 $('div#queryAnalyzerDialog div.placeHolder a[href="#showNums"]').click(function() {
1812 $('div#queryAnalyzerDialog div#queryProfiling').hide();
1813 $('div#queryAnalyzerDialog table.queryNums').show();
1817 $('div#queryAnalyzerDialog div.placeHolder a[href="#showChart"]').click(function() {
1818 $('div#queryAnalyzerDialog div#queryProfiling').show();
1819 $('div#queryAnalyzerDialog table.queryNums').hide();
1823 profilingChart = PMA_createProfilingChart(chartData, {
1825 renderTo: 'queryProfiling'
1835 $('div#queryProfiling').resizable();
1840 /* Saves the monitor to localstorage */
1841 function saveMonitor() {
1844 $.each(runtime.charts, function(key, elem) {
1846 gridCopy[key].nodes = elem.nodes;
1847 gridCopy[key].settings = elem.settings;
1848 gridCopy[key].title = elem.title;
1851 if (window.localStorage) {
1852 window.localStorage['monitorCharts'] = $.toJSON(gridCopy);
1853 window.localStorage['monitorSettings'] = $.toJSON(monitorSettings);
1854 window.localStorage['monitorVersion'] = monitorProtocolVersion;
1857 $('a[href="#clearMonitorConfig"]').show();
1861 // Run the monitor once loaded
1863 $('a[href="#pauseCharts"]').trigger('click');