From b621d2b56ccd19cdb2515fc60a99ac8a31da4abb Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Wed, 5 Dec 2012 21:20:54 +0000 Subject: [PATCH] Split the server staus monitor features into a separate page --- js/messages.php | 11 - js/server_status.js | 429 ------- js/server_status_monitor.js | 189 +++- libraries/Menu.class.php | 10 + libraries/ServerStatusData.class.php | 53 +- libraries/common.inc.php | 4 + server_status.php | 1572 +++++--------------------- server_status_advisor.php | 11 +- server_status_monitor.php | 733 ++++++++++++ server_status_queries.php | 4 +- server_status_variables.php | 18 +- themes/original/css/common.css.php | 4 - themes/pmahomme/css/common.css.php | 4 - 13 files changed, 1205 insertions(+), 1837 deletions(-) create mode 100644 server_status_monitor.php diff --git a/js/messages.php b/js/messages.php index 8c4f2fbb70..b713d6bf20 100644 --- a/js/messages.php +++ b/js/messages.php @@ -73,18 +73,7 @@ $js_messages['strThousandsSeparator'] = __(','); /* l10n: Decimal separator */ $js_messages['strDecimalSeparator'] = __('.'); -$js_messages['strChartKBSent'] = __('KiB sent since last refresh'); -$js_messages['strChartKBReceived'] = __('KiB received since last refresh'); -$js_messages['strChartServerTraffic'] = __('Server traffic (in KiB)'); -$js_messages['strChartConnections'] = __('Connections since last refresh'); -$js_messages['strChartProcesses'] = __('Processes'); $js_messages['strChartConnectionsTitle'] = __('Connections / Processes'); -/* l10n: Questions is the name of a MySQL Status variable */ -$js_messages['strChartIssuedQueries'] = __('Questions since last refresh'); -/* l10n: Questions is the name of a MySQL Status variable */ -$js_messages['strChartIssuedQueriesTitle'] = __('Questions (executed statements by the server)'); - -$js_messages['strChartQueryPie'] = __('Query statistics'); /* server status monitor */ $js_messages['strIncompatibleMonitorConfig'] = __('Local monitor configuration incompatible'); diff --git a/js/server_status.js b/js/server_status.js index 838c288c73..e9fb3263c7 100644 --- a/js/server_status.js +++ b/js/server_status.js @@ -2,15 +2,6 @@ /** * @fileoverview functions used in server status pages * @name Server Status - * - * @requires jQuery - * @requires jQueryUI - * @requires jQueryCookie - * @requires jQueryTablesorter - * @requires jqPlot - * @requires canvg - * @requires js/functions.js - * */ var pma_token, @@ -20,16 +11,6 @@ var pma_token, is_superuser, server_db_isLocal; -/** - * Unbind all event handlers before tearing down a page - */ -AJAX.registerTeardown('server_status.js', function() { - $('a.popupLink').unbind('click'); - $(document).unbind('click'); // Am I sure about this? I guess not... - $('div.buttonlinks select').unbind('click'); - $('div.buttonlinks a.tabRefresh').unbind('click'); -}); - // Add a tablesorter parser to properly handle thousands seperated numbers and SI prefixes AJAX.registerOnload('server_status.js', function() { @@ -41,414 +22,4 @@ AJAX.registerOnload('server_status.js', function() { is_superuser = $js_data_form.find("input[name=is_superuser]").val(); server_db_isLocal = $js_data_form.find("input[name=server_db_isLocal]").val(); - // Show all javascript related parts of the page - $('#serverstatus .jsfeature').show(); - - jQuery.tablesorter.addParser({ - id: "fancyNumber", - is: function(s) { - return /^[0-9]?[0-9,\.]*\s?(k|M|G|T|%)?$/.test(s); - }, - format: function(s) { - var num = jQuery.tablesorter.formatFloat( - s.replace(PMA_messages['strThousandsSeparator'], '') - .replace(PMA_messages['strDecimalSeparator'], '.') - ); - - var factor = 1; - switch (s.charAt(s.length - 1)) { - case '%': factor = -2; break; - // Todo: Complete this list (as well as in the regexp a few lines up) - case 'k': factor = 3; break; - case 'M': factor = 6; break; - case 'G': factor = 9; break; - case 'T': factor = 12; break; - } - - return num * Math.pow(10, factor); - }, - type: "numeric" - }); - - jQuery.tablesorter.addParser({ - id: "withinSpanNumber", - is: function(s) { - return /(.*)?<\/span>/); - return (res && res.length >= 3) ? res[2] : 0; - }, - type: "numeric" - }); - - // faster zebra widget: no row visibility check, faster css class switching, no cssChildRow check - jQuery.tablesorter.addWidget({ - id: "fast-zebra", - format: function (table) { - if (table.config.debug) { - var time = new Date(); - } - $("tr:even", table.tBodies[0]) - .removeClass(table.config.widgetZebra.css[0]) - .addClass(table.config.widgetZebra.css[1]); - $("tr:odd", table.tBodies[0]) - .removeClass(table.config.widgetZebra.css[1]) - .addClass(table.config.widgetZebra.css[0]); - if (table.config.debug) { - $.tablesorter.benchmark("Applying Fast-Zebra widget", time); - } - } - }); - - // Popup behaviour - $('a.popupLink').click( function() { - var $link = $(this); - - $('div.' + $link.attr('href').substr(1)) - .show() - .offset({ top: $link.offset().top + $link.height() + 5, left: $link.offset().left }) - .addClass('openedPopup'); - - return false; - }); - - $(document).click( function(event) { - $('div.openedPopup').each(function() { - var $cnt = $(this); - var pos = $cnt.offset(); - - // Hide if the mouseclick is outside the popupcontent - if (event.pageX < pos.left - || event.pageY < pos.top - || event.pageX > pos.left + $cnt.outerWidth() - || event.pageY > pos.top + $cnt.outerHeight() - ) { - $cnt.hide().removeClass('openedPopup'); - } - }); - }); }); - -AJAX.registerOnload('server_status.js', function() { - // Filters for status variables - var textFilter = null; - var alertFilter = false; - var categoryFilter = ''; - var odd_row = false; - var text = ''; // Holds filter text - var queryPieChart = null; - var monitorLoaded = false; - - /* Chart configuration */ - // Defines what the tabs are currently displaying (realtime or data) - var tabStatus = new Object(); - // Holds the current chart instances for each tab - var tabChart = new Object(); - // Holds current live charts' timeouts - var chart_replot_timers = new Object(); - - /*** Table sort tooltip ***/ - PMA_createqTip($('table.sortable thead th'), PMA_messages['strSortHint']); - - $.ajaxSetup({ - cache: false - }); - - // Add tabs - $('#serverStatusTabs').tabs({ - // Tab persistence - cookie: { name: 'pma_serverStatusTabs', expires: 1 }, - show: function(event, ui) { - // Fixes line break in the menu bar when the page overflows and scrollbar appears - $('#topmenu').menuResizer('resize'); - - // Initialize selected tab - if (!$(ui.tab.hash).data('init-done')) { - initTab($(ui.tab.hash), null); - } - // Load Server status monitor - if (ui.tab.hash == '#statustabs_charting' && ! monitorLoaded) { - $('div#statustabs_charting').append( //PMA_messages['strLoadingMonitor'] + ' ' + - '' - ); - // Delay loading a bit so the tab loads and the user gets to see a ajax loading icon - setTimeout(function() { - var scripts = [ - {name:'jquery/timepicker.js',fire:0}, - {name:'jquery/jquery.json-2.2.js',fire:0}, - {name:'jquery/jquery.sortableTable.js',fire:0}, - {name:'server_status_monitor.js',fire:1} - ]; - AJAX.scriptHandler.load(scripts); - }, 50); - - monitorLoaded = true; - } - } - }); - - // Fixes wrong tab height with floated elements. See also http://bugs.jqueryui.com/ticket/5601 - $(".ui-widget-content:not(.ui-tabs):not(.ui-helper-clearfix)").addClass("ui-helper-clearfix"); - - // Initialize each tab - $('div.ui-tabs-panel').each(function() { - var $tab = $(this); - tabStatus[$tab.attr('id')] = 'static'; - // Initialize tabs after browser catches up with previous changes and displays tabs - setTimeout(function() { - initTab($tab, null); - }, 0.5); - }); - - /** Realtime charting of variables **/ - - function recursiveTimer($tab, type) { - replotLiveChart($tab, type); - chart_replot_timers[$tab.attr('id')] = setTimeout(function() { - recursiveTimer($tab, type) }, ($('.refreshRate :selected', $tab).val() * 1000)); - } - - function getCurrentDataSet($tab, type) { - var ret = null; - var line1 = null; - var line2 = null; - var retval = null; - - $.ajax({ - async: false, - url: 'server_status.php', - type: 'post', - data: { - 'token' : PMA_commonParams.get('token'), - 'server' : PMA_commonParams.get('server'), - 'ajax_request' : true, - 'chart_data' : true, - 'type' : type - }, - dataType: 'json', - success: function(data) { - ret = $.parseJSON(data.message); - } - }); - // get data based on chart type - if(type == 'proc') { - line1 = [ret.x, ret.y_conn - previous_y_line1[$tab.attr('id')]]; - line2 = [ret.x, ret.y_proc]; - previous_y_line1[$tab.attr('id')] = ret.y_conn; - } - else if(type == 'queries') { - line1 = [ret.x, ret.y-previous_y_line1[$tab.attr('id')]]; - previous_y_line1[$tab.attr('id')] = ret.y; - } - else if(type == 'traffic') { - ret.y_sent = ret.y_sent/1024; - ret.y_received = ret.y_received/1024; - line1 = [ret.x, ret.y_sent - previous_y_line1[$tab.attr('id')]]; - line2 = [ret.x, ret.y_received - previous_y_line2[$tab.attr('id')]]; - previous_y_line1[$tab.attr('id')] = ret.y_sent; - previous_y_line2[$tab.attr('id')] = ret.y_received; - } - - retval = [line1, line2]; - return retval; - } - - function getSettings(type) { - - var settings = { - grid: { - drawBorder: false, - shadow: false, - background: 'rgba(0,0,0,0)' - }, - axes: { - xaxis: { - renderer: $.jqplot.DateAxisRenderer, - tickOptions: { - formatString: '%H:%M:%S', - showGridline: false - } - }, - yaxis: { - autoscale:true, - label: PMA_messages['strTotalCount'], - labelRenderer: $.jqplot.CanvasAxisLabelRenderer - } - }, - seriesDefaults: { - rendererOptions: { - smooth: true - } - }, - legend: { - show: true, - location: 's', // compass direction, nw, n, ne, e, se, s, sw, w. - xoffset: 12, // pixel offset of the legend box from the x (or x2) axis. - yoffset: 12 // pixel offset of the legend box from the y (or y2) axis. - } - }; - - var title_message; - var x_legend = new Array(); - if(type == 'proc') { - title_message = PMA_messages['strChartConnectionsTitle']; - x_legend[0] = PMA_messages['strChartConnections']; - x_legend[1] = PMA_messages['strChartProcesses']; - settings.series = [ {label: x_legend[0]}, {label: x_legend[1]} ]; - } - else if(type == 'queries') { - title_message = PMA_messages['strChartIssuedQueriesTitle']; - x_legend[0] = PMA_messages['strChartIssuedQueries']; - settings.series = [ {label: x_legend[0]} ]; - } - else if(type == 'traffic') { - title_message = PMA_messages['strChartServerTraffic']; - x_legend[0] = PMA_messages['strChartKBSent']; - x_legend[1] = PMA_messages['strChartKBReceived']; - settings.series = [ {label: x_legend[0]}, {label: x_legend[1]} ]; - } - settings.title = title_message; - - return settings; - } - - function replotLiveChart($tab, type) { - var data_set = getCurrentDataSet($tab, type); - if(type == 'proc' || type == 'traffic') { - series[$tab.attr('id')][0].push(data_set[0]); - series[$tab.attr('id')][1].push(data_set[1]); - // update data set - tabChart[$tab.attr('id')].series[0].data = series[$tab.attr('id')][0]; - tabChart[$tab.attr('id')].series[1].data = series[$tab.attr('id')][1]; - } - else if(type == 'queries') { - // there is just one line to be plotted - series[$tab.attr('id')][0].push(data_set[0]); - // update data set - tabChart[$tab.attr('id')].series[0].data = series[$tab.attr('id')][0]; - } - tabChart[$tab.attr('id')].resetAxesScale(); - var current_time = new Date().getTime(); - var data_points = $('.dataPointsNumber :selected', $tab).val(); - var refresh_rate = $('.refreshRate :selected', $tab).val() * 1000; - // Min X would be decided based on refresh rate and number of data points - var minX = current_time - (refresh_rate * data_points); - var interval = (((current_time - minX)/data_points) / 1000); - interval = (data_points > 20) ? (((current_time - minX)/20) / 1000) : interval; - // update chart options - tabChart[$tab.attr('id')]['axes']['xaxis']['max'] = current_time; - tabChart[$tab.attr('id')]['axes']['xaxis']['min'] = minX; - tabChart[$tab.attr('id')]['axes']['xaxis']['tickInterval'] = interval + " seconds"; - // replot - tabChart[$tab.attr('id')].replot(); - } - - /* Adjust DOM / Add handlers to the tabs */ - function initTab(tab, data) { - if ($(tab).data('init-done') && !data) { - return; - } - $(tab).data('init-done', true); - switch(tab.attr('id')) { - case 'statustabs_traffic': - if (data != null) { - tab.find('.tabInnerContent').html(data.message); - } - PMA_showHints(); - break; - } - } - - // TODO: tablesorter shouldn't sort already sorted columns - function initTableSorter(tabid) { - var $table, opts; - switch(tabid) { - case 'statustabs_queries': - $table = $('#serverstatusqueriesdetails'); - opts = { - sortList: [[3, 1]], - widgets: ['fast-zebra'], - headers: { - 1: { sorter: 'fancyNumber' }, - 2: { sorter: 'fancyNumber' } - } - }; - break; - case 'statustabs_allvars': - $table = $('#serverstatusvariables'); - opts = { - sortList: [[0, 0]], - widgets: ['fast-zebra'], - headers: { - 1: { sorter: 'withinSpanNumber' } - } - }; - break; - } - $table.tablesorter(opts); - $table.find('tr:first th') - .append(''); - } - - // Provides a nicely formatted and sorted tooltip of each datapoint of the query statistics - function sortedQueriesPointInfo(queries, lastQueries){ - var max, maxIdx, num = 0; - var queryKeys = new Array(); - var queryValues = new Array(); - var sumOther = 0; - var sumTotal = 0; - - // Separate keys and values, then sort them - $.each(queries.pointInfo, function(key, value) { - if (value-lastQueries.pointInfo[key] > 0) { - queryKeys.push(key); - queryValues.push(value-lastQueries.pointInfo[key]); - sumTotal += value-lastQueries.pointInfo[key]; - } - }); - var numQueries = queryKeys.length; - var pointInfo = '' + PMA_messages['strTotal'] + ': ' + sumTotal + '
'; - - while(queryKeys.length > 0) { - max = 0; - for (var i = 0; i < queryKeys.length; i++) { - if (queryValues[i] > max) { - max = queryValues[i]; - maxIdx = i; - } - } - if (numQueries > 8 && num >= 6) { - sumOther += queryValues[maxIdx]; - } else { - pointInfo += queryKeys[maxIdx].substr(4).replace('_', ' ') + ': ' + queryValues[maxIdx] + '
'; - } - - queryKeys.splice(maxIdx, 1); - queryValues.splice(maxIdx, 1); - num++; - } - - if (sumOther>0) { - pointInfo += PMA_messages['strOther'] + ': ' + sumOther; - } - - return pointInfo; - } -}); - - -// Needs to be global as server_status_monitor.js uses it too -function serverResponseError() { - var btns = {}; - btns[PMA_messages['strReloadPage']] = function() { - window.location.reload(); - }; - $('#emptyDialog').dialog({title: PMA_messages['strRefreshFailed']}); - $('#emptyDialog').html( - PMA_getImage('s_attention.png') + - PMA_messages['strInvalidResponseExplanation'] - ); - $('#emptyDialog').dialog({ buttons: btns }); -} diff --git a/js/server_status_monitor.js b/js/server_status_monitor.js index d4799df235..30f5ada5cb 100644 --- a/js/server_status_monitor.js +++ b/js/server_status_monitor.js @@ -1,12 +1,57 @@ /* vim: set expandtab sw=4 ts=4 sts=4: */ -var runtime = {}; +var runtime = {}, + server_time_diff, + server_os, + is_superuser, + server_db_isLocal; +AJAX.registerOnload('server_status_monitor.js', function() { + var $js_data_form = $('#js_data'); + server_time_diff = new Date().getTime() - $js_data_form.find("input[name=server_time]").val(); + server_os = $js_data_form.find("input[name=server_os]").val(); + is_superuser = $js_data_form.find("input[name=is_superuser]").val(); + server_db_isLocal = $js_data_form.find("input[name=server_db_isLocal]").val(); +}); + /** * Unbind all event handlers before tearing down a page */ +AJAX.registerTeardown('server_status_monitor.js', function() { + $('a.popupLink').unbind('click'); + $('body').unbind('click'); +}); +/** + * Popup behaviour + */ +AJAX.registerOnload('server_status_monitor.js', function() { + $('a.popupLink').click( function() { + var $link = $(this); + $('div.' + $link.attr('href').substr(1)) + .show() + .offset({ top: $link.offset().top + $link.height() + 5, left: $link.offset().left }) + .addClass('openedPopup'); + + return false; + }); + $('body').click( function(event) { + $('div.openedPopup').each(function() { + var $cnt = $(this); + var pos = $cnt.offset(); + // Hide if the mouseclick is outside the popupcontent + if (event.pageX < pos.left + || event.pageY < pos.top + || event.pageX > pos.left + $cnt.outerWidth() + || event.pageY > pos.top + $cnt.outerHeight() + ) { + $cnt.hide().removeClass('openedPopup'); + } + }); + }); +}); + AJAX.registerTeardown('server_status_monitor.js', function() { $('a[href="#rearrangeCharts"], a[href="#endChartEditMode"]').unbind('click'); - $('div#statustabs_charting div.popupContent select[name="chartColumns"]').unbind('change'); - $('div#statustabs_charting div.popupContent select[name="gridChartRefresh"]').unbind('change'); + $('div.popupContent select[name="chartColumns"]').unbind('change'); + $(' div.popupContent select[name="gridChartRefresh"]').unbind('change'); $('a[href="#addNewChart"]').unbind('click'); $('a[href="#exportMonitorConfig"]').unbind('click'); $('a[href="#importMonitorConfig"]').unbind('click'); @@ -22,15 +67,13 @@ AJAX.registerTeardown('server_status_monitor.js', function() { $('a[href="#submitClearSeries"]').unbind('click'); $('a[href="#submitAddSeries"]').unbind('click'); // $("input#variableInput").destroy(); - clearTimeout(runtime.refreshTimeout); - runtime.refreshTimeout = null; - $.cookie('pma_serverStatusTabs', null); + destroyGrid(); }); AJAX.registerOnload('server_status_monitor.js', function() { // Show tab links - $('div#statustabs_charting div.tabLinks').show(); - $('div#statustabs_charting img#loadingMonitorIcon').remove(); + $('div.tabLinks').show(); + $('img#loadingMonitorIcon').remove(); // Codemirror is loaded on demand so we might need to initialize it if (! codemirror_editor) { var $elm = $('#sqlquery'); @@ -46,7 +89,8 @@ AJAX.registerOnload('server_status_monitor.js', function() { ); } } - // Timepicker is loaded on demand so we need to initialize datetime fields from the 'load log' dialog + // Timepicker is loaded on demand so we need to initialize + // datetime fields from the 'load log' dialog $('div#logAnalyseDialog .datetimefield').each(function() { PMA_addDatepicker($(this)); }); @@ -58,9 +102,10 @@ AJAX.registerOnload('server_status_monitor.js', function() { var newChart = null; var chartSpacing; - // Whenever the monitor object (runtime.charts) or the settings object (monitorSettings) - // changes in a way incompatible to the previous version, increase this number - // It will reset the users monitor and settings object in his localStorage to the default configuration + // Whenever the monitor object (runtime.charts) or the settings object + // (monitorSettings) changes in a way incompatible to the previous version, + // increase this number. It will reset the users monitor and settings object + // in his localStorage to the default configuration var monitorProtocolVersion = '1.0'; // Runtime parameter of the monitor, is being fully set in initGrid() @@ -75,7 +120,8 @@ AJAX.registerOnload('server_status_monitor.js', function() { chartAI: 0, // To play/pause the monitor redrawCharts: false, - // Object that contains a list of nodes that need to be retrieved from the server for chart updates + // Object that contains a list of nodes that need to be retrieved + // from the server for chart updates dataList: [], // Current max points per chart (needed for auto calculation) gridMaxPoints: 20, @@ -88,7 +134,8 @@ AJAX.registerOnload('server_status_monitor.js', function() { var defaultMonitorSettings = { columns: 3, chartSize: { width: 295, height: 250 }, - // Max points in each chart. Settings it to 'auto' sets gridMaxPoints to (chartwidth - 40) / 12 + // Max points in each chart. Settings it to 'auto' sets + // gridMaxPoints to (chartwidth - 40) / 12 gridMaxPoints: 'auto', /* Refresh rate of all grid charts in ms */ gridRefresh: 5000 @@ -335,14 +382,15 @@ AJAX.registerOnload('server_status_monitor.js', function() { editMode = false; } - // Icon graphics have zIndex 19, 20 and 21. Let's just hope nothing else has the same zIndex + // Icon graphics have zIndex 19, 20 and 21. + // Let's just hope nothing else has the same zIndex $('table#chartGrid div svg').find('*[zIndex=20], *[zIndex=21], *[zIndex=19]').toggle(editMode); $('a[href="#endChartEditMode"]').toggle(editMode); if (editMode) { // Close the settings popup - $('#statustabs_charting .popupContent').hide().removeClass('openedPopup'); + $('div.popupContent').hide().removeClass('openedPopup'); $("#chartGrid").sortableTable({ ignoreRect: { @@ -427,7 +475,7 @@ AJAX.registerOnload('server_status_monitor.js', function() { }); // global settings - $('div#statustabs_charting div.popupContent select[name="chartColumns"]').change(function() { + $('div.popupContent select[name="chartColumns"]').change(function() { monitorSettings.columns = parseInt(this.value); var newSize = chartSize(); @@ -452,7 +500,8 @@ AJAX.registerOnload('server_status_monitor.js', function() { numColumns++; }); - // To little cells in one row => for each cell to little, move all cells backwards by 1 + // To little cells in one row => for each cell to little, + // move all cells backwards by 1 if ($tr.next().length > 0) { var cnt = monitorSettings.columns - $tr.find('td').length; for (var i = 0; i < cnt; i++) { @@ -492,7 +541,7 @@ AJAX.registerOnload('server_status_monitor.js', function() { saveMonitor(); // Save settings }); - $('div#statustabs_charting div.popupContent select[name="gridChartRefresh"]').change(function() { + $('div.popupContent select[name="gridChartRefresh"]').change(function() { monitorSettings.gridRefresh = parseInt(this.value) * 1000; clearTimeout(runtime.refreshTimeout); @@ -522,7 +571,8 @@ AJAX.registerOnload('server_status_monitor.js', function() { if (type == 'preset') { newChart = presetCharts[$('div#addChartDialog select[name="presetCharts"]').prop('value')]; } else { - // If user builds his own chart, it's being set/updated each time he adds a series + // If user builds his own chart, it's being set/updated + // each time he adds a series // So here we only warn if he didn't add a series yet if (! newChart || ! newChart.nodes || newChart.nodes.length == 0) { alert(PMA_messages['strAddOneSeriesWarning']); @@ -585,7 +635,7 @@ AJAX.registerOnload('server_status_monitor.js', function() { $('
', { "class": "disableAjax", method: "post", - action: "file_echo.php?" + url_query + "&filename=1", + action: "file_echo.php?" + PMA_commonParams.get('common_query') + "&filename=1", style: "display:none;" }) .append( @@ -602,7 +652,7 @@ AJAX.registerOnload('server_status_monitor.js', function() { $('a[href="#importMonitorConfig"]').click(function() { $('div#emptyDialog').dialog({title: PMA_messages['strImportDialogTitle']}); - $('div#emptyDialog').html(PMA_messages['strImportDialogMessage'] + ':
' + + $('div#emptyDialog').html(PMA_messages['strImportDialogMessage'] + ':
' + '
'); var dlgBtns = {}; @@ -704,7 +754,7 @@ AJAX.registerOnload('server_status_monitor.js', function() { $.extend(vars, getvars); } - $.get('server_status.php?' + url_query, vars, + $.get('server_status_monitor.php?' + PMA_commonParams.get('common_query'), vars, function(data) { var logVars = $.parseJSON(data.message), icon = PMA_getImage('s_success.png'), msg='', str=''; @@ -1008,30 +1058,6 @@ AJAX.registerOnload('server_status_monitor.js', function() { refreshChartGrid(); } - /* Destroys all monitor related resources */ - function destroyGrid() { - if (runtime.charts) { - $.each(runtime.charts, function(key, value) { - try { - value.chart.destroy(); - } catch(err) {} - }); - } - - try { - runtime.refreshRequest.abort(); - } catch(err) {} - try { - clearTimeout(runtime.refreshTimeout); - } catch(err) {} - - $('table#chartGrid').html(''); - - runtime.charts = null; - runtime.chartAI = 0; - monitorSettings = null; - } - /* Calls destroyGrid() and initGrid(), but before doing so it saves the chart * data from each chart and restores it after the monitor is initialized again */ function rebuildGrid() { @@ -1370,7 +1396,7 @@ AJAX.registerOnload('server_status_monitor.js', function() { /* Called in regular intervalls, this function updates the values of each chart in the grid */ function refreshChartGrid() { /* Send to server */ - runtime.refreshRequest = $.post('server_status.php?' + url_query, { + runtime.refreshRequest = $.post('server_status_monitor.php?' + PMA_commonParams.get('common_query'), { ajax_request: true, chart_data: 1, type: 'chartgrid', @@ -1437,7 +1463,7 @@ AJAX.registerOnload('server_status_monitor.js', function() { // Set y value, if defined if (value != undefined) { - elem.chart.series[j].data.push([chartData.x, value]); + elem.chart.series[j].data.push([chartData.x, value]); if(value > elem.maxYLabel) { elem.maxYLabel = value; } @@ -1472,7 +1498,7 @@ AJAX.registerOnload('server_status_monitor.js', function() { }); } - /* Function to get highest plotted point's y label, to scale the chart, + /* Function to get highest plotted point's y label, to scale the chart, * TODO: make jqplot's autoscale:true work here */ function getMaxYLabel(dataValues) { @@ -1488,7 +1514,8 @@ AJAX.registerOnload('server_status_monitor.js', function() { if (prev == null) { return undefined; } - // cur and prev are datapoint arrays, but containing only 1 element for cpu-linux + // cur and prev are datapoint arrays, but containing + // only 1 element for cpu-linux cur = cur[0]; prev = prev[0]; @@ -1573,7 +1600,7 @@ AJAX.registerOnload('server_status_monitor.js', function() { }); - logRequest = $.get('server_status.php?' + url_query, + logRequest = $.get('server_status_monitor.php?' + PMA_commonParams.get('common_query'), { ajax_request: true, log_data: 1, type: opts.src, @@ -1655,10 +1682,12 @@ AJAX.registerOnload('server_status_monitor.js', function() { } ); - /* Handles the actions performed when the user uses any of the log table filters - * which are the filter by name and grouping with ignoring data in WHERE clauses + /* Handles the actions performed when the user uses any of the + * log table filters which are the filter by name and grouping + * with ignoring data in WHERE clauses * - * @param boolean Should be true when the users enabled or disabled to group queries ignoring data in WHERE clauses + * @param boolean Should be true when the users enabled or disabled + * to group queries ignoring data in WHERE clauses */ function filterQueries(varFilterChange) { var odd_row = false, cell, textFilter; @@ -1699,7 +1728,8 @@ AJAX.registerOnload('server_status_monitor.js', function() { // We just assume the sql text is always in the second last column, and that the total count is right of it $('div#logTable table tbody tr td:nth-child(' + (runtime.logDataCols.length - 1) + ')').each(function() { var $t = $(this); - // If query is a SELECT and user enabled or disabled to group queries ignoring data in where statements, we + // If query is a SELECT and user enabled or disabled to group + // queries ignoring data in where statements, we // need to re-calculate the sums of each row if (varFilterChange && $t.html().match(/^SELECT/i)) { if (noVars) { @@ -1708,7 +1738,8 @@ AJAX.registerOnload('server_status_monitor.js', function() { q = $t.text().replace(equalsFilter, '$1=...$6').trim(); q = q.replace(functionFilter, ' $1(...)'); - // Js does not specify a limit on property name length, so we can abuse it as index :-) + // Js does not specify a limit on property name length, + // so we can abuse it as index :-) if (filteredQueries[q]) { filteredQueries[q] += parseInt($t.next().text()); totalSum += parseInt($t.next().text()); @@ -1740,7 +1771,8 @@ AJAX.registerOnload('server_status_monitor.js', function() { } } - // If not required to be hidden, do we need to hide because of a not matching text filter? + // If not required to be hidden, do we need + // to hide because of a not matching text filter? if (! hide && (textFilter != null && ! textFilter.exec($t.text()))) { hide = true; } @@ -1919,7 +1951,8 @@ AJAX.registerOnload('server_status_monitor.js', function() { if (codemirror_editor) { query = PMA_SQLPrettyPrint(query); codemirror_editor.setValue(query); - // Codemirror is bugged, it doesn't refresh properly sometimes. Following lines seem to fix that + // Codemirror is bugged, it doesn't refresh properly sometimes. + // Following lines seem to fix that setTimeout(function() { codemirror_editor.refresh(); },50); @@ -1965,7 +1998,7 @@ AJAX.registerOnload('server_status_monitor.js', function() { PMA_messages['strAnalyzing'] + ' '); - $.post('server_status.php?' + url_query, { + $.post('server_status_monitor.php?' + PMA_commonParams.get('common_query'), { ajax_request: true, query_analyzer: true, query: codemirror_editor ? codemirror_editor.getValue() : $('#sqlquery').val(), @@ -2105,3 +2138,39 @@ AJAX.registerOnload('server_status_monitor.js', function() { AJAX.registerOnload('server_status_monitor.js', function() { $('a[href="#pauseCharts"]').trigger('click'); }); + +// Needs to be global as server_status_monitor.js uses it too +function serverResponseError() { + var btns = {}; + btns[PMA_messages['strReloadPage']] = function() { + window.location.reload(); + }; + $('#emptyDialog').dialog({title: PMA_messages['strRefreshFailed']}); + $('#emptyDialog').html( + PMA_getImage('s_attention.png') + + PMA_messages['strInvalidResponseExplanation'] + ); + $('#emptyDialog').dialog({ buttons: btns }); +} + +/* Destroys all monitor related resources */ +function destroyGrid() { + if (runtime.charts) { + $.each(runtime.charts, function(key, value) { + try { + value.chart.destroy(); + } catch(err) {} + }); + } + + try { + runtime.refreshRequest.abort(); + } catch(err) {} + try { + clearTimeout(runtime.refreshTimeout); + } catch(err) {} + $('table#chartGrid').html(''); + runtime.charts = null; + runtime.chartAI = 0; + monitorSettings = null; +} diff --git a/libraries/Menu.class.php b/libraries/Menu.class.php index 201c0028cd..d954616f44 100644 --- a/libraries/Menu.class.php +++ b/libraries/Menu.class.php @@ -456,6 +456,16 @@ class PMA_Menu $tabs['status']['icon'] = 's_status.png'; $tabs['status']['link'] = 'server_status.php'; $tabs['status']['text'] = __('Status'); + $tabs['status']['active'] = in_array( + basename($GLOBALS['PMA_PHP_SELF']), + array( + 'server_status.php', + 'server_status_advisor.php', + 'server_status_monitor.php', + 'server_status_queries.php', + 'server_status_variables.php' + ) + ); if ($is_superuser && ! PMA_DRIZZLE) { $tabs['rights']['icon'] = 's_rights.png'; diff --git a/libraries/ServerStatusData.class.php b/libraries/ServerStatusData.class.php index 85d507b05e..fc2cfa0ef8 100644 --- a/libraries/ServerStatusData.class.php +++ b/libraries/ServerStatusData.class.php @@ -308,23 +308,48 @@ class PMA_ServerStatusData { * * @return array */ - public static function getMenuHtml() + public function getMenuHtml() { - $retval = '