Split the server staus monitor features into a separate page

This commit is contained in:
Rouslan Placella 2012-12-05 21:20:54 +00:00
parent 82a4de0080
commit b621d2b56c
13 changed files with 1205 additions and 1837 deletions

View File

@ -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');

View File

@ -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 class="original"/.test(s);
},
format: function(s, table, html) {
var res = html.innerHTML.match(/<span(\s*style="display:none;"\s*)?\s*class="original">(.*)?<\/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'] + ' ' +
'<img class="ajaxIcon" id="loadingMonitorIcon" src="' +
pmaThemeImage + 'ajax_clock_small.gif" alt="">'
);
// 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('<img class="icon sortableIcon" src="themes/dot.gif" alt="">');
}
// 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 = '<b>' + PMA_messages['strTotal'] + ': ' + sumTotal + '</b><br>';
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] + '<br>';
}
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 });
}

View File

@ -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() {
$('<form />', {
"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'] + ':<br/><form action="file_echo.php?' + url_query + '&import=1" method="post" enctype="multipart/form-data">' +
$('div#emptyDialog').html(PMA_messages['strImportDialogMessage'] + ':<br/><form action="file_echo.php?' + PMA_commonParams.get('common_query') + '&import=1" method="post" enctype="multipart/form-data">' +
'<input type="file" name="file"> <input type="hidden" name="import" value="1"> </form>');
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'] + ' <img class="ajaxIcon" src="' +
pmaThemeImage + 'ajax_clock_small.gif" alt="">');
$.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;
}

View File

@ -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';

View File

@ -308,23 +308,48 @@ class PMA_ServerStatusData {
*
* @return array
*/
public static function getMenuHtml()
public function getMenuHtml()
{
$retval = '<ul id="topmenu2">';
$retval .= '<li>';
$retval .= '<a class="tab" href="server_status_queries.php?' . PMA_generate_common_url() . '">';
$retval .= __('Query statistics') . '</a>';
$retval .= '</li>';
$retval .= '<li>';
$retval .= '<a class="tab" href="server_status_variables.php?' . PMA_generate_common_url() . '">';
$retval .= __('All status variables') . '</a>';
$retval .= '</li>';
$retval .= '<li>';
$retval .= '<a class="tab" href="server_status_advisor.php?' . PMA_generate_common_url() . '">';
$retval .= __('Advisor') . '</a>';
$retval .= '</li>';
$url_params = PMA_generate_common_url();
$items = array(
array(
'name' => __('Server'),
'url' => 'server_status.php'
),
array(
'name' => __('Query statistics'),
'url' => 'server_status_queries.php'
),
array(
'name' => __('All status variables'),
'url' => 'server_status_variables.php'
),
array(
'name' => __('Monitor'),
'url' => 'server_status_monitor.php'
),
array(
'name' => __('Advisor'),
'url' => 'server_status_advisor.php'
)
);
$retval = '<ul id="topmenu2">';
foreach ($items as $item) {
$class = '';
if ($item['url'] === $this->selfUrl) {
$class = ' class="tabactive"';
}
$retval .= '<li>';
$retval .= '<a' . $class;
$retval .= ' href="' . $item['url'] . '?' . $url_params . '">';
$retval .= $item['name'];
$retval .= '</a>';
$retval .= '</li>';
}
$retval .= '</ul>';
$retval .= '<div class="clearfloat"></div>';
return $retval;
}
}

View File

@ -391,6 +391,10 @@ $goto_whitelist = array(
'server_processlist.php',
'server_sql.php',
'server_status.php',
'server_status_advisor.php',
'server_status_monitor.php',
'server_status_queries.php',
'server_status_variables.php',
'server_variables.php',
'sql.php',
'tbl_addfield.php',

File diff suppressed because it is too large Load Diff

View File

@ -9,13 +9,22 @@
require_once 'libraries/common.inc.php';
require_once 'libraries/Advisor.class.php';
require_once 'libraries/ServerStatusData.class.php';
if (PMA_DRIZZLE) {
$server_master_status = false;
$server_slave_status = false;
} else {
include_once 'libraries/replication.inc.php';
include_once 'libraries/replication_gui.lib.php';
}
$ServerStatusData = new PMA_ServerStatusData('server_status_advisor.php');
$response = PMA_Response::getInstance();
$scripts = $response->getHeader()->getScripts();
$scripts->addFile('server_status_advisor.js');
$output = '<div>';
$output .= PMA_ServerStatusData::getMenuHtml();
$output .= $ServerStatusData->getMenuHtml();
$output .= '<a href="#openAdvisorInstructions">';
$output .= PMA_Util::getIcon('b_help.png', __('Instructions'));
$output .= '</a>';

733
server_status_monitor.php Normal file
View File

@ -0,0 +1,733 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
*
*
* @package PhpMyAdmin
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/server_common.inc.php';
require_once 'libraries/ServerStatusData.class.php';
if (PMA_DRIZZLE) {
$server_master_status = false;
$server_slave_status = false;
} else {
include_once 'libraries/replication.inc.php';
include_once 'libraries/replication_gui.lib.php';
}
/**
* Ajax request
*/
if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
// Send with correct charset
header('Content-Type: text/html; charset=UTF-8');
// real-time charting data
if (isset($_REQUEST['chart_data'])) {
switch($_REQUEST['type']) {
case 'chartgrid': // Data for the monitor
$ret = json_decode($_REQUEST['requiredData'], true);
$statusVars = array();
$serverVars = array();
$sysinfo = $cpuload = $memory = 0;
$pName = '';
/* Accumulate all required variables and data */
// For each chart
foreach ($ret as $chart_id => $chartNodes) {
// For each data series
foreach ($chartNodes as $node_id => $nodeDataPoints) {
// For each data point in the series (usually just 1)
foreach ($nodeDataPoints as $point_id => $dataPoint) {
$pName = $dataPoint['name'];
switch ($dataPoint['type']) {
/* We only collect the status and server variables here to
* read them all in one query,
* and only afterwards assign them.
* Also do some white list filtering on the names
*/
case 'servervar':
if (! preg_match('/[^a-zA-Z_]+/', $pName)) {
$serverVars[] = $pName;
}
break;
case 'statusvar':
if (! preg_match('/[^a-zA-Z_]+/', $pName)) {
$statusVars[] = $pName;
}
break;
case 'proc':
$result = PMA_DBI_query('SHOW PROCESSLIST');
$ret[$chart_id][$node_id][$point_id]['value']
= PMA_DBI_num_rows($result);
break;
case 'cpu':
if (!$sysinfo) {
include_once 'libraries/sysinfo.lib.php';
$sysinfo = PMA_getSysInfo();
}
if (!$cpuload) {
$cpuload = $sysinfo->loadavg();
}
if (PMA_getSysInfoOs() == 'Linux') {
$ret[$chart_id][$node_id][$point_id]['idle']
= $cpuload['idle'];
$ret[$chart_id][$node_id][$point_id]['busy']
= $cpuload['busy'];
} else {
$ret[$chart_id][$node_id][$point_id]['value']
= $cpuload['loadavg'];
}
break;
case 'memory':
if (!$sysinfo) {
include_once 'libraries/sysinfo.lib.php';
$sysinfo = PMA_getSysInfo();
}
if (!$memory) {
$memory = $sysinfo->memory();
}
$ret[$chart_id][$node_id][$point_id]['value']
= $memory[$pName];
break;
} /* switch */
} /* foreach */
} /* foreach */
} /* foreach */
// Retrieve all required status variables
if (count($statusVars)) {
$statusVarValues = PMA_DBI_fetch_result(
"SHOW GLOBAL STATUS WHERE Variable_name='"
. implode("' OR Variable_name='", $statusVars) . "'",
0,
1
);
} else {
$statusVarValues = array();
}
// Retrieve all required server variables
if (count($serverVars)) {
$serverVarValues = PMA_DBI_fetch_result(
"SHOW GLOBAL VARIABLES WHERE Variable_name='"
. implode("' OR Variable_name='", $serverVars) . "'",
0,
1
);
} else {
$serverVarValues = array();
}
// ...and now assign them
foreach ($ret as $chart_id => $chartNodes) {
foreach ($chartNodes as $node_id => $nodeDataPoints) {
foreach ($nodeDataPoints as $point_id => $dataPoint) {
switch($dataPoint['type']) {
case 'statusvar':
$ret[$chart_id][$node_id][$point_id]['value']
= $statusVarValues[$dataPoint['name']];
break;
case 'servervar':
$ret[$chart_id][$node_id][$point_id]['value']
= $serverVarValues[$dataPoint['name']];
break;
}
}
}
}
$ret['x'] = microtime(true) * 1000;
exit(json_encode($ret));
}
}
if (isset($_REQUEST['log_data'])) {
if (PMA_MYSQL_INT_VERSION < 50106) {
// Table logging is only available since 5.1.6
exit('""');
}
$start = intval($_REQUEST['time_start']);
$end = intval($_REQUEST['time_end']);
if ($_REQUEST['type'] == 'slow') {
$q = 'SELECT start_time, user_host, ';
$q .= 'Sec_to_Time(Sum(Time_to_Sec(query_time))) as query_time, ';
$q .= 'Sec_to_Time(Sum(Time_to_Sec(lock_time))) as lock_time, ';
$q .= 'SUM(rows_sent) AS rows_sent, ';
$q .= 'SUM(rows_examined) AS rows_examined, db, sql_text, ';
$q .= 'COUNT(sql_text) AS \'#\' ';
$q .= 'FROM `mysql`.`slow_log` ';
$q .= 'WHERE start_time > FROM_UNIXTIME(' . $start . ') ';
$q .= 'AND start_time < FROM_UNIXTIME(' . $end . ') GROUP BY sql_text';
$result = PMA_DBI_try_query($q);
$return = array('rows' => array(), 'sum' => array());
$type = '';
while ($row = PMA_DBI_fetch_assoc($result)) {
$type = strtolower(
substr($row['sql_text'], 0, strpos($row['sql_text'], ' '))
);
switch($type) {
case 'insert':
case 'update':
//Cut off big inserts and updates, but append byte count instead
if (strlen($row['sql_text']) > 220) {
$implode_sql_text = implode(
' ',
PMA_Util::formatByteDown(
strlen($row['sql_text']), 2, 2
)
);
$row['sql_text'] = substr($row['sql_text'], 0, 200)
. '... [' . $implode_sql_text . ']';
}
break;
default:
break;
}
if (! isset($return['sum'][$type])) {
$return['sum'][$type] = 0;
}
$return['sum'][$type] += $row['#'];
$return['rows'][] = $row;
}
$return['sum']['TOTAL'] = array_sum($return['sum']);
$return['numRows'] = count($return['rows']);
PMA_DBI_free_result($result);
exit(json_encode($return));
}
if ($_REQUEST['type'] == 'general') {
$limitTypes = '';
if (isset($_REQUEST['limitTypes']) && $_REQUEST['limitTypes']) {
$limitTypes
= 'AND argument REGEXP \'^(INSERT|SELECT|UPDATE|DELETE)\' ';
}
$q = 'SELECT TIME(event_time) as event_time, user_host, thread_id, ';
$q .= 'server_id, argument, count(argument) as \'#\' ';
$q .= 'FROM `mysql`.`general_log` ';
$q .= 'WHERE command_type=\'Query\' ';
$q .= 'AND event_time > FROM_UNIXTIME(' . $start . ') ';
$q .= 'AND event_time < FROM_UNIXTIME(' . $end . ') ';
$q .= $limitTypes . 'GROUP by argument'; // HAVING count > 1';
$result = PMA_DBI_try_query($q);
$return = array('rows' => array(), 'sum' => array());
$type = '';
$insertTables = array();
$insertTablesFirst = -1;
$i = 0;
$removeVars = isset($_REQUEST['removeVariables'])
&& $_REQUEST['removeVariables'];
while ($row = PMA_DBI_fetch_assoc($result)) {
preg_match('/^(\w+)\s/', $row['argument'], $match);
$type = strtolower($match[1]);
if (! isset($return['sum'][$type])) {
$return['sum'][$type] = 0;
}
$return['sum'][$type] += $row['#'];
switch($type) {
case 'insert':
// Group inserts if selected
if ($removeVars
&& preg_match(
'/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i',
$row['argument'], $matches
)
) {
$insertTables[$matches[2]]++;
if ($insertTables[$matches[2]] > 1) {
$return['rows'][$insertTablesFirst]['#']
= $insertTables[$matches[2]];
// Add a ... to the end of this query to indicate that
// there's been other queries
$temp = $return['rows'][$insertTablesFirst]['argument'];
if ($temp[strlen($temp) - 1] != '.') {
$return['rows'][$insertTablesFirst]['argument']
.= '<br/>...';
}
// Group this value, thus do not add to the result list
continue 2;
} else {
$insertTablesFirst = $i;
$insertTables[$matches[2]] += $row['#'] - 1;
}
}
// No break here
case 'update':
// Cut off big inserts and updates,
// but append byte count therefor
if (strlen($row['argument']) > 220) {
$row['argument'] = substr($row['argument'], 0, 200)
. '... ['
. implode(
' ',
PMA_Util::formatByteDown(
strlen($row['argument'])
),
2,
2
)
. ']';
}
break;
default:
break;
}
$return['rows'][] = $row;
$i++;
}
$return['sum']['TOTAL'] = array_sum($return['sum']);
$return['numRows'] = count($return['rows']);
PMA_DBI_free_result($result);
exit(json_encode($return));
}
}
if (isset($_REQUEST['logging_vars'])) {
if (isset($_REQUEST['varName']) && isset($_REQUEST['varValue'])) {
$value = PMA_Util::sqlAddSlashes($_REQUEST['varValue']);
if (! is_numeric($value)) {
$value="'" . $value . "'";
}
if (! preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName'])) {
PMA_DBI_query(
'SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value
);
}
}
$loggingVars = PMA_DBI_fetch_result(
'SHOW GLOBAL VARIABLES WHERE Variable_name IN'
. ' ("general_log","slow_query_log","long_query_time","log_output")',
0,
1
);
exit(json_encode($loggingVars));
}
if (isset($_REQUEST['query_analyzer'])) {
$return = array();
if (strlen($_REQUEST['database'])) {
PMA_DBI_select_db($_REQUEST['database']);
}
if ($profiling = PMA_Util::profilingSupported()) {
PMA_DBI_query('SET PROFILING=1;');
}
// Do not cache query
$query = preg_replace(
'/^(\s*SELECT)/i',
'\\1 SQL_NO_CACHE',
$_REQUEST['query']
);
$result = PMA_DBI_try_query($query);
$return['affectedRows'] = $GLOBALS['cached_affected_rows'];
$result = PMA_DBI_try_query('EXPLAIN ' . $query);
while ($row = PMA_DBI_fetch_assoc($result)) {
$return['explain'][] = $row;
}
// In case an error happened
$return['error'] = PMA_DBI_getError();
PMA_DBI_free_result($result);
if ($profiling) {
$return['profiling'] = array();
$result = PMA_DBI_try_query(
'SELECT seq,state,duration FROM INFORMATION_SCHEMA.PROFILING'
. ' WHERE QUERY_ID=1 ORDER BY seq'
);
while ($row = PMA_DBI_fetch_assoc($result)) {
$return['profiling'][]= $row;
}
PMA_DBI_free_result($result);
}
exit(json_encode($return));
}
}
/**
* JS Includes
*/
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('server_status_monitor.js');
$scripts->addFile('jquery/jquery.tablesorter.js');
$scripts->addFile('jquery/jquery.json-2.2.js');
$scripts->addFile('jquery/jquery.sortableTable.js');
$scripts->addFile('jquery/timepicker.js');
/* < IE 9 doesn't support canvas natively */
if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) {
$scripts->addFile('jqplot/excanvas.js');
}
$scripts->addFile('canvg/canvg.js');
// for charting
$scripts->addFile('jqplot/jquery.jqplot.js');
$scripts->addFile('jqplot/plugins/jqplot.pieRenderer.js');
$scripts->addFile('jqplot/plugins/jqplot.canvasTextRenderer.js');
$scripts->addFile('jqplot/plugins/jqplot.canvasAxisLabelRenderer.js');
$scripts->addFile('jqplot/plugins/jqplot.dateAxisRenderer.js');
$scripts->addFile('jqplot/plugins/jqplot.highlighter.js');
$scripts->addFile('jqplot/plugins/jqplot.cursor.js');
$scripts->addFile('date.js');
/**
* start output
*/
$ServerStatusData = new PMA_ServerStatusData('server_status_monitor.php');
echo '<div>';
echo $ServerStatusData->getMenuHtml();
echo getPrintMonitorHtml($ServerStatusData);
/**
* Define some data needed on the client side
*/
$input = '<input type="hidden" name="%s" value="%s" />';
echo '<form id="js_data" class="hide">';
echo sprintf($input, 'server_time', microtime(true) * 1000);
echo sprintf($input, 'server_os', PHP_OS);
echo sprintf($input, 'is_superuser', PMA_isSuperuser());
echo sprintf($input, 'server_db_isLocal', $ServerStatusData->db_isLocal);
echo '</form>';
echo '<div id="profiling_docu" class="hide">';
echo PMA_Util::showMySQLDocu('general-thread-states', 'general-thread-states');
echo '</div>';
echo '<div id="explain_docu" class="hide">';
echo PMA_Util::showMySQLDocu('explain-output', 'explain-output');
echo '</div>';
echo '</div>';
exit;
/**
* Prints html with monitor
*
* @return void
*/
function getPrintMonitorHtml($ServerStatusData)
{
$retval = '<div class="tabLinks">';
$retval .= '<a href="#pauseCharts">';
$retval .= PMA_Util::getImage('play.png') . __('Start Monitor');
$retval .= '</a>';
$retval .= '<a href="#settingsPopup" class="popupLink">';
$retval .= PMA_Util::getImage('s_cog.png') . __('Settings');
$retval .= '</a>';
if (! PMA_DRIZZLE) {
$retval .= '<a href="#monitorInstructionsDialog">';
$retval .= PMA_Util::getImage('b_help.png') . __('Instructions/Setup');
}
$retval .= '<a href="#endChartEditMode" style="display:none;">';
$retval .= PMA_Util::getImage('s_okay.png');
$retval .= __('Done rearranging/editing charts');
$retval .= '</a>';
$retval .= '</div>';
$retval .= '<div class="popupContent settingsPopup">';
$retval .= '<a href="#addNewChart">';
$retval .= PMA_Util::getImage('b_chart.png') . __('Add chart');
$retval .= '</a>';
$retval .= '<a href="#rearrangeCharts">';
$retval .= PMA_Util::getImage('b_tblops.png') . __('Rearrange/edit charts');
$retval .= '</a>';
$retval .= '<div class="clearfloat paddingtop"></div>';
$retval .= '<div class="floatleft">';
$retval .= __('Refresh rate') . '<br />';
$retval .= PMA_getRefreshList(
'gridChartRefresh',
5,
Array(2, 3, 4, 5, 10, 20, 40, 60, 120, 300, 600, 1200)
);
$retval .= '<br />';
$retval .= '</div>';
$retval .= '<div class="floatleft">';
$retval .= __('Chart columns');
$retval .= '<br />';
$retval .= '<select name="chartColumns">';
$retval .= '<option>1</option>';
$retval .= '<option>2</option>';
$retval .= '<option>3</option>';
$retval .= '<option>4</option>';
$retval .= '<option>5</option>';
$retval .= '<option>6</option>';
$retval .= '<option>7</option>';
$retval .= '<option>8</option>';
$retval .= '<option>9</option>';
$retval .= '<option>10</option>';
$retval .= '</select>';
$retval .= '</div>';
$retval .= '<div class="clearfloat paddingtop">';
$retval .= '<b>' . __('Chart arrangement') . '</b> ';
$retval .= PMA_Util::showHint(
__(
'The arrangement of the charts is stored to the browsers local storage. '
. 'You may want to export it if you have a complicated set up.'
)
);
$retval .= '<br/>';
$retval .= '<a class="ajax" href="#importMonitorConfig">';
$retval .= __('Import');
$retval .= '</a>';
$retval .= '&nbsp;&nbsp;';
$retval .= '<a class="disableAjax" href="#exportMonitorConfig">';
$retval .= __('Export');
$retval .= '</a>';
$retval .= '&nbsp;&nbsp;';
$retval .= '<a href="#clearMonitorConfig">';
$retval .= __('Reset to default');
$retval .= '</a>';
$retval .= '</div>';
$retval .= '</div>';
$retval .= '<div id="monitorInstructionsDialog" title="';
$retval .= __('Monitor Instructions') . '" style="display:none;">';
$retval .= __(
'The phpMyAdmin Monitor can assist you in optimizing the server'
. ' configuration and track down time intensive 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%'
);
if (PMA_MYSQL_INT_VERSION < 50106) {
$retval .= '<p>';
$retval .= PMA_Util::getImage('s_attention.png');
$retval .= __(
'Unfortunately your Database server does not support logging to table,'
. ' which is a requirement for analyzing the database logs with'
. ' phpMyAdmin. Logging to table is supported by MySQL 5.1.6 and'
. ' onwards. You may still use the server charting features however.'
);
$retval .= '</p>';
} else {
$retval .= '<p></p>';
$retval .= '<img class="ajaxIcon" src="';
$retval .= $GLOBALS['pmaThemeImage'] . 'ajax_clock_small.gif"';
$retval .= ' alt="' . __('Loading') . '" />';
$retval .= '<div class="ajaxContent"></div>';
$retval .= '<div class="monitorUse" style="display:none;">';
$retval .= '<p></p>';
$retval .= '<strong>';
$retval .= __('Using the monitor:');
$retval .= '</strong><p>';
$retval .= __(
'Your browser will refresh all displayed charts in a regular interval.'
. ' You may add charts and change the refresh rate under \'Settings\','
. ' or remove any chart using the cog icon on each respective chart.'
);
$retval .= '</p><p>';
$retval .= __(
'To display queries from the logs, select the relevant time span on any'
. ' chart by holding down the left mouse button and panning over the'
. ' chart. Once confirmed, this will load a table of grouped queries,'
. ' there you may click on any occuring SELECT statements to further'
. ' analyze them.');
$retval .= '</p>';
$retval .= '<p>';
$retval .= PMA_Util::getImage('s_attention.png');
$retval .= '<strong>';
$retval .= __('Please note:');
$retval .= '</strong><br />';
$retval .= __(
'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.'
);
$retval .= '</p>';
$retval .= '</div>';
}
$retval .= '</div>';
$retval .= '<div id="addChartDialog" title="' . __('Add chart') . '" style="display:none;">';
$retval .= '<div id="tabGridVariables">';
$retval .= '<p><input type="text" name="chartTitle" value="' . __('Chart Title') . '" /></p>';
$retval .= '<input type="radio" name="chartType" value="preset" id="chartPreset" />';
$retval .= '<label for="chartPreset">' . __('Preset chart') . '</label>';
$retval .= '<select name="presetCharts"></select><br/>';
$retval .= '<input type="radio" name="chartType" value="variable" id="chartStatusVar" checked="checked" />';
$retval .= '<label for="chartStatusVar">' . __('Status variable(s)') . '</label><br/>';
$retval .= '<div id="chartVariableSettings">';
$retval .= '<label for="chartSeries">' . __('Select series:') . '</label><br />';
$retval .= '<select id="chartSeries" name="varChartList" size="1">';
$retval .= '<option>' . __('Commonly monitored') . '</option>';
$retval .= '<option>Processes</option>';
$retval .= '<option>Questions</option>';
$retval .= '<option>Connections</option>';
$retval .= '<option>Bytes_sent</option>';
$retval .= '<option>Bytes_received</option>';
$retval .= '<option>Threads_connected</option>';
$retval .= '<option>Created_tmp_disk_tables</option>';
$retval .= '<option>Handler_read_first</option>';
$retval .= '<option>Innodb_buffer_pool_wait_free</option>';
$retval .= '<option>Key_reads</option>';
$retval .= '<option>Open_tables</option>';
$retval .= '<option>Select_full_join</option>';
$retval .= '<option>Slow_queries</option>';
$retval .= '</select><br />';
$retval .= '<label for="variableInput">';
$retval .= __('or type variable name:');
$retval .= ' </label>';
$retval .= '<input type="text" name="variableInput" id="variableInput" />';
$retval .= '<p></p>';
$retval .= '<input type="checkbox" name="differentialValue"';
$retval .= ' id="differentialValue" value="differential" checked="checked" />';
$retval .= '<label for="differentialValue">';
$retval .= __('Display as differential value');
$retval .= '</label><br />';
$retval .= '<input type="checkbox" id="useDivisor" name="useDivisor" value="1" />';
$retval .= '<label for="useDivisor">' . __('Apply a divisor') . '</label>';
$retval .= '<span class="divisorInput" style="display:none;">';
$retval .= '<input type="text" name="valueDivisor" size="4" value="1" />';
$retval .= '(<a href="#kibDivisor">' . __('KiB') . '</a>, <a href="#mibDivisor">' . __('MiB') . '</a>)';
$retval .= '</span><br />';
$retval .= '<input type="checkbox" id="useUnit" name="useUnit" value="1" />';
$retval .= '<label for="useUnit">' . __('Append unit to data values') . '</label>';
$retval .= '<span class="unitInput" style="display:none;">';
$retval .= '<input type="text" name="valueUnit" size="4" value="" />';
$retval .= '</span>';
$retval .= '<p>';
$retval .= '<a href="#submitAddSeries"><b>' . __('Add this series') . '</b></a>';
$retval .= '<span id="clearSeriesLink" style="display:none;">';
$retval .= ' | <a href="#submitClearSeries">' . __('Clear series') . '</a>';
$retval .= '</span>';
$retval .= '</p>';
$retval .= __('Series in Chart:');
$retval .= '<br/>';
$retval .= '<span id="seriesPreview">';
$retval .= '<i>' . __('None') . '</i>';
$retval .= '</span>';
$retval .= '</div>';
$retval .= '</div>';
$retval .= '</div>';
$retval .= '<div id="emptyDialog" title="Dialog" style="display:none;"></div>';
if (! PMA_DRIZZLE) {
$retval .= '<div id="logAnalyseDialog" title="';
$retval .= __('Log statistics') . '" style="display:none;">';
$retval .= '<p>' . __('Selected time range:');
$retval .= '<input type="text" name="dateStart" class="datetimefield" value="" /> - ';
$retval .= '<input type="text" name="dateEnd" class="datetimefield" value="" />';
$retval .= '</p>';
$retval .= '<input type="checkbox" id="limitTypes" value="1" checked="checked" />';
$retval .= '<label for="limitTypes">';
$retval .= __('Only retrieve SELECT,INSERT,UPDATE and DELETE Statements');
$retval .= '</label>';
$retval .= '<br/>';
$retval .= '<input type="checkbox" id="removeVariables" value="1" checked="checked" />';
$retval .= '<label for="removeVariables">';
$retval .= __('Remove variable data in INSERT statements for better grouping');
$retval .= '</label>';
$retval .= '<p>';
$retval .= __('Choose from which log you want the statistics to be generated from.');
$retval .= '</p>';
$retval .= '<p>';
$retval .= __('Results are grouped by query text.');
$retval .= '</p>';
$retval .= '</div>';
$retval .= '<div id="queryAnalyzerDialog" title="';
$retval .= __('Query analyzer') . '" style="display:none;">';
$retval .= '<textarea id="sqlquery"> </textarea>';
$retval .= '<p></p>';
$retval .= '<div class="placeHolder"></div>';
$retval .= '</div>';
}
$retval .= '<table class="clearfloat" id="chartGrid"></table>';
$retval .= '<div id="logTable">';
$retval .= '<br/>';
$retval .= '</div>';
$retval .= '<script type="text/javascript">';
$retval .= 'variableNames = [ ';
$i=0;
foreach ($ServerStatusData->status as $name=>$value) {
if (is_numeric($value)) {
if ($i++ > 0) {
$retval .= ", ";
}
$retval .= "'" . $name . "'";
}
}
$retval .= '];';
$retval .= '</script>';
return $retval;
}
/**
* Builds a <select> list for refresh rates
*
* @param string $name Name of select
* @param int $defaultRate Currently chosen rate
* @param array $refreshRates List of refresh rates
*
* @return HTML code with select
*/
function PMA_getRefreshList($name,
$defaultRate = 5,
$refreshRates = Array(1, 2, 5, 10, 20, 40, 60, 120, 300, 600)
) {
$return = '<select name="' . $name . '" id="id_' . $name
. '" class="refreshRate">';
foreach ($refreshRates as $rate) {
$selected = ($rate == $defaultRate)?' selected="selected"':'';
$return .= '<option value="' . $rate . '"' . $selected . '>';
if ($rate < 60) {
$return .= sprintf(_ngettext('%d second', '%d seconds', $rate), $rate);
} else {
$rate = $rate / 60;
$return .= sprintf(_ngettext('%d minute', '%d minutes', $rate), $rate);
}
$return .= '</option>';
}
$return .= '</select>';
return $return;
}
?>

View File

@ -16,7 +16,7 @@ if (PMA_DRIZZLE) {
include_once 'libraries/replication_gui.lib.php';
}
$ServerStatusData = new PMA_ServerStatusData('server_status_qyuries.php');
$ServerStatusData = new PMA_ServerStatusData('server_status_queries.php');
$response = PMA_Response::getInstance();
$header = $response->getHeader();
@ -38,7 +38,7 @@ $scripts->addFile('jqplot/plugins/jqplot.cursor.js');
// Add the html content to the response
$response->addHTML('<div>');
$response->addHTML(PMA_ServerStatusData::getMenuHtml());
$response->addHTML($ServerStatusData->getMenuHtml());
$response->addHTML(getQueryStatisticsHtml($ServerStatusData));
$response->addHTML('</div>');
exit;

View File

@ -16,6 +16,22 @@ if (PMA_DRIZZLE) {
include_once 'libraries/replication_gui.lib.php';
}
/**
* flush status variables if requested
*/
if (isset($_REQUEST['flush'])) {
$_flush_commands = array(
'STATUS',
'TABLES',
'QUERY CACHE',
);
if (in_array($_REQUEST['flush'], $_flush_commands)) {
PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
}
unset($_flush_commands);
}
$ServerStatusData = new PMA_ServerStatusData('server_status_variables.php');
$response = PMA_Response::getInstance();
@ -24,7 +40,7 @@ $scripts = $header->getScripts();
$scripts->addFile('server_status_variables.js');
$response->addHTML('<div>');
$response->addHTML(PMA_ServerStatusData::getMenuHtml());
$response->addHTML($ServerStatusData->getMenuHtml());
$response->addHTML(getFilterHtml($ServerStatusData));
$response->addHTML(getLinkSuggestionsHtml($ServerStatusData));
$response->addHTML(getVariablesTableHtml($ServerStatusData));

View File

@ -1017,10 +1017,6 @@ img.sortableIcon {
white-space: nowrap;
}
.jsfeature {
display: none; /* Made visible with js */
}
/* Also used for the variables page */
fieldset#tableFilter {
margin-bottom:1em;

View File

@ -1262,10 +1262,6 @@ img.sortableIcon {
white-space: nowrap;
}
.jsfeature {
display: none; /* Made visible with js */
}
/* Also used for the variables page */
fieldset#tableFilter {
margin-bottom: 1em;