/* vim: set expandtab sw=4 ts=4 sts=4: */
var runtime = {};
var server_time_diff;
var server_os;
var is_superuser;
var server_db_isLocal;
var chartSize;
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 () {
$('#emptyDialog').remove();
$('#addChartDialog').remove();
$('a.popupLink').off('click');
$('body').off('click');
});
/**
* Popup behaviour
*/
AJAX.registerOnload('server_status_monitor.js', function () {
$('
')
.attr('id', 'emptyDialog')
.appendTo('#page_content');
$('#addChartDialog')
.appendTo('#page_content');
$('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"]').off('click');
$('div.popupContent select[name="chartColumns"]').off('change');
$('div.popupContent select[name="gridChartRefresh"]').off('change');
$('a[href="#addNewChart"]').off('click');
$('a[href="#exportMonitorConfig"]').off('click');
$('a[href="#importMonitorConfig"]').off('click');
$('a[href="#clearMonitorConfig"]').off('click');
$('a[href="#pauseCharts"]').off('click');
$('a[href="#monitorInstructionsDialog"]').off('click');
$('input[name="chartType"]').off('click');
$('input[name="useDivisor"]').off('click');
$('input[name="useUnit"]').off('click');
$('select[name="varChartList"]').off('click');
$('a[href="#kibDivisor"]').off('click');
$('a[href="#mibDivisor"]').off('click');
$('a[href="#submitClearSeries"]').off('click');
$('a[href="#submitAddSeries"]').off('click');
// $("input#variableInput").destroy();
$('#chartPreset').off('click');
$('#chartStatusVar').off('click');
destroyGrid();
});
AJAX.registerOnload('server_status_monitor.js', function () {
// Show tab links
$('div.tabLinks').show();
$('#loadingMonitorIcon').remove();
// Codemirror is loaded on demand so we might need to initialize it
if (! codemirror_editor) {
var $elm = $('#sqlquery');
if ($elm.length > 0 && typeof CodeMirror !== 'undefined') {
codemirror_editor = CodeMirror.fromTextArea(
$elm[0],
{
lineNumbers: true,
matchBrackets: true,
indentUnit: 4,
mode: 'text/x-mysql',
lineWrapping: true
}
);
}
}
// Timepicker is loaded on demand so we need to initialize
// datetime fields from the 'load log' dialog
$('#logAnalyseDialog').find('.datetimefield').each(function () {
PMA_addDatepicker($(this));
});
/** ** Monitor charting implementation ****/
/* Saves the previous ajax response for differential values */
var oldChartData = null;
// Holds about to be created chart
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
var monitorProtocolVersion = '1.0';
// Runtime parameter of the monitor, is being fully set in initGrid()
runtime = {
// Holds all visible charts in the grid
charts: null,
// Stores the timeout handler so it can be cleared
refreshTimeout: null,
// Stores the GET request to refresh the charts
refreshRequest: null,
// Chart auto increment
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
dataList: [],
// Current max points per chart (needed for auto calculation)
gridMaxPoints: 20,
// displayed time frame
xmin: -1,
xmax: -1
};
var monitorSettings = null;
var defaultMonitorSettings = {
columns: 3,
chartSize: { width: 295, height: 250 },
// 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
};
// Allows drag and drop rearrange and print/edit icons on charts
var editMode = false;
/* List of preconfigured charts that the user may select */
var presetCharts = {
// Query cache efficiency
'qce': {
title: PMA_messages.strQueryCacheEfficiency,
series: [{
label: PMA_messages.strQueryCacheEfficiency
}],
nodes: [{
dataPoints: [{ type: 'statusvar', name: 'Qcache_hits' }, { type: 'statusvar', name: 'Com_select' }],
transformFn: 'qce'
}],
maxYLabel: 0
},
// Query cache usage
'qcu': {
title: PMA_messages.strQueryCacheUsage,
series: [{
label: PMA_messages.strQueryCacheUsed
}],
nodes: [{
dataPoints: [{ type: 'statusvar', name: 'Qcache_free_memory' }, { type: 'servervar', name: 'query_cache_size' }],
transformFn: 'qcu'
}],
maxYLabel: 0
}
};
// time span selection
var selectionTimeDiff = [];
var selectionStartX;
var selectionStartY;
var selectionEndX;
var selectionEndY;
var drawTimeSpan = false;
// chart tooltip
var tooltipBox;
/* Add OS specific system info charts to the preset chart list */
switch (server_os) {
case 'WINNT':
$.extend(presetCharts, {
'cpu': {
title: PMA_messages.strSystemCPUUsage,
series: [{
label: PMA_messages.strAverageLoad
}],
nodes: [{
dataPoints: [{ type: 'cpu', name: 'loadavg' }]
}],
maxYLabel: 100
},
'memory': {
title: PMA_messages.strSystemMemory,
series: [{
label: PMA_messages.strTotalMemory,
fill: true
}, {
dataType: 'memory',
label: PMA_messages.strUsedMemory,
fill: true
}],
nodes: [{ dataPoints: [{ type: 'memory', name: 'MemTotal' }], valueDivisor: 1024 },
{ dataPoints: [{ type: 'memory', name: 'MemUsed' }], valueDivisor: 1024 }
],
maxYLabel: 0
},
'swap': {
title: PMA_messages.strSystemSwap,
series: [{
label: PMA_messages.strTotalSwap,
fill: true
}, {
label: PMA_messages.strUsedSwap,
fill: true
}],
nodes: [{ dataPoints: [{ type: 'memory', name: 'SwapTotal' }] },
{ dataPoints: [{ type: 'memory', name: 'SwapUsed' }] }
],
maxYLabel: 0
}
});
break;
case 'Linux':
$.extend(presetCharts, {
'cpu': {
title: PMA_messages.strSystemCPUUsage,
series: [{
label: PMA_messages.strAverageLoad
}],
nodes: [{ dataPoints: [{ type: 'cpu', name: 'irrelevant' }], transformFn: 'cpu-linux' }],
maxYLabel: 0
},
'memory': {
title: PMA_messages.strSystemMemory,
series: [
{ label: PMA_messages.strBufferedMemory, fill: true },
{ label: PMA_messages.strUsedMemory, fill: true },
{ label: PMA_messages.strCachedMemory, fill: true },
{ label: PMA_messages.strFreeMemory, fill: true }
],
nodes: [
{ dataPoints: [{ type: 'memory', name: 'Buffers' }], valueDivisor: 1024 },
{ dataPoints: [{ type: 'memory', name: 'MemUsed' }], valueDivisor: 1024 },
{ dataPoints: [{ type: 'memory', name: 'Cached' }], valueDivisor: 1024 },
{ dataPoints: [{ type: 'memory', name: 'MemFree' }], valueDivisor: 1024 }
],
maxYLabel: 0
},
'swap': {
title: PMA_messages.strSystemSwap,
series: [
{ label: PMA_messages.strCachedSwap, fill: true },
{ label: PMA_messages.strUsedSwap, fill: true },
{ label: PMA_messages.strFreeSwap, fill: true }
],
nodes: [
{ dataPoints: [{ type: 'memory', name: 'SwapCached' }], valueDivisor: 1024 },
{ dataPoints: [{ type: 'memory', name: 'SwapUsed' }], valueDivisor: 1024 },
{ dataPoints: [{ type: 'memory', name: 'SwapFree' }], valueDivisor: 1024 }
],
maxYLabel: 0
}
});
break;
case 'SunOS':
$.extend(presetCharts, {
'cpu': {
title: PMA_messages.strSystemCPUUsage,
series: [{
label: PMA_messages.strAverageLoad
}],
nodes: [{
dataPoints: [{ type: 'cpu', name: 'loadavg' }]
}],
maxYLabel: 0
},
'memory': {
title: PMA_messages.strSystemMemory,
series: [
{ label: PMA_messages.strUsedMemory, fill: true },
{ label: PMA_messages.strFreeMemory, fill: true }
],
nodes: [
{ dataPoints: [{ type: 'memory', name: 'MemUsed' }], valueDivisor: 1024 },
{ dataPoints: [{ type: 'memory', name: 'MemFree' }], valueDivisor: 1024 }
],
maxYLabel: 0
},
'swap': {
title: PMA_messages.strSystemSwap,
series: [
{ label: PMA_messages.strUsedSwap, fill: true },
{ label: PMA_messages.strFreeSwap, fill: true }
],
nodes: [
{ dataPoints: [{ type: 'memory', name: 'SwapUsed' }], valueDivisor: 1024 },
{ dataPoints: [{ type: 'memory', name: 'SwapFree' }], valueDivisor: 1024 }
],
maxYLabel: 0
}
});
break;
}
// Default setting for the chart grid
var defaultChartGrid = {
'c0': {
title: PMA_messages.strQuestions,
series: [
{ label: PMA_messages.strQuestions }
],
nodes: [
{ dataPoints: [{ type: 'statusvar', name: 'Questions' }], display: 'differential' }
],
maxYLabel: 0
},
'c1': {
title: PMA_messages.strChartConnectionsTitle,
series: [
{ label: PMA_messages.strConnections },
{ label: PMA_messages.strProcesses }
],
nodes: [
{ dataPoints: [{ type: 'statusvar', name: 'Connections' }], display: 'differential' },
{ dataPoints: [{ type: 'proc', name: 'processes' }] }
],
maxYLabel: 0
},
'c2': {
title: PMA_messages.strTraffic,
series: [
{ label: PMA_messages.strBytesSent },
{ label: PMA_messages.strBytesReceived }
],
nodes: [
{ dataPoints: [{ type: 'statusvar', name: 'Bytes_sent' }], display: 'differential', valueDivisor: 1024 },
{ dataPoints: [{ type: 'statusvar', name: 'Bytes_received' }], display: 'differential', valueDivisor: 1024 }
],
maxYLabel: 0
}
};
// Server is localhost => We can add cpu/memory/swap to the default chart
if (server_db_isLocal && typeof presetCharts.cpu !== 'undefined') {
defaultChartGrid.c3 = presetCharts.cpu;
defaultChartGrid.c4 = presetCharts.memory;
defaultChartGrid.c5 = presetCharts.swap;
}
$('a[href="#rearrangeCharts"], a[href="#endChartEditMode"]').click(function (event) {
event.preventDefault();
editMode = !editMode;
if ($(this).attr('href') === '#endChartEditMode') {
editMode = false;
}
$('a[href="#endChartEditMode"]').toggle(editMode);
if (editMode) {
// Close the settings popup
$('div.popupContent').hide().removeClass('openedPopup');
$('#chartGrid').sortableTable({
ignoreRect: {
top: 8,
left: chartSize.width - 63,
width: 54,
height: 24
}
});
} else {
$('#chartGrid').sortableTable('destroy');
}
saveMonitor(); // Save settings
return false;
});
// global settings
$('div.popupContent select[name="chartColumns"]').change(function () {
monitorSettings.columns = parseInt(this.value, 10);
calculateChartSize();
// Empty cells should keep their size so you can drop onto them
$('#chartGrid').find('tr td').css('width', chartSize.width + 'px');
$('#chartGrid').find('.monitorChart').css({
width: chartSize.width + 'px',
height: chartSize.height + 'px'
});
/* Reorder all charts that it fills all column cells */
var numColumns;
var $tr = $('#chartGrid').find('tr:first');
var row = 0;
var tempManageCols = function () {
if (numColumns > monitorSettings.columns) {
if ($tr.next().length === 0) {
$tr.after('
');
}
$tr.next().prepend($(this));
}
numColumns++;
};
var tempAddCol = function () {
if ($(this).next().length !== 0) {
$(this).append($(this).next().find('td:first'));
}
};
while ($tr.length !== 0) {
numColumns = 1;
// To many cells in one row => put into next row
$tr.find('td').each(tempManageCols);
// 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++) {
$tr.append($tr.next().find('td:first'));
$tr.nextAll().each(tempAddCol);
}
}
$tr = $tr.next();
row++;
}
if (monitorSettings.gridMaxPoints === 'auto') {
runtime.gridMaxPoints = Math.round((chartSize.width - 40) / 12);
}
runtime.xmin = new Date().getTime() - server_time_diff - runtime.gridMaxPoints * monitorSettings.gridRefresh;
runtime.xmax = new Date().getTime() - server_time_diff + monitorSettings.gridRefresh;
if (editMode) {
$('#chartGrid').sortableTable('refresh');
}
refreshChartGrid();
saveMonitor(); // Save settings
});
$('div.popupContent select[name="gridChartRefresh"]').change(function () {
monitorSettings.gridRefresh = parseInt(this.value, 10) * 1000;
clearTimeout(runtime.refreshTimeout);
if (runtime.refreshRequest) {
runtime.refreshRequest.abort();
}
runtime.xmin = new Date().getTime() - server_time_diff - runtime.gridMaxPoints * monitorSettings.gridRefresh;
// fixing chart shift towards left on refresh rate change
// runtime.xmax = new Date().getTime() - server_time_diff + monitorSettings.gridRefresh;
runtime.refreshTimeout = setTimeout(refreshChartGrid, monitorSettings.gridRefresh);
saveMonitor(); // Save settings
});
$('a[href="#addNewChart"]').click(function (event) {
event.preventDefault();
var dlgButtons = { };
dlgButtons[PMA_messages.strAddChart] = function () {
var type = $('input[name="chartType"]:checked').val();
if (type === 'preset') {
newChart = presetCharts[$('#addChartDialog').find('select[name="presetCharts"]').prop('value')];
} else {
// 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);
return;
}
}
newChart.title = $('input[name="chartTitle"]').val();
// Add a cloned object to the chart grid
addChart($.extend(true, {}, newChart));
newChart = null;
saveMonitor(); // Save settings
$(this).dialog('close');
};
dlgButtons[PMA_messages.strClose] = function () {
newChart = null;
$('span#clearSeriesLink').hide();
$('#seriesPreview').html('');
$(this).dialog('close');
};
var $presetList = $('#addChartDialog').find('select[name="presetCharts"]');
if ($presetList.html().length === 0) {
$.each(presetCharts, function (key, value) {
$presetList.append('');
});
$presetList.change(function () {
$('input[name="chartTitle"]').val(
$presetList.find(':selected').text()
);
$('#chartPreset').prop('checked', true);
});
$('#chartPreset').click(function () {
$('input[name="chartTitle"]').val(
$presetList.find(':selected').text()
);
});
$('#chartStatusVar').click(function () {
$('input[name="chartTitle"]').val(
$('#chartSeries').find(':selected').text().replace(/_/g, ' ')
);
});
$('#chartSeries').change(function () {
$('input[name="chartTitle"]').val(
$('#chartSeries').find(':selected').text().replace(/_/g, ' ')
);
});
}
$('#addChartDialog').dialog({
width: 'auto',
height: 'auto',
buttons: dlgButtons
});
$('#seriesPreview').html('' + PMA_messages.strNone + '');
return false;
});
$('a[href="#exportMonitorConfig"]').click(function (event) {
event.preventDefault();
var gridCopy = {};
$.each(runtime.charts, function (key, elem) {
gridCopy[key] = {};
gridCopy[key].nodes = elem.nodes;
gridCopy[key].series = elem.series;
gridCopy[key].settings = elem.settings;
gridCopy[key].title = elem.title;
gridCopy[key].maxYLabel = elem.maxYLabel;
});
var exportData = {
monitorCharts: gridCopy,
monitorSettings: monitorSettings
};
var blob = new Blob([JSON.stringify(exportData)], { type: 'application/octet-stream' });
var url = null;
var fileName = 'monitor-config.json';
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, fileName);
} else {
url = URL.createObjectURL(blob);
window.location.href = url;
}
setTimeout(function () {
// For some browsers it is necessary to delay revoking the ObjectURL
if (url !== null) {
window.URL.revokeObjectURL(url);
}
url = undefined;
blob = undefined;
}, 100);
});
$('a[href="#importMonitorConfig"]').click(function (event) {
event.preventDefault();
$('#emptyDialog').dialog({ title: PMA_messages.strImportDialogTitle });
$('#emptyDialog').html(PMA_messages.strImportDialogMessage + ': ');
var dlgBtns = {};
dlgBtns[PMA_messages.strImport] = function () {
var input = $('#emptyDialog').find('#import_file')[0];
var reader = new FileReader();
reader.onerror = function (event) {
alert(PMA_messages.strFailedParsingConfig + '\n' + event.target.error.code);
};
reader.onload = function (e) {
var data = e.target.result;
var json = null;
// Try loading config
try {
json = JSON.parse(data);
} catch (err) {
alert(PMA_messages.strFailedParsingConfig);
$('#emptyDialog').dialog('close');
return;
}
// Basic check, is this a monitor config json?
if (!json || ! json.monitorCharts || ! json.monitorCharts) {
alert(PMA_messages.strFailedParsingConfig);
$('#emptyDialog').dialog('close');
return;
}
// If json ok, try applying config
try {
if (isStorageSupported('localStorage')) {
window.localStorage.monitorCharts = JSON.stringify(json.monitorCharts);
window.localStorage.monitorSettings = JSON.stringify(json.monitorSettings);
}
rebuildGrid();
} catch (err) {
alert(PMA_messages.strFailedBuildingGrid);
// If an exception is thrown, load default again
if (isStorageSupported('localStorage')) {
window.localStorage.removeItem('monitorCharts');
window.localStorage.removeItem('monitorSettings');
}
rebuildGrid();
}
$('#emptyDialog').dialog('close');
};
reader.readAsText(input.files[0]);
};
dlgBtns[PMA_messages.strCancel] = function () {
$(this).dialog('close');
};
$('#emptyDialog').dialog({
width: 'auto',
height: 'auto',
buttons: dlgBtns
});
});
$('a[href="#clearMonitorConfig"]').click(function (event) {
event.preventDefault();
if (isStorageSupported('localStorage')) {
window.localStorage.removeItem('monitorCharts');
window.localStorage.removeItem('monitorSettings');
window.localStorage.removeItem('monitorVersion');
}
$(this).hide();
rebuildGrid();
});
$('a[href="#pauseCharts"]').click(function (event) {
event.preventDefault();
runtime.redrawCharts = ! runtime.redrawCharts;
if (! runtime.redrawCharts) {
$(this).html(PMA_getImage('play') + PMA_messages.strResumeMonitor);
} else {
$(this).html(PMA_getImage('pause') + PMA_messages.strPauseMonitor);
if (! runtime.charts) {
initGrid();
$('a[href="#settingsPopup"]').show();
}
}
return false;
});
$('a[href="#monitorInstructionsDialog"]').click(function (event) {
event.preventDefault();
var $dialog = $('#monitorInstructionsDialog');
$dialog.dialog({
width: '60%',
height: 'auto'
}).find('img.ajaxIcon').show();
var loadLogVars = function (getvars) {
var vars = { ajax_request: true, logging_vars: true };
if (getvars) {
$.extend(vars, getvars);
}
$.post('server_status_monitor.php' + PMA_commonParams.get('common_query'), vars,
function (data) {
var logVars;
if (typeof data !== 'undefined' && data.success === true) {
logVars = data.message;
} else {
return serverResponseError();
}
var icon = PMA_getImage('s_success');
var msg = '';
var str = '';
if (logVars.general_log === 'ON') {
if (logVars.slow_query_log === 'ON') {
msg = PMA_messages.strBothLogOn;
} else {
msg = PMA_messages.strGenLogOn;
}
}
if (msg.length === 0 && logVars.slow_query_log === 'ON') {
msg = PMA_messages.strSlowLogOn;
}
if (msg.length === 0) {
icon = PMA_getImage('s_error');
msg = PMA_messages.strBothLogOff;
}
str = '' + PMA_messages.strCurrentSettings + '
');
chartSpacing = {
width: $('#chartGrid').find('td:nth-child(2)').offset().left -
$('#chartGrid').find('td:nth-child(1)').offset().left,
height: $('#chartGrid').find('tr:nth-child(2) td:nth-child(2)').offset().top -
$('#chartGrid').find('tr:nth-child(1) td:nth-child(1)').offset().top
};
$('#chartGrid').html('');
/* Add all charts - in correct order */
var keys = [];
$.each(runtime.charts, function (key, value) {
keys.push(key);
});
keys.sort();
for (i = 0; i < keys.length; i++) {
addChart(runtime.charts[keys[i]], true);
}
/* Fill in missing cells */
var numCharts = $('#chartGrid').find('.monitorChart').length;
var numMissingCells = (monitorSettings.columns - numCharts % monitorSettings.columns) % monitorSettings.columns;
for (i = 0; i < numMissingCells; i++) {
$('#chartGrid').find('tr:last').append('
');
}
// Empty cells should keep their size so you can drop onto them
calculateChartSize();
$('#chartGrid').find('tr td').css('width', chartSize.width + 'px');
buildRequiredDataList();
refreshChartGrid();
}
/* 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 () {
var oldData = null;
if (runtime.charts) {
oldData = {};
$.each(runtime.charts, function (key, chartObj) {
for (var i = 0, l = chartObj.nodes.length; i < l; i++) {
oldData[chartObj.nodes[i].dataPoint] = [];
for (var j = 0, ll = chartObj.chart.series[i].data.length; j < ll; j++) {
oldData[chartObj.nodes[i].dataPoint].push([chartObj.chart.series[i].data[j].x, chartObj.chart.series[i].data[j].y]);
}
}
});
}
destroyGrid();
initGrid();
}
/* Calculactes the dynamic chart size that depends on the column width */
function calculateChartSize () {
var panelWidth;
if ($('body').height() > $(window).height()) { // has vertical scroll bar
panelWidth = $('#logTable').innerWidth();
} else {
panelWidth = $('#logTable').innerWidth() - 10; // leave some space for vertical scroll bar
}
var wdt = panelWidth;
var windowWidth = $(window).width();
if (windowWidth > 768) {
wdt = (panelWidth - monitorSettings.columns * chartSpacing.width) / monitorSettings.columns;
}
chartSize = {
width: Math.floor(wdt),
height: Math.floor(0.75 * wdt)
};
}
/* Adds a chart to the chart grid */
function addChart (chartObj, initialize) {
var i;
var settings = {
title: escapeHtml(chartObj.title),
grid: {
drawBorder: false,
shadow: false,
background: 'rgba(0,0,0,0)'
},
axes: {
xaxis: {
renderer: $.jqplot.DateAxisRenderer,
tickOptions: {
formatString: '%H:%M:%S',
showGridline: false
},
min: runtime.xmin,
max: runtime.xmax
},
yaxis: {
min: 0,
max: 100,
tickInterval: 20
}
},
seriesDefaults: {
rendererOptions: {
smooth: true
},
showLine: true,
lineWidth: 2,
markerOptions: {
size: 6
}
},
highlighter: {
show: true
}
};
if (settings.title === PMA_messages.strSystemCPUUsage ||
settings.title === PMA_messages.strQueryCacheEfficiency
) {
settings.axes.yaxis.tickOptions = {
formatString: '%d %%'
};
} else if (settings.title === PMA_messages.strSystemMemory ||
settings.title === PMA_messages.strSystemSwap
) {
settings.stackSeries = true;
settings.axes.yaxis.tickOptions = {
formatter: $.jqplot.byteFormatter(2) // MiB
};
} else if (settings.title === PMA_messages.strTraffic) {
settings.axes.yaxis.tickOptions = {
formatter: $.jqplot.byteFormatter(1) // KiB
};
} else if (settings.title === PMA_messages.strQuestions ||
settings.title === PMA_messages.strConnections
) {
settings.axes.yaxis.tickOptions = {
formatter: function (format, val) {
if (Math.abs(val) >= 1000000) {
return $.jqplot.sprintf('%.3g M', val / 1000000);
} else if (Math.abs(val) >= 1000) {
return $.jqplot.sprintf('%.3g k', val / 1000);
} else {
return $.jqplot.sprintf('%d', val);
}
}
};
}
settings.series = chartObj.series;
if ($('#' + 'gridchart' + runtime.chartAI).length === 0) {
var numCharts = $('#chartGrid').find('.monitorChart').length;
if (numCharts === 0 || (numCharts % monitorSettings.columns === 0)) {
$('#chartGrid').append('
');
}
if (!chartSize) {
calculateChartSize();
}
$('#chartGrid').find('tr:last').append(
'
' +
'' +
'
'
);
}
// Set series' data as [0,0], smooth lines won't plot with data array having null values.
// also chart won't plot initially with no data and data comes on refreshChartGrid()
var series = [];
for (i in chartObj.series) {
series.push([[0, 0]]);
}
var tempTooltipContentEditor = function (str, seriesIndex, pointIndex, plot) {
var j;
// TODO: move style to theme CSS
var tooltipHtml = '
';
// x value i.e. time
var timeValue = str.split(',')[0];
var seriesValue;
tooltipHtml += 'Time: ' + timeValue;
tooltipHtml += '';
// Add y values to the tooltip per series
for (j in plot.series) {
// get y value if present
if (plot.series[j].data.length > pointIndex) {
seriesValue = plot.series[j].data[pointIndex][1];
} else {
return;
}
var seriesLabel = plot.series[j].label;
var seriesColor = plot.series[j].color;
// format y value
if (plot.series[0]._yaxis.tickOptions.formatter) {
// using formatter function
seriesValue = plot.series[0]._yaxis.tickOptions.formatter('%s', seriesValue);
} else if (plot.series[0]._yaxis.tickOptions.formatString) {
// using format string
seriesValue = PMA_sprintf(plot.series[0]._yaxis.tickOptions.formatString, seriesValue);
}
tooltipHtml += ' ' +
seriesLabel + ': ' + seriesValue + '';
}
tooltipHtml += '
';
return tooltipHtml;
};
// set Tooltip for each series
for (i in settings.series) {
settings.series[i].highlighter = {
show: true,
tooltipContentEditor: tempTooltipContentEditor
};
}
chartObj.chart = $.jqplot('gridchart' + runtime.chartAI, series, settings);
// remove [0,0] after plotting
for (i in chartObj.chart.series) {
chartObj.chart.series[i].data.shift();
}
var $legend = $('').css('padding', '0.5em');
for (i in chartObj.chart.series) {
$legend.append(
$('').append(
$('