1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * @fileoverview functions used in server status pages
8 * @requires jQueryCookie
9 * @requires jQueryTablesorter
10 * @requires Highcharts
12 * @requires js/functions.js
16 // Add a tablesorter parser to properly handle thousands seperated numbers and SI prefixes
18 jQuery
.tablesorter
.addParser({
21 return /^[0-9]?[0-9,\.]*\s?(k|M|G|T|%)?$/.test(s
);
24 var num
= jQuery
.tablesorter
.formatFloat(
25 s
.replace(PMA_messages
['strThousandsSeperator'],'')
26 .replace(PMA_messages
['strDecimalSeperator'],'.')
30 switch (s
.charAt(s
.length
- 1)) {
31 case '%': factor
= -2; break;
32 // Todo: Complete this list (as well as in the regexp a few lines up)
33 case 'k': factor
= 3; break;
34 case 'M': factor
= 6; break;
35 case 'G': factor
= 9; break;
36 case 'T': factor
= 12; break;
39 return num
* Math
.pow(10,factor
);
46 $('a[rel="popupLink"]').click( function() {
49 $('.' + $link
.attr('href').substr(1))
51 .offset({ top
: $link
.offset().top
+ $link
.height() + 5, left
: $link
.offset().left
})
52 .addClass('openedPopup');
57 $(document
).click( function(event
) {
58 $('.openedPopup').each(function() {
60 var pos
= $(this).offset();
62 // Hide if the mouseclick is outside the popupcontent
63 if(event
.pageX
< pos
.left
|| event
.pageY
< pos
.top
|| event
.pageX
> pos
.left
+ $cnt
.outerWidth() || event
.pageY
> pos
.top
+ $cnt
.outerHeight())
64 $cnt
.hide().removeClass('openedPopup');
70 // Filters for status variables
72 var alertFilter
= false;
73 var categoryFilter
='';
75 var text
=''; // Holds filter text
76 var queryPieChart
= null;
78 /* Chart configuration */
79 // Defines what the tabs are currently displaying (realtime or data)
80 var tabStatus
= new Object();
81 // Holds the current chart instances for each tab
82 var tabChart
= new Object();
85 /*** Table sort tooltip ***/
87 var $tableSortHint
= $('<div class="dHint" style="display:none;">' + 'Click to sort' + '</div>');
88 $('body').append($tableSortHint
);
90 $('table.sortable thead th').live('mouseover mouseout',function(e
) {
91 if(e
.type
== 'mouseover') {
103 .hide(300,function() {
104 $(this).data('shown',false);
109 $(document
).mousemove(function(e
) {
110 if($tableSortHint
.data('shown') == true)
118 // Tell highcarts not to use UTC dates (global setting)
119 Highcharts
.setOptions({
130 $('#serverStatusTabs').tabs({
132 cookie
: { name
: 'pma_serverStatusTabs', expires
: 1 },
133 // Fixes line break in the menu bar when the page overflows and scrollbar appears
134 show: function() { menuResize(); }
137 // Fixes wrong tab height with floated elements. See also http://bugs.jqueryui.com/ticket/5601
138 $(".ui-widget-content:not(.ui-tabs):not(.ui-helper-clearfix)").addClass("ui-helper-clearfix");
140 // Initialize each tab
141 $('div.ui-tabs-panel').each(function() {
142 initTab($(this),null);
143 tabStatus
[$(this).attr('id')] = 'static';
146 // Display button links
147 $('div.buttonlinks').show();
149 // Handles refresh rate changing
150 $('.buttonlinks select').change(function() {
151 var chart
=tabChart
[$(this).parents('div.ui-tabs-panel').attr('id')];
153 // Clear current timeout and set timeout with the new refresh rate
154 clearTimeout(chart_activeTimeouts
[chart
.options
.chart
.renderTo
]);
155 if(chart
.options
.realtime
.postRequest
)
156 chart
.options
.realtime
.postRequest
.abort();
158 chart
.options
.realtime
.refreshRate
= 1000*parseInt(this.value
);
160 chart
.xAxis
[0].setExtremes(
161 new Date().getTime() - server_time_diff
- chart
.options
.realtime
.numMaxPoints
* chart
.options
.realtime
.refreshRate
,
162 new Date().getTime() - server_time_diff
,
166 chart_activeTimeouts
[chart
.options
.chart
.renderTo
] = setTimeout(
167 chart
.options
.realtime
.timeoutCallBack
,
168 chart
.options
.realtime
.refreshRate
172 // Ajax refresh of variables (always the first element in each tab)
173 $('.buttonlinks a.tabRefresh').click(function() {
174 // ui-tabs-panel class is added by the jquery tabs feature
175 var tab
=$(this).parents('div.ui-tabs-panel');
178 // Show ajax load icon
179 $(this).find('img').show();
181 $.get($(this).attr('href'),{ajax_request
:1},function(data
) {
182 $(that
).find('img').hide();
186 tabStatus
[tab
.attr('id')]='data';
192 /** Realtime charting of variables **/
194 // Live traffic charting
195 $('.buttonlinks a.livetrafficLink').click(function() {
196 // ui-tabs-panel class is added by the jquery tabs feature
197 var $tab
=$(this).parents('div.ui-tabs-panel');
198 var tabstat
= tabStatus
[$tab
.attr('id')];
200 if(tabstat
=='static' || tabstat
=='liveconnections') {
203 { name
: PMA_messages
['strChartKBSent'], data
: [] },
204 { name
: PMA_messages
['strChartKBReceived'], data
: [] }
206 title
: { text
: PMA_messages
['strChartServerTraffic'] },
207 realtime
: { url
:'server_status.php?' + url_query
,
209 callback: function(chartObj
, curVal
, lastVal
, numLoadedPoints
) {
210 if(lastVal
==null) return;
211 chartObj
.series
[0].addPoint(
212 { x
: curVal
.x
, y
: (curVal
.y_sent
- lastVal
.y_sent
) / 1024 },
214 numLoadedPoints
>= chartObj
.options
.realtime
.numMaxPoints
216 chartObj
.series
[1].addPoint(
217 { x
: curVal
.x
, y
: (curVal
.y_received
- lastVal
.y_received
) / 1024 },
219 numLoadedPoints
>= chartObj
.options
.realtime
.numMaxPoints
222 error: function() { serverResponseError(); }
226 setupLiveChart($tab
,this,settings
);
227 if(tabstat
== 'liveconnections')
228 $tab
.find('.buttonlinks a.liveconnectionsLink').html(PMA_messages
['strLiveConnChart']);
229 tabStatus
[$tab
.attr('id')]='livetraffic';
231 $(this).html(PMA_messages
['strLiveTrafficChart']);
232 setupLiveChart($tab
,this,null);
238 // Live connection/process charting
239 $('.buttonlinks a.liveconnectionsLink').click(function() {
240 var $tab
=$(this).parents('div.ui-tabs-panel');
241 var tabstat
= tabStatus
[$tab
.attr('id')];
243 if(tabstat
== 'static' || tabstat
== 'livetraffic') {
246 { name
: PMA_messages
['strChartConnections'], data
: [] },
247 { name
: PMA_messages
['strChartProcesses'], data
: [] }
249 title
: { text
: PMA_messages
['strChartConnectionsTitle'] },
250 realtime
: { url
:'server_status.php?'+url_query
,
252 callback: function(chartObj
, curVal
, lastVal
,numLoadedPoints
) {
253 if(lastVal
==null) return;
254 chartObj
.series
[0].addPoint(
255 { x
: curVal
.x
, y
: curVal
.y_conn
- lastVal
.y_conn
},
257 numLoadedPoints
>= chartObj
.options
.realtime
.numMaxPoints
259 chartObj
.series
[1].addPoint(
260 { x
: curVal
.x
, y
: curVal
.y_proc
},
262 numLoadedPoints
>= chartObj
.options
.realtime
.numMaxPoints
265 error: function() { serverResponseError(); }
269 setupLiveChart($tab
,this,settings
);
270 if(tabstat
== 'livetraffic')
271 $tab
.find('.buttonlinks a.livetrafficLink').html(PMA_messages
['strLiveTrafficChart']);
272 tabStatus
[$tab
.attr('id')]='liveconnections';
274 $(this).html(PMA_messages
['strLiveConnChart']);
275 setupLiveChart($tab
,this,null);
281 // Live query statistics
282 $('.buttonlinks a.livequeriesLink').click(function() {
283 var $tab
= $(this).parents('div.ui-tabs-panel');
286 if(tabStatus
[$tab
.attr('id')] == 'static') {
288 series
: [ { name
: PMA_messages
['strChartIssuedQueries'], data
: [] } ],
289 title
: { text
: PMA_messages
['strChartIssuedQueriesTitle'] },
290 tooltip
: { formatter:function() { return this.point
.name
; } },
291 realtime
: { url
:'server_status.php?'+url_query
,
293 callback: function(chartObj
, curVal
, lastVal
,numLoadedPoints
) {
294 if(lastVal
== null) return;
295 chartObj
.series
[0].addPoint(
296 { x
: curVal
.x
, y
: curVal
.y
- lastVal
.y
, name
: sortedQueriesPointInfo(curVal
,lastVal
) },
298 numLoadedPoints
>= chartObj
.options
.realtime
.numMaxPoints
301 error: function() { serverResponseError(); }
305 $(this).html(PMA_messages
['strLiveQueryChart']);
308 setupLiveChart($tab
,this,settings
);
309 tabStatus
[$tab
.attr('id')] = 'livequeries';
313 function setupLiveChart($tab
,link
,settings
) {
314 if(settings
!= null) {
315 // Loading a chart with existing chart => remove old chart first
316 if(tabStatus
[$tab
.attr('id')] != 'static') {
317 clearTimeout(chart_activeTimeouts
[$tab
.attr('id') + "_chart_cnt"]);
318 chart_activeTimeouts
[$tab
.attr('id')+"_chart_cnt"] = null;
319 tabChart
[$tab
.attr('id')].destroy();
320 // Also reset the select list
321 $tab
.find('.buttonlinks select').get(0).selectedIndex
= 2;
324 if(! settings
.chart
) settings
.chart
= {};
325 settings
.chart
.renderTo
= $tab
.attr('id') + "_chart_cnt";
327 $tab
.find('.tabInnerContent')
329 .after('<div class="liveChart" id="' + $tab
.attr('id') + '_chart_cnt"></div>');
330 tabChart
[$tab
.attr('id')] = PMA_createChart(settings
);
331 $(link
).html(PMA_messages
['strStaticData']);
332 $tab
.find('.buttonlinks a.tabRefresh').hide();
333 $tab
.find('.buttonlinks .refreshList').show();
335 clearTimeout(chart_activeTimeouts
[$tab
.attr('id') + "_chart_cnt"]);
336 chart_activeTimeouts
[$tab
.attr('id') + "_chart_cnt"]=null;
337 $tab
.find('.tabInnerContent').show();
338 $tab
.find('div#'+$tab
.attr('id') + '_chart_cnt').remove();
339 tabStatus
[$tab
.attr('id')]='static';
340 tabChart
[$tab
.attr('id')].destroy();
341 $tab
.find('.buttonlinks a.tabRefresh').show();
342 $tab
.find('.buttonlinks select').get(0).selectedIndex
=2;
343 $tab
.find('.buttonlinks .refreshList').hide();
347 /* 3 Filtering functions */
348 $('#filterAlert').change(function() {
349 alertFilter
= this.checked
;
353 $('#filterText').keyup(function(e
) {
354 word
= $(this).val().replace('_',' ');
356 if(word
.length
== 0) textFilter
= null;
357 else textFilter
= new RegExp("(^|_)" + word
,'i');
364 $('#filterCategory').change(function() {
365 categoryFilter
= $(this).val();
369 /* Adjust DOM / Add handlers to the tabs */
370 function initTab(tab
,data
) {
371 switch(tab
.attr('id')) {
372 case 'statustabs_traffic':
373 if(data
!= null) tab
.find('.tabInnerContent').html(data
);
374 PMA_convertFootnotesToTooltips();
376 case 'statustabs_queries':
378 queryPieChart
.destroy();
379 tab
.find('.tabInnerContent').html(data
);
382 // Build query statistics chart
383 var cdata
= new Array();
384 $.each(jQuery
.parseJSON($('#serverstatusquerieschart span').html()),function(key
,value
) {
385 cdata
.push([key
,parseInt(value
)]);
388 queryPieChart
= PMA_createChart({
390 renderTo
: 'serverstatusquerieschart'
398 name
: PMA_messages
['strChartQueryPie'],
403 allowPointSelect
: true,
407 formatter: function() {
408 return '<b>'+ this.point
.name
+'</b><br/> ' + Highcharts
.numberFormat(this.percentage
, 2) + ' %';
414 formatter: function() {
415 return '<b>' + this.point
.name
+ '</b><br/>' + Highcharts
.numberFormat(this.y
, 2) + '<br/>(' + Highcharts
.numberFormat(this.percentage
, 2) + ' %)';
421 case 'statustabs_allvars':
423 tab
.find('.tabInnerContent').html(data
);
429 initTableSorter(tab
.attr('id'));
432 function initTableSorter(tabid
) {
434 case 'statustabs_queries':
435 $('#serverstatusqueriesdetails').tablesorter({
439 1: { sorter
: 'fancyNumber' },
440 2: { sorter
: 'fancyNumber' }
444 $('#serverstatusqueriesdetails tr:first th')
445 .append('<img class="icon sortableIcon" src="themes/dot.gif" alt="">');
449 case 'statustabs_allvars':
450 $('#serverstatusvariables').tablesorter({
454 1: { sorter
: 'fancyNumber' }
458 $('#serverstatusvariables tr:first th')
459 .append('<img class="icon sortableIcon" src="themes/dot.gif" alt="">');
465 /* Filters the status variables by name/category/alert in the variables tab */
466 function filterVariables() {
467 var useful_links
= 0;
470 if(categoryFilter
.length
> 0) section
= categoryFilter
;
472 if(section
.length
> 1) {
473 $('#linkSuggestions span').each(function() {
474 if($(this).attr('class').indexOf('status_'+section
) != -1) {
476 $(this).css('display','');
478 $(this).css('display','none');
486 $('#linkSuggestions').css('display','');
487 else $('#linkSuggestions').css('display','none');
490 $('#serverstatusvariables th.name').each(function() {
491 if((textFilter
== null || textFilter
.exec($(this).text()))
492 && (! alertFilter
|| $(this).next().find('span.attention').length
>0)
493 && (categoryFilter
.length
== 0 || $(this).parent().hasClass('s_'+categoryFilter
))) {
495 $(this).parent().css('display','');
497 $(this).parent().addClass('odd');
498 $(this).parent().removeClass('even');
500 $(this).parent().addClass('even');
501 $(this).parent().removeClass('odd');
504 $(this).parent().css('display','none');
509 // Provides a nicely formatted and sorted tooltip of each datapoint of the query statistics
510 function sortedQueriesPointInfo(queries
, lastQueries
){
511 var max
, maxIdx
, num
=0;
512 var queryKeys
= new Array();
513 var queryValues
= new Array();
517 // Separate keys and values, then sort them
518 $.each(queries
.pointInfo
, function(key
,value
) {
519 if(value
-lastQueries
.pointInfo
[key
] > 0) {
521 queryValues
.push(value
-lastQueries
.pointInfo
[key
]);
522 sumTotal
+= value
-lastQueries
.pointInfo
[key
];
525 var numQueries
= queryKeys
.length
;
526 var pointInfo
= '<b>' + PMA_messages
['strTotal'] + ': ' + sumTotal
+ '</b><br>';
528 while(queryKeys
.length
> 0) {
530 for(var i
=0; i
< queryKeys
.length
; i
++) {
531 if(queryValues
[i
] > max
) {
532 max
= queryValues
[i
];
536 if(numQueries
> 8 && num
>= 6)
537 sumOther
+= queryValues
[maxIdx
];
538 else pointInfo
+= queryKeys
[maxIdx
].substr(4).replace('_',' ') + ': ' + queryValues
[maxIdx
] + '<br>';
540 queryKeys
.splice(maxIdx
,1);
541 queryValues
.splice(maxIdx
,1);
546 pointInfo
+= PMA_messages
['strOther'] + ': ' + sumOther
;
554 /**** Monitor charting implementation ****/
555 /* Saves the previous ajax response for differential values */
556 var oldChartData
= null;
557 // Holds about to created chart
561 // Runtime parameter of the monitor
563 // Holds all visible charts in the grid
565 // Current max points per chart (needed for auto calculation)
567 // displayed time frame
570 // Stores the timeout handler so it can be cleared
571 refreshTimeout
: null,
572 // Stores the GET request to refresh the charts
573 refreshRequest
: null,
574 // Chart auto increment
576 // To play/pause the monitor
578 // Object that contains a list of nodes that need to be retrieved from the server for chart updates
582 var monitorSettings
= null;
584 var defaultMonitorSettings
= {
586 chartSize
: { width
: 295, height
: 250 },
587 // Max points in each chart. Settings it to 'auto' sets gridMaxPoints to (chartwidth - 40) / 12
588 gridMaxPoints
: 'auto',
589 /* Refresh rate of all grid charts in ms */
593 // Allows drag and drop rearrange and print/edit icons on charts
594 var editMode
= false;
598 title
: PMA_messages
['strSystemCPUUsage'],
599 nodes
: [{ dataType
: 'cpu', name
: PMA_messages
['strAverageLoad'], dataPoint
: 'loadavg', unit
: '%'}]
602 title
: PMA_messages
['strSystemMemory'],
604 { dataType
: 'memory', name
: PMA_messages
['strTotalMemory'], dataPoint
: 'MemTotal', valueDivisor
: 1024, unit
: PMA_messages
['strMiB'] },
605 { dataType
: 'memory', name
: PMA_messages
['strUsedMemory'], dataPoint
: 'MemUsed', valueDivisor
: 1024, unit
: PMA_messages
['strMiB'] },
609 title
: PMA_messages
['strSystemSwap'],
611 { dataType
: 'memory', name
: PMA_messages
['strTotalSwap'], dataPoint
: 'SwapTotal', valueDivisor
: 1024, unit
: PMA_messages
['strMiB'] },
612 { dataType
: 'memory', name
: PMA_messages
['strUsedSwap'], dataPoint
: 'SwapUsed', valueDivisor
: 1024, unit
: PMA_messages
['strMiB'] },
616 title
: PMA_messages
['strSystemCPUUsage'],
619 name
: PMA_messages
['strAverageLoad'],
621 // Needs to be string so it is not ignored by $.toJSON()
623 'if(prev == null) return undefined;' +
624 'var diff_total = cur.busy + cur.idle - (prev.busy + prev.idle);' +
625 'var diff_idle = cur.idle - prev.idle;' +
626 'return 100*(diff_total - diff_idle) / diff_total;'
631 title
: PMA_messages
['strSystemMemory'],
633 { dataType
: 'memory', name
: PMA_messages
['strUsedMemory'], dataPoint
: 'MemUsed', valueDivisor
: 1024, unit
: PMA_messages
['strMiB'] },
634 { dataType
: 'memory', name
: PMA_messages
['strCachedMemory'], dataPoint
: 'Cached', valueDivisor
: 1024, unit
: PMA_messages
['strMiB'] },
635 { dataType
: 'memory', name
: PMA_messages
['strBufferedMemory'], dataPoint
: 'Buffers', valueDivisor
: 1024, unit
: PMA_messages
['strMiB'] },
636 { dataType
: 'memory', name
: PMA_messages
['strFreeMemory'], dataPoint
:'MemFree', valueDivisor
: 1024, unit
: PMA_messages
['strMiB'] },
651 title
: PMA_messages
['strSystemSwap'],
653 { dataType
: 'memory', name
: PMA_messages
['strTotalSwap'], dataPoint
: 'SwapUsed', valueDivisor
: 1024, unit
: PMA_messages
['strMiB'] },
654 { dataType
: 'memory', name
: PMA_messages
['strCachedSwap'], dataPoint
: 'SwapCached', valueDivisor
: 1024, unit
: PMA_messages
['strMiB'] },
655 { dataType
: 'memory', name
: PMA_messages
['strFreeSwap'], dataPoint
: 'SwapFree', valueDivisor
: 1024, unit
: PMA_messages
['strMiB'] },
673 'c0': { title
: PMA_messages
['strQuestions'],
674 nodes
: [{ dataType
: 'statusvar', name
: PMA_messages
['strQuestions'], dataPoint
: 'Questions', display
: 'differential' }]
677 title
: PMA_messages
['strChartConnectionsTitle'],
678 nodes
: [ { dataType
: 'statusvar', name
: PMA_messages
['strConnections'], dataPoint
: 'Connections', display
: 'differential' },
679 { dataType
: 'proc', name
: PMA_messages
['strProcesses'], dataPoint
: 'processes'} ]
682 title
: PMA_messages
['strTraffic'],
684 { dataType
: 'statusvar', name
: PMA_messages
['strBytesSent'], dataPoint
: 'Bytes_sent', display
: 'differential', valueDivisor
: 1024, unit
: PMA_messages
['strKiB'] },
685 { dataType
: 'statusvar', name
: PMA_messages
['strBytesReceived'], dataPoint
: 'Bytes_received', display
: 'differential', valueDivisor
: 1024, unit
: PMA_messages
['strKiB'] }
690 // Server is localhost => We can add cpu/memory/swap
691 if(server_db_isLocal
) {
692 defaultChartGrid
['c3'] = presetCharts
['cpu-' + server_os
];
693 defaultChartGrid
['c4'] = presetCharts
['memory-' + server_os
];
694 defaultChartGrid
['c5'] = presetCharts
['swap-' + server_os
];
700 symbol
: 'url(' + pmaThemeImage
+ 's_cog.png)',
702 symbolFill
: '#B5C9DF',
703 hoverSymbolFill
: '#779ABF',
704 _titleKey
: 'settings',
705 menuName
: 'gridsettings',
707 textKey
: 'editChart',
708 onclick: function() {
712 textKey
: 'removeChart',
713 onclick: function() {
720 Highcharts
.setOptions({
722 settings
: PMA_messages
['strSettings'],
723 removeChart
: PMA_messages
['strRemoveChart'],
724 editChart
: PMA_messages
['strEditChart']
728 $('a[href="#rearrangeCharts"], a[href="#endChartEditMode"]').click(function() {
729 editMode
= !editMode
;
730 if($(this).attr('href') == '#endChartEditMode') editMode
= false;
732 // Icon graphics have zIndex 19,20 and 21. Let's just hope nothing else has the same zIndex
733 $('table#chartGrid div svg').find('*[zIndex=20], *[zIndex=21], *[zIndex=19]').toggle(editMode
)
735 $('a[href="#endChartEditMode"]').toggle(editMode
);
738 // Close the settings popup
739 $('#statustabs_charting .popupContent').hide().removeClass('openedPopup');
741 $("#chartGrid").sortableTable({
744 left
: chartSize().width
- 63,
749 // Drop event. The drag child element is moved into the drop element
750 // and vice versa. So the parameters are switched.
751 drop: function(drag
, drop
, pos
) {
752 var dragKey
, dropKey
, dropRender
;
753 var dragRender
= $(drag
).children().first().attr('id');
755 if($(drop
).children().length
> 0)
756 dropRender
= $(drop
).children().first().attr('id');
758 // Find the charts in the array
759 $.each(runtime
.charts
, function(key
, value
) {
760 if(value
.chart
.options
.chart
.renderTo
== dragRender
)
762 if(dropRender
&& value
.chart
.options
.chart
.renderTo
== dropRender
)
766 // Case 1: drag and drop are charts -> Switch keys
769 dragChart
= runtime
.charts
[dragKey
];
770 runtime
.charts
[dragKey
] = runtime
.charts
[dropKey
];
771 runtime
.charts
[dropKey
] = dragChart
;
773 // Case 2: drop is a empty cell => just completely rebuild the ids
775 var dropKeyNum
= parseInt(dropKey
.substr(1));
776 var insertBefore
= pos
.col
+ pos
.row
* monitorSettings
.columns
;
778 var newChartList
= {};
781 $.each(runtime
.charts
, function(key
, value
) {
788 // Rebuilds all ids, with the dragged chart correctly inserted
789 for(var i
=0; i
<keys
.length
; i
++) {
790 if(keys
[i
] == insertBefore
) {
791 newChartList
['c' + (c
++)] = runtime
.charts
[dropKey
];
792 insertBefore
= -1; // Insert ok
794 newChartList
['c' + (c
++)] = runtime
.charts
[keys
[i
]];
797 // Not inserted => put at the end
798 if(insertBefore
!= -1)
799 newChartList
['c' + (c
++)] = runtime
.charts
[dropKey
];
801 runtime
.charts
= newChartList
;
811 $("#chartGrid").sortableTable('destroy');
812 saveMonitor(); // Save settings
819 $('div#statustabs_charting div.popupContent select[name="chartColumns"]').change(function() {
820 monitorSettings
.columns
= parseInt(this.value
);
822 var newSize
= chartSize();
824 // Empty cells should keep their size so you can drop onto them
825 $('table#chartGrid tr td').css('width',newSize
.width
+ 'px');
827 /* Reorder all charts that it fills all column cells */
829 var $tr
= $('table#chartGrid tr:first');
831 while($tr
.length
!= 0) {
833 // To many cells in one row => put into next row
834 $tr
.find('td').each(function() {
835 if(numColumns
> monitorSettings
.columns
) {
836 if($tr
.next().length
== 0) $tr
.after('<tr></tr>');
837 $tr
.next().prepend($(this));
842 // To little cells in one row => for each cell to little, move all cells backwards by 1
843 if($tr
.next().length
> 0) {
844 var cnt
= monitorSettings
.columns
- $tr
.find('td').length
;
845 for(var i
=0; i
< cnt
; i
++) {
846 $tr
.append($tr
.next().find('td:first'));
847 $tr
.nextAll().each(function() {
848 if($(this).next().length
!= 0)
849 $(this).append($(this).next().find('td:first'));
858 /* Apply new chart size to all charts */
859 $.each(runtime
.charts
, function(key
, value
) {
867 if(monitorSettings
.gridMaxPoints
== 'auto')
868 runtime
.gridMaxPoints
= Math
.round((newSize
.width
- 40) / 12);
870 runtime
.xmin
= new Date().getTime() - server_time_diff
- runtime
.gridMaxPoints
* monitorSettings
.gridRefresh
;
871 runtime
.xmax
= new Date().getTime() - server_time_diff
+ monitorSettings
.gridRefresh
;
874 $("#chartGrid").sortableTable('refresh');
876 saveMonitor(); // Save settings
879 $('div#statustabs_charting div.popupContent select[name="gridChartRefresh"]').change(function() {
880 monitorSettings
.gridRefresh
= parseInt(this.value
) * 1000;
881 clearTimeout(runtime
.refreshTimeout
);
883 if(runtime
.refreshRequest
)
884 runtime
.refreshRequest
.abort();
886 runtime
.xmin
= new Date().getTime() - server_time_diff
- runtime
.gridMaxPoints
* monitorSettings
.gridRefresh
;
887 runtime
.xmax
= new Date().getTime() - server_time_diff
+ monitorSettings
.gridRefresh
;
889 $.each(runtime
.charts
, function(key
, value
) {
890 value
.chart
.xAxis
[0].setExtremes(runtime
.xmin
, runtime
.xmax
, false);
893 runtime
.refreshTimeout
= setTimeout(refreshChartGrid
, monitorSettings
.gridRefresh
);
895 saveMonitor(); // Save settings
898 $('a[href="#addNewChart"]').click(function() {
899 var dlgButtons
= { };
901 dlgButtons
[PMA_messages
['strAddChart']] = function() {
902 var type
= $('input[name="chartType"]:checked').val();
904 if(type
== 'cpu' || type
== 'memory' || type
=='swap')
905 newChart
= presetCharts
[type
+ '-' + server_os
];
907 if(! newChart
|| ! newChart
.nodes
|| newChart
.nodes
.length
== 0) {
908 alert(PMA_messages
['strAddOneSeriesWarning']);
913 newChart
.title
= $('input[name="chartTitle"]').attr('value');
914 // Add a cloned object to the chart grid
915 addChart($.extend(true, {}, newChart
));
919 saveMonitor(); // Save settings
921 $(this).dialog("close");
924 dlgButtons
[PMA_messages
['strClose']] = function() {
926 $('span#clearSeriesLink').hide();
927 $('#seriesPreview').html('');
928 $(this).dialog("close");
931 $('div#addChartDialog').dialog({
937 $('div#addChartDialog #seriesPreview').html('<i>' + PMA_messages
['strNone'] + '</i>');
942 $('a[href="#pauseCharts"]').click(function() {
943 runtime
.redrawCharts
= ! runtime
.redrawCharts
;
944 if(! runtime
.redrawCharts
)
945 $(this).html('<img src="themes/dot.gif" class="icon ic_play" alt="" /> ' + PMA_messages
['strResumeMonitor']);
947 $(this).html('<img src="themes/dot.gif" class="icon ic_pause" alt="" /> ' + PMA_messages
['strPauseMonitor']);
948 if(runtime
.charts
== null) {
950 $('a[href="#settingsPopup"]').show();
956 $('a[href="#monitorInstructionsDialog"]').click(function() {
957 var $dialog
= $('div#monitorInstructionsDialog');
962 }).find('img.ajaxIcon').show();
964 var loadLogVars = function(getvars
) {
965 vars
= { ajax_request
: true, logging_vars
: true };
966 if(getvars
) $.extend(vars
,getvars
);
968 $.get('server_status.php?' + url_query
, vars
,
970 var logVars
= $.parseJSON(data
),
971 icon
= 'ic_s_success', msg
='', str
='';
973 if(logVars
['general_log'] == 'ON') {
974 if(logVars
['slow_query_log'] == 'ON')
975 msg
= PMA_messages
['strBothLogOn'];
977 msg
= PMA_messages
['strGenLogOn'];
980 if(msg
.length
== 0 && logVars
['slow_query_log'] == 'ON') {
981 msg
= PMA_messages
['strSlowLogOn'];
984 if(msg
.length
== 0) {
986 msg
= PMA_messages
['strBothLogOff'];
989 str
= '<b>' + PMA_messages
['strCurrentSettings'] + '</b><br><div class="smallIndent">';
990 str
+= '<img src="themes/dot.gif" class="icon ' + icon
+ '" alt=""/> ' + msg
+ '<br />';
992 if(logVars
['log_output'] != 'TABLE')
993 str
+= '<img src="themes/dot.gif" class="icon ic_s_error" alt=""/> ' + PMA_messages
['strLogOutNotTable'] + '<br />';
995 str
+= '<img src="themes/dot.gif" class="icon ic_s_success" alt=""/> ' + PMA_messages
['strLogOutIsTable'] + '<br />';
997 if(logVars
['slow_query_log'] == 'ON') {
998 if(logVars
['long_query_time'] > 2)
999 str
+= '<img src="themes/dot.gif" class="icon ic_s_attention" alt=""/> '
1000 + $.sprintf(PMA_messages
['strSmallerLongQueryTimeAdvice'], logVars
['long_query_time'])
1003 if(logVars
['long_query_time'] < 2)
1004 str
+= '<img src="themes/dot.gif" class="icon ic_s_success" alt=""/> '
1005 + $.sprintf(PMA_messages
['strLongQueryTimeSet'], logVars
['long_query_time'])
1012 str
+= '<p></p><b>Change settings</b>';
1013 str
+= '<div class="smallIndent">';
1014 str
+= PMA_messages
['strSettingsAppliedGlobal'] + '<br/>';
1016 var varValue
= 'TABLE';
1017 if(logVars
['log_output'] == 'TABLE') varValue
= 'FILE';
1019 str
+= '- <a class="set" href="#log_output-' + varValue
+ '">'
1020 + $.sprintf(PMA_messages
['strSetLogOutput'], varValue
)
1023 if(logVars
['general_log'] != 'ON')
1024 str
+= '- <a class="set" href="#general_log-ON">'
1025 + $.sprintf(PMA_messages
['strEnableVar'], 'general_log')
1028 str
+= '- <a class="set" href="#general_log-OFF">'
1029 + $.sprintf(PMA_messages
['strDisableVar'], 'general_log')
1032 if(logVars
['slow_query_log'] != 'ON')
1033 str
+= '- <a class="set" href="#slow_query_log-ON">'
1034 + $.sprintf(PMA_messages
['strEnableVar'], 'slow_query_log')
1037 str
+= '- <a class="set" href="#slow_query_log-OFF">'
1038 + $.sprintf(PMA_messages
['strDisableVar'], 'slow_query_log')
1043 if(logVars
['long_query_time'] > 2) varValue
= 1;
1045 str
+= '- <a class="set" href="#long_query_time-' + varValue
+ '">'
1046 + $.sprintf(PMA_messages
['setSetLongQueryTime'], varValue
)
1050 str
+= PMA_messages
['strNoSuperUser'] + '<br/>';
1054 $dialog
.find('div.monitorUse').toggle(
1055 logVars
['log_output'] == 'TABLE' && (logVars
['slow_query_log'] == 'ON' || logVars
['general_log'] == 'ON')
1058 $dialog
.find('div.ajaxContent').html(str
);
1059 $dialog
.find('img.ajaxIcon').hide();
1060 $dialog
.find('a.set').click(function() {
1061 var nameValue
= $(this).attr('href').split('-');
1062 loadLogVars({ varName
: nameValue
[0].substr(1), varValue
: nameValue
[1]});
1063 $dialog
.find('img.ajaxIcon').show();
1075 $('input[name="chartType"]').change(function() {
1076 $('#chartVariableSettings').toggle(this.checked
&& this.value
== 'variable');
1077 var title
= $('input[name="chartTitle"]').attr('value');
1078 if(title
== PMA_messages
['strChartTitle'] || title
== $('label[for="'+$('input[name="chartTitle"]').data('lastRadio')+'"]').text()) {
1079 $('input[name="chartTitle"]').data('lastRadio',$(this).attr('id'));
1080 $('input[name="chartTitle"]').attr('value',$('label[for="'+$(this).attr('id')+'"]').text());
1085 $('input[name="useDivisor"]').change(function() {
1086 $('span.divisorInput').toggle(this.checked
);
1088 $('input[name="useUnit"]').change(function() {
1089 $('span.unitInput').toggle(this.checked
);
1092 $('select[name="varChartList"]').change(function () {
1093 if(this.selectedIndex
!=0)
1094 $('#variableInput').attr('value',this.value
);
1097 $('a[href="#kibDivisor"]').click(function() {
1098 $('input[name="valueDivisor"]').attr('value',1024);
1099 $('input[name="valueUnit"]').attr('value',PMA_messages
['strKiB']);
1100 $('span.unitInput').toggle(true);
1101 $('input[name="useUnit"]').prop('checked',true);
1105 $('a[href="#mibDivisor"]').click(function() {
1106 $('input[name="valueDivisor"]').attr('value',1024*1024);
1107 $('input[name="valueUnit"]').attr('value',PMA_messages
['strMiB']);
1108 $('span.unitInput').toggle(true);
1109 $('input[name="useUnit"]').prop('checked',true);
1113 $('a[href="#submitClearSeries"]').click(function() {
1114 $('#seriesPreview').html('<i>' + PMA_messages
['strNone'] + '</i>');
1116 $('span#clearSeriesLink').hide();
1119 $('a[href="#submitAddSeries"]').click(function() {
1120 if($('input#variableInput').attr('value').length
== 0) return false;
1122 if(newChart
== null) {
1123 $('#seriesPreview').html('');
1126 title
: $('input[name="chartTitle"]').attr('value'),
1132 dataType
:'statusvar',
1133 dataPoint
: $('input#variableInput').attr('value'),
1134 name
: $('input#variableInput').attr('value'),
1135 display
: $('input[name="differentialValue"]').attr('checked') ? 'differential' : ''
1138 if(serie
.dataPoint
== 'Processes') serie
.dataType
='proc';
1140 if($('input[name="useDivisor"]').attr('checked'))
1141 serie
.valueDivisor
= parseInt($('input[name="valueDivisor"]').attr('value'));
1143 if($('input[name="useUnit"]').attr('checked'))
1144 serie
.unit
= $('input[name="valueUnit"]').attr('value');
1148 var str
= serie
.display
== 'differential' ? ', ' + PMA_messages
['strDifferential'] : '';
1149 str
+= serie
.valueDivisor
? (', ' + $.sprintf(PMA_messages
['strDividedBy'], serie
.valueDivisor
)) : '';
1151 $('#seriesPreview').append('- ' + serie
.dataPoint
+ str
+ '<br>');
1153 newChart
.nodes
.push(serie
);
1155 $('input#variableInput').attr('value','');
1156 $('input[name="differentialValue"]').attr('checked',true);
1157 $('input[name="useDivisor"]').attr('checked',false);
1158 $('input[name="useUnit"]').attr('checked',false);
1159 $('input[name="useDivisor"]').trigger('change');
1160 $('input[name="useUnit"]').trigger('change');
1161 $('select[name="varChartList"]').get(0).selectedIndex
=0;
1163 $('span#clearSeriesLink').show();
1168 $("input#variableInput").autocomplete({
1169 source
: variableNames
1173 function initGrid() {
1177 /* Apply default values & config */
1178 if(window
.localStorage
) {
1179 if(window
.localStorage
['monitorCharts'])
1180 runtime
.charts
= $.parseJSON(window
.localStorage
['monitorCharts']);
1181 if(window
.localStorage
['monitorSettings'])
1182 monitorSettings
= $.parseJSON(window
.localStorage
['monitorSettings']);
1184 $('a[href="#clearMonitorConfig"]').toggle(runtime
.charts
!= null);
1187 if(runtime
.charts
== null)
1188 runtime
.charts
= defaultChartGrid
;
1189 if(monitorSettings
== null)
1190 monitorSettings
= defaultMonitorSettings
;
1192 $('select[name="gridChartRefresh"]').attr('value',monitorSettings
.gridRefresh
/ 1000);
1193 $('select[name="chartColumns"]').attr('value',monitorSettings
.columns
);
1195 if(monitorSettings
.gridMaxPoints
== 'auto')
1196 runtime
.gridMaxPoints
= Math
.round((monitorSettings
.chartSize
.width
- 40) / 12);
1198 runtime
.gridMaxPoints
= monitorSettings
.gridMaxPoints
;
1200 runtime
.xmin
= new Date().getTime() - server_time_diff
- runtime
.gridMaxPoints
* monitorSettings
.gridRefresh
;
1201 runtime
.xmax
= new Date().getTime() - server_time_diff
+ monitorSettings
.gridRefresh
;
1203 /* Calculate how much spacing there is between each chart */
1204 $('table#chartGrid').html('<tr><td></td><td></td></tr><tr><td></td><td></td></tr>');
1206 width
: $('table#chartGrid td:nth-child(2)').offset().left
- $('table#chartGrid td:nth-child(1)').offset().left
,
1207 height
: $('table#chartGrid tr:nth-child(2) td:nth-child(2)').offset().top
- $('table#chartGrid tr:nth-child(1) td:nth-child(1)').offset().top
1209 $('table#chartGrid').html('');
1211 /* Add all charts - in correct order */
1213 $.each(runtime
.charts
, function(key
, value
) {
1217 for(var i
=0; i
<keys
.length
; i
++)
1218 addChart(runtime
.charts
[keys
[i
]],true);
1220 /* Fill in missing cells */
1221 var numCharts
= $('table#chartGrid .monitorChart').length
;
1222 var numMissingCells
= (monitorSettings
.columns
- numCharts
% monitorSettings
.columns
) % monitorSettings
.columns
;
1223 for(var i
=0; i
< numMissingCells
; i
++) {
1224 $('table#chartGrid tr:last').append('<td></td>');
1227 // Empty cells should keep their size so you can drop onto them
1228 $('table#chartGrid tr td').css('width',chartSize().width
+ 'px');
1231 buildRequiredDataList();
1235 function chartSize() {
1236 var wdt
= $('div#logTable').innerWidth() / monitorSettings
.columns
- (monitorSettings
.columns
- 1) * chartSpacing
.width
;
1243 function addChart(chartObj
, initialize
) {
1245 for(var j
=0; j
<chartObj
.nodes
.length
; j
++)
1246 series
.push(chartObj
.nodes
[j
]);
1250 renderTo
: 'gridchart' + runtime
.chartAI
,
1251 width
: chartSize().width
,
1252 height
: chartSize().height
,
1256 selection: function(event
) {
1257 if(editMode
) return false;
1259 var extremesObject
= event
.xAxis
[0],
1260 min
= extremesObject
.min
,
1261 max
= extremesObject
.max
;
1263 $('#logAnalyseDialog input[name="dateStart"]')
1264 .attr('value', Highcharts
.dateFormat('%Y-%m-%d %H:%M:%S', new Date(min
)));
1265 $('#logAnalyseDialog input[name="dateEnd"]')
1266 .attr('value', Highcharts
.dateFormat('%Y-%m-%d %H:%M:%S', new Date(max
)));
1270 dlgBtns
[PMA_messages
['strFromSlowLog']] = function() {
1271 var dateStart
= Date
.parse($('#logAnalyseDialog input[name="dateStart"]').attr('value')) || min
;
1272 var dateEnd
= Date
.parse($('#logAnalyseDialog input[name="dateEnd"]').attr('value')) || max
;
1278 removeVariables
: $('input#removeVariables').prop('checked'),
1279 limitTypes
: $('input#limitTypes').prop('checked')
1282 $('#logAnalyseDialog').find('dateStart,dateEnd').datepicker('destroy');
1284 $(this).dialog("close");
1287 dlgBtns
[PMA_messages
['strFromGeneralLog']] = function() {
1288 var dateStart
= Date
.parse($('#logAnalyseDialog input[name="dateStart"]').attr('value')) || min
;
1289 var dateEnd
= Date
.parse($('#logAnalyseDialog input[name="dateEnd"]').attr('value')) || max
;
1295 removeVariables
: $('input#removeVariables').prop('checked'),
1296 limitTypes
: $('input#limitTypes').prop('checked')
1299 $('#logAnalyseDialog').find('dateStart,dateEnd').datepicker('destroy');
1301 $(this).dialog("close");
1304 $('#logAnalyseDialog').dialog({
1325 formatter: function() {
1326 var s
= '<b>'+Highcharts
.dateFormat('%H:%M:%S', this.x
)+'</b>';
1328 $.each(this.points
, function(i
, point
) {
1329 s
+= '<br/><span style="color:'+point
.series
.color
+'">'+ point
.series
.name
+':</span> '+
1330 ((parseInt(point
.y
) == point
.y
) ? point
.y
: Highcharts
.numberFormat(this.y
, 2)) + ' ' + (point
.series
.options
.unit
|| '');
1341 buttons
: gridbuttons
,
1342 title
: { text
: chartObj
.title
}
1345 if(chartObj
.settings
)
1346 $.extend(true,settings
,chartObj
.settings
);
1348 if($('#'+settings
.chart
.renderTo
).length
==0) {
1349 var numCharts
= $('table#chartGrid .monitorChart').length
;
1351 if(numCharts
== 0 || !( numCharts
% monitorSettings
.columns
))
1352 $('table#chartGrid').append('<tr></tr>');
1354 $('table#chartGrid tr:last').append('<td><div class="ui-state-default monitorChart" id="'+settings
.chart
.renderTo
+'"></div></td>');
1357 chartObj
.chart
= PMA_createChart(settings
);
1358 chartObj
.numPoints
= 0;
1360 if(initialize
!= true) {
1361 runtime
.charts
['c'+runtime
.chartAI
] = chartObj
;
1362 buildRequiredDataList();
1365 // Edit,Print icon only in edit mode
1366 $('table#chartGrid div svg').find('*[zIndex=20], *[zIndex=21], *[zIndex=19]').toggle(editMode
)
1371 function editChart(chartObj
) {
1372 var htmlnode
= chartObj
.options
.chart
.renderTo
;
1373 if(! htmlnode
) return;
1377 $.each(runtime
.charts
, function(key
, value
) {
1378 if(value
.chart
.options
.chart
.renderTo
== htmlnode
) {
1385 if(chart
== null) return;
1387 var htmlStr
= '<p><b>Chart title: </b> <br/> <input type="text" size="35" name="chartTitle" value="' + chart
.title
+ '" />';
1388 htmlStr
+= '</p><p><b>Series:</b> </p><ol>';
1389 for(var i
=0; i
<chart
.nodes
.length
; i
++) {
1390 htmlStr
+= '<li><i>' + chart
.nodes
[i
].dataPoint
+': </i><br/><input type="text" name="chartSerie-' + i
+ '" value=" ' + chart
.nodes
[i
].name
+ '" /></li>';
1394 dlgBtns
['Save'] = function() {
1395 runtime
.charts
[chartKey
].title
= $('div#emptyDialog input[name="chartTitle"]').attr('value');
1396 runtime
.charts
[chartKey
].chart
.setTitle({ text
: runtime
.charts
[chartKey
].title
});
1398 $('div#emptyDialog input[name*="chartSerie"]').each(function() {
1399 var idx
= $(this).attr('name').split('-')[1];
1400 runtime
.charts
[chartKey
].nodes
[idx
].name
= $(this).attr('value');
1401 runtime
.charts
[chartKey
].chart
.series
[idx
].name
= $(this).attr('value');
1404 $(this).dialog('close');
1407 dlgBtns
['Cancel'] = function() {
1408 $(this).dialog('close');
1411 $('div#emptyDialog').attr('title','Edit chart');
1412 $('div#emptyDialog').html(htmlStr
+'</ol>');
1413 $('div#emptyDialog').dialog({
1420 function removeChart(chartObj
) {
1421 var htmlnode
= chartObj
.options
.chart
.renderTo
;
1422 if(! htmlnode
) return;
1424 $.each(runtime
.charts
, function(key
, value
) {
1425 if(value
.chart
.options
.chart
.renderTo
== htmlnode
) {
1426 delete runtime
.charts
[key
];
1431 buildRequiredDataList();
1433 // Using settimeout() because clicking the remove link fires an onclick event
1434 // which throws an error when the chart is destroyed
1435 setTimeout(function() {
1437 $('div#' + htmlnode
).remove();
1440 saveMonitor(); // Save settings
1443 function refreshChartGrid() {
1444 /* Send to server */
1445 runtime
.refreshRequest
= $.post('server_status.php?'+url_query
, { ajax_request
: true, chart_data
: 1, type
: 'chartgrid', requiredData
: $.toJSON(runtime
.dataList
) },function(data
) {
1448 chartData
= $.parseJSON(data
);
1450 return serverResponseError();
1455 /* Update values in each graph */
1456 $.each(runtime
.charts
, function(orderKey
, elem
) {
1457 var key
= elem
.chartID
;
1458 // If newly added chart, we have no data for it yet
1459 if(! chartData
[key
]) return;
1461 for(var j
=0; j
< elem
.nodes
.length
; j
++) {
1462 value
= chartData
[key
][j
].y
;
1465 if(oldChartData
==null) diff
= chartData
.x
- runtime
.xmax
;
1466 else diff
= parseInt(chartData
.x
- oldChartData
.x
);
1468 runtime
.xmin
+= diff
;
1469 runtime
.xmax
+= diff
;
1472 elem
.chart
.xAxis
[0].setExtremes(runtime
.xmin
, runtime
.xmax
, false);
1474 if(elem
.nodes
[j
].display
== 'differential') {
1475 if(oldChartData
== null || oldChartData
[key
] == null) continue;
1476 value
-= oldChartData
[key
][j
].y
;
1479 if(elem
.nodes
[j
].valueDivisor
)
1480 value
= value
/ elem
.nodes
[j
].valueDivisor
;
1482 if(elem
.nodes
[j
].transformFn
) {
1483 value
= eval('(function(cur, prev) { ' + elem
.nodes
[j
].transformFn
+ '})(' +
1484 'chartData[key][j],' + (oldChartData
== null ? 'null' : 'oldChartData[key][j]') + ')');
1487 if(value
!= undefined)
1488 elem
.chart
.series
[j
].addPoint(
1489 { x
: chartData
.x
, y
: value
},
1491 elem
.numPoints
>= runtime
.gridMaxPoints
1497 runtime
.charts
[orderKey
].numPoints
++;
1498 if(runtime
.redrawCharts
)
1499 elem
.chart
.redraw();
1502 oldChartData
= chartData
;
1504 runtime
.refreshTimeout
= setTimeout(refreshChartGrid
, monitorSettings
.gridRefresh
);
1508 /* Build list of nodes that need to be retrieved */
1509 function buildRequiredDataList() {
1510 runtime
.dataList
= {};
1511 // Store an own id, because the property name is subject of reordering, thus destroying our mapping with runtime.charts <=> runtime.dataList
1513 $.each(runtime
.charts
, function(key
, chart
) {
1514 runtime
.dataList
[chartID
] = chart
.nodes
;
1515 runtime
.charts
[key
].chartID
= chartID
;
1520 function loadLogStatistics(opts
) {
1522 var logRequest
= null;
1524 if(! opts
.removeVariables
)
1525 opts
.removeVariables
= false;
1526 if(! opts
.limitTypes
)
1527 opts
.limitTypes
= false;
1529 $('#emptyDialog').html(PMA_messages
['strAnalysingLogs'] + ' <img class="ajaxIcon" src="' + pmaThemeImage
+ 'ajax_clock_small.gif" alt="">');
1531 $('#emptyDialog').dialog({
1535 'Cancel request': function() {
1536 if(logRequest
!= null)
1539 $(this).dialog("close");
1545 logRequest
= $.get('server_status.php?'+url_query
,
1546 { ajax_request
: true,
1549 time_start
: Math
.round(opts
.start
/ 1000),
1550 time_end
: Math
.round(opts
.end
/ 1000),
1551 removeVariables
: opts
.removeVariables
,
1552 limitTypes
: opts
.limitTypes
1557 logData
= $.parseJSON(data
);
1559 return serverResponseError();
1562 if(logData
.rows
.length
!= 0) {
1563 runtime
.logDataCols
= buildLogTable(logData
);
1565 /* Show some stats in the dialog */
1566 $('#emptyDialog').attr('title', PMA_messages
['strLoadingLogs']);
1567 $('#emptyDialog').html('<p>' + PMA_messages
['strLogDataLoaded'] + '</p>');
1568 $.each(logData
.sum
, function(key
, value
) {
1569 key
= key
.charAt(0).toUpperCase() + key
.slice(1).toLowerCase();
1570 if(key
== 'Total') key
= '<b>' + key
+ '</b>';
1571 $('#emptyDialog').append(key
+ ': ' + value
+ '<br/>');
1574 /* Add filter options if more than a bunch of rows there to filter */
1575 if(logData
.numRows
> 12) {
1576 $('div#logTable').prepend(
1577 '<fieldset id="logDataFilter">' +
1578 ' <legend>' + PMA_messages
['strFilters'] + '</legend>' +
1579 ' <div class="formelement">' +
1580 ' <label for="filterQueryText">' + PMA_messages
['strFilterByWordRegexp'] + '</label>' +
1581 ' <input name="filterQueryText" type="text" id="filterQueryText" style="vertical-align: baseline;" />' +
1583 ((logData
.numRows
> 250) ? ' <div class="formelement"><button name="startFilterQueryText" id="startFilterQueryText">' + PMA_messages
['strFilter'] + '</button></div>' : '') +
1584 ' <div class="formelement">' +
1585 ' <input type="checkbox" id="noWHEREData" name="noWHEREData" value="1" /> ' +
1586 ' <label for="noWHEREData"> ' + PMA_messages
['strIgnoreWhereAndGroup'] + '</label>' +
1591 $('div#logTable input#noWHEREData').change(function() {
1592 filterQueries(true);
1595 //preg_replace('/\s+([^=]+)=(\d+|((\'|"|)(?U)(.+)(?<!\\\)\4(\s+|$)))/i',' $1={} ',$str);
1597 if(logData
.numRows
> 250) {
1598 $('div#logTable button#startFilterQueryText').click(filterQueries
);
1600 $('div#logTable input#filterQueryText').keyup(filterQueries
);
1606 dlgBtns
[PMA_messages
['strJumpToTable']] = function() {
1607 $(this).dialog("close");
1608 $(document
).scrollTop($('div#logTable').offset().top
);
1611 $('#emptyDialog').dialog( "option", "buttons", dlgBtns
);
1614 $('#emptyDialog').html('<p>' + PMA_messages
['strNoDataFound'] + '</p>');
1617 dlgBtns
[PMA_messages
['strClose']] = function() {
1618 $(this).dialog("close");
1621 $('#emptyDialog').dialog( "option", "buttons", dlgBtns
);
1626 function filterQueries(varFilterChange
) {
1627 var odd_row
=false, cell
, textFilter
;
1628 var val
= $('div#logTable input#filterQueryText').val();
1630 if(val
.length
== 0) textFilter
= null;
1631 else textFilter
= new RegExp(val
, 'i');
1633 var rowSum
= 0, totalSum
= 0, i
=0, q
;
1634 var noVars
= $('div#logTable input#noWHEREData').attr('checked');
1635 var equalsFilter
= /([^=]+)=(\d+|((\'|"|).*?[^\\])\4((\s+)|$))/gi;
1636 var functionFilter
= /([a-z0-9_]+)\(.+?\)/gi;
1637 var filteredQueries
= {};
1638 var filteredQueriesLines
= {};
1639 var hide
= false, rowData
;
1640 var queryColumnName
= runtime
.logDataCols
[runtime
.logDataCols
.length
- 2];
1641 var sumColumnName
= runtime
.logDataCols
[runtime
.logDataCols
.length
- 1];
1643 var isSlowLog
= opts
.src
== 'slow';
1644 var columnSums
= {};
1646 var countRow = function(query
, row
) {
1647 var cells
= row
.match(/<td>(.*?)<\/td>/gi);
1648 if(!columnSums
[query
]) columnSums
[query
] = [0,0,0,0];
1650 columnSums
[query
][0] += timeToSec(cells
[2].replace(/(<td>|<\/td>)/gi,''));
1651 columnSums
[query
][1] += timeToSec(cells
[3].replace(/(<td>|<\/td>)/gi,''));
1652 columnSums
[query
][2] += parseInt(cells
[4].replace(/(<td>|<\/td>)/gi,''));
1653 columnSums
[query
][3] += parseInt(cells
[5].replace(/(<td>|<\/td>)/gi,''));
1656 // We just assume the sql text is always in the second last column, and that the total count is right of it
1657 $('div#logTable table tbody tr td:nth-child(' + (runtime
.logDataCols
.length
- 1) + ')').each(function() {
1658 if(varFilterChange
&& $(this).html().match(/^SELECT/i)) {
1660 q
= $(this).text().replace(equalsFilter
, '$1=...$6').trim();
1661 q
= q
.replace(functionFilter
, ' $1(...)');
1663 // Js does not specify a limit on property name length, so we can abuse it as index :-)
1664 if(filteredQueries
[q
]) {
1665 filteredQueries
[q
] += parseInt($(this).next().text());
1666 totalSum
+= parseInt($(this).next().text());
1669 filteredQueries
[q
] = parseInt($(this).next().text());;
1670 filteredQueriesLines
[q
] = i
;
1673 if(isSlowLog
) countRow(q
, $(this).parent().html());
1675 // Restore original columns
1677 rowData
= $(this).parent().data('query');
1680 $(this).text(rowData
[queryColumnName
]);
1682 $(this).next().text(rowData
[sumColumnName
]);
1685 $(this).parent().children('td:nth-child(3)').text(rowData
['query_time']);
1686 $(this).parent().children('td:nth-child(4)').text(rowData
['lock_time']);
1687 $(this).parent().children('td:nth-child(5)').text(rowData
['rows_sent']);
1688 $(this).parent().children('td:nth-child(6)').text(rowData
['rows_examined']);
1693 if(! hide
&& (textFilter
!= null && ! textFilter
.exec($(this).text()))) hide
= true;
1696 $(this).parent().css('display','none');
1698 totalSum
+= parseInt($(this).next().text());
1701 odd_row
= ! odd_row
;
1702 $(this).parent().css('display','');
1704 $(this).parent().addClass('odd');
1705 $(this).parent().removeClass('even');
1707 $(this).parent().addClass('even');
1708 $(this).parent().removeClass('odd');
1716 // Update count values of grouped entries
1717 if(varFilterChange
) {
1719 var numCol
, row
, $table
= $('div#logTable table tbody');
1720 $.each(filteredQueriesLines
, function(key
,value
) {
1721 if(filteredQueries
[key
] <= 1) return;
1723 row
= $table
.children('tr:nth-child(' + (value
+1) + ')');
1724 numCol
= row
.children(':nth-child(' + (runtime
.logDataCols
.length
) + ')');
1725 numCol
.text(filteredQueries
[key
]);
1728 row
.children('td:nth-child(3)').text(secToTime(columnSums
[key
][0]));
1729 row
.children('td:nth-child(4)').text(secToTime(columnSums
[key
][1]));
1730 row
.children('td:nth-child(5)').text(columnSums
[key
][2]);
1731 row
.children('td:nth-child(6)').text(columnSums
[key
][3]);
1736 $('div#logTable table').trigger("update");
1737 setTimeout(function() {
1738 $('div#logTable table').trigger('sorton',[[[runtime
.logDataCols
.length
- 1,1]]]);
1742 $('div#logTable table tfoot tr')
1743 .html('<th colspan="' + (runtime
.logDataCols
.length
- 1) + '">' +
1744 PMA_messages
['strSumRows'] + ' '+ rowSum
+'<span style="float:right">' +
1745 PMA_messages
['strTotal'] + '</span></th><th align="right">' + totalSum
+ '</th>');
1749 /*loadLogStatistics({
1751 start:1311076210*1000,
1752 end:1311162689*1000,
1753 removeVariables: true,
1757 function timeToSec(timeStr
) {
1758 var time
= timeStr
.split(':');
1759 return parseInt(time
[0]*3600) + parseInt(time
[1]*60) + parseInt(time
[2]);
1762 function secToTime(timeInt
) {
1763 hours
= Math
.floor(timeInt
/ 3600);
1764 timeInt
-= hours
*3600;
1765 minutes
= Math
.floor(timeInt
/ 60);
1766 timeInt
-= minutes
*60;
1768 if(hours
< 10) hours
= '0' + hours
;
1769 if(minutes
< 10) minutes
= '0' + minutes
;
1770 if(timeInt
< 10) timeInt
= '0' + timeInt
;
1772 return hours
+ ':' + minutes
+ ':' + timeInt
;
1775 function buildLogTable(data
) {
1776 var rows
= data
.rows
;
1777 var cols
= new Array();
1778 var $table
= $('<table border="0" class="sortable"></table>');
1779 var $tBody
, $tRow
, $tCell
;
1781 $('#logTable').html($table
);
1783 var formatValue = function(name
, value
) {
1786 return value
.replace(/(\[.*?\])+/g,'');
1791 for(var i
=0; i
< rows
.length
; i
++) {
1793 $.each(rows
[0],function(key
, value
) {
1796 $table
.append( '<thead>' +
1797 '<tr><th class="nowrap">' + cols
.join('</th><th class="nowrap">') + '</th></tr>' +
1800 $table
.append($tBody
= $('<tbody></tbody>'));
1803 $tBody
.append($tRow
= $('<tr class="noclick"></tr>'));
1805 for(var j
=0; j
< cols
.length
; j
++) {
1806 // Assuming the query column is the second last
1807 if(j
== cols
.length
- 2 && rows
[i
][cols
[j
]].match(/^SELECT/i)) {
1808 $tRow
.append($tCell
=$('<td class="analyzableQuery">' + formatValue(cols
[j
], rows
[i
][cols
[j
]]) + '</td>'));
1809 $tCell
.click(queryAnalyzer
);
1811 $tRow
.append('<td>' + formatValue(cols
[j
], rows
[i
][cols
[j
]]) + '</td>');
1814 $tRow
.data('query',rows
[i
]);
1818 $table
.append('<tfoot>' +
1819 '<tr><th colspan="' + (cols
.length
- 1) + '">' + PMA_messages
['strSumRows'] +
1820 ' '+ data
.numRows
+'<span style="float:right">' + PMA_messages
['strTotal'] +
1821 '</span></th><th align="right">' + data
.sum
.TOTAL
+ '</th></tr></tfoot>');
1824 function queryAnalyzer() {
1825 var query
= $(this).parent().data('query')[cols
[cols
.length
-2]];
1827 /* A very basic SQL Formatter. Totally fails in the cases of
1828 - Any string appearance containing a MySQL Keyword, surrounded by whitespaces
1829 - Subqueries too probably
1831 // .* selector doesn't includde whitespace, [^] doesn't work in IE8, thus we use [^\0] since the zero-byte char (hopefully) doesn't appear in table names ;)
1832 var sLists
= query
.match(/SELECT\s+[^\0]+\s+FROM\s+/gi);
1834 for(var i
=0; i
< sLists
.length
; i
++) {
1835 query
= query
.replace(sLists
[i
],sLists
[i
].replace(/\s*((`|'|"|).*?\1,)\s*/gi,'$1\n\t'));
1838 .replace(/(\s+|^)(SELECT|FROM|WHERE|GROUP BY|HAVING|ORDER BY|LIMIT)(\s+|$)/gi,'\n$2\n\t')
1839 .replace(/\s+UNION\s+/gi,'\n\nUNION\n\n')
1840 .replace(/\s+(AND)\s+/gi,' $1\n\t')
1844 codemirror_editor
.setValue(query
);
1846 var profilingChart
= null;
1848 $('div#queryAnalyzerDialog').dialog({
1853 'Analyse Query' : function() {
1854 $('div#queryAnalyzerDialog div.placeHolder').html('Analyzing... ' + '<img class="ajaxIcon" src="' + pmaThemeImage
+ 'ajax_clock_small.gif" alt="">');
1856 $.post('server_status.php?'+url_query
, {
1858 query_analyzer
: true,
1859 query
: codemirror_editor
.getValue()
1861 data
= $.parseJSON(data
);
1865 $('div#queryAnalyzerDialog div.placeHolder').html('<div class="error">' + data
.error
+ '</div>');
1869 // Float sux, I'll use table :(
1870 $('div#queryAnalyzerDialog div.placeHolder')
1871 .html('<table width="100%" border="0"><tr><td class="explain"></td><td class="chart"></td></tr></table>');
1873 var explain
= '<b>Explain output</b> '+explain_docu
;
1874 if(data
.explain
.length
> 1) {
1876 for(var i
=0; i
< data
.explain
.length
; i
++) {
1877 if(i
> 0) explain
+= ', ';
1878 explain
+= '<a href="#showExplain-' + i
+ '">' + i
+ '</a>';
1882 explain
+='<p></p>';
1883 for(var i
=0; i
< data
.explain
.length
; i
++) {
1884 explain
+= '<div class="explain-' + i
+ '"' + (i
>0? 'style="display:none;"' : '' ) + '>';
1885 $.each(data
.explain
[i
], function(key
,value
) {
1886 value
= (value
==null)?'null':value
;
1888 if(key
== 'type' && value
.toLowerCase() == 'all') value
= '<span class="attention">' + value
+'</span>';
1889 if(key
== 'Extra') value
= value
.replace(/(using (temporary|filesort))/gi,'<span class="attention">$1</span>');
1890 explain
+= key
+': ' + value
+ '<br />';
1892 explain
+= '</div>';
1895 // Since there is such a nice free space below the explain, lets put it here for now
1896 explain
+= '<p><b>' + PMA_messages
['strAffectedRows'] + '</b> ' + data
.affectedRows
;
1898 $('div#queryAnalyzerDialog div.placeHolder td.explain').append(explain
);
1900 $('div#queryAnalyzerDialog div.placeHolder a[href*="#showExplain"]').click(function() {
1901 var id
= $(this).attr('href').split('-')[1];
1902 $(this).parent().find('div[class*="explain"]').hide();
1903 $(this).parent().find('div[class*="explain-' + id
+ '"]').show();
1906 if(data
.profiling
) {
1908 var numberTable
= '<table class="queryNums"><thead><tr><th>Status</th><th>Time</th></tr></thead><tbody>';
1911 for(var i
=0; i
< data
.profiling
.length
; i
++) {
1912 duration
= parseFloat(data
.profiling
[i
].duration
);
1914 chartData
.push([data
.profiling
[i
].state
, duration
]);
1915 totalTime
+=duration
;
1917 numberTable
+= '<tr><td>' + data
.profiling
[i
].state
+ ' </td><td> ' + PMA_prettyProfilingNum(duration
,2) + '</td></tr>';
1919 numberTable
+= '<tr><td><b>Total time:</b></td><td>' + PMA_prettyProfilingNum(totalTime
,2) + '</td></tr>';
1920 numberTable
+= '</tbody></table>';
1922 $('div#queryAnalyzerDialog div.placeHolder td.chart').append('<b>Profiling results ' + profiling_docu
+ '</b> (<a href="#showNums">Table</a>, <a href="#showChart">Chart</a>)<br/>' + numberTable
+ ' <div id="queryProfiling"></div>');
1924 $('div#queryAnalyzerDialog div.placeHolder a[href="#showNums"]').click(function() {
1925 $('div#queryAnalyzerDialog div#queryProfiling').hide();
1926 $('div#queryAnalyzerDialog table.queryNums').show();
1930 $('div#queryAnalyzerDialog div.placeHolder a[href="#showChart"]').click(function() {
1931 $('div#queryAnalyzerDialog div#queryProfiling').show();
1932 $('div#queryAnalyzerDialog table.queryNums').hide();
1936 profilingChart
= PMA_createProfilingChart(chartData
, {
1938 renderTo
: 'queryProfiling'
1948 $('div#queryProfiling').resizable();
1953 'Close' : function() {
1954 if(profilingChart
!= null) {
1955 profilingChart
.destroy();
1957 $('div#queryAnalyzerDialog div.placeHolder').html('');
1958 codemirror_editor
.setValue('');
1960 $(this).dialog("close");
1966 // Append a tooltip to the count column, if there exist one
1967 if($('#logTable th:last').html() == '#') {
1968 $('#logTable th:last').append(' <img class="qroupedQueryInfoIcon icon ic_b_docs" src="themes/dot.gif" alt="" />');
1970 var qtipContent
= PMA_messages
['strCountColumnExplanation'];
1971 if(groupInserts
) qtipContent
+= '<p>' + PMA_messages
['strMoreCountColumnExplanation'] + '</p>';
1973 $('img.qroupedQueryInfoIcon').qtip({
1974 content
: qtipContent
,
1977 target
: 'bottomMiddle',
1982 hide
: { delay
: 1000 }
1986 $('div#logTable table').tablesorter({
1987 sortList
: [[cols
.length
- 1,1]],
1991 $('div#logTable table thead th')
1992 .append('<img class="icon sortableIcon" src="themes/dot.gif" alt="">');
1997 function saveMonitor() {
2000 $.each(runtime
.charts
, function(key
, elem
) {
2002 gridCopy
[key
].nodes
= elem
.nodes
;
2003 gridCopy
[key
].settings
= elem
.settings
;
2004 gridCopy
[key
].title
= elem
.title
;
2007 if(window
.localStorage
) {
2008 window
.localStorage
['monitorCharts'] = $.toJSON(gridCopy
);
2009 window
.localStorage
['monitorSettings'] = $.toJSON(monitorSettings
);
2012 $('a[href="#clearMonitorConfig"]').show();
2015 $('a[href="#clearMonitorConfig"]').click(function() {
2016 window
.localStorage
.removeItem('monitorCharts');
2017 window
.localStorage
.removeItem('monitorSettings');
2021 function serverResponseError() {
2023 btns
[PMA_messages
['strReloadPage']] = function() {
2024 window
.location
.reload();
2026 $('#emptyDialog').attr('title',PMA_messages
['strRefreshFailed']);
2027 $('#emptyDialog').html('<img class="icon ic_s_attention" src="themes/dot.gif" alt=""> ' + PMA_messages
['strInvalidResponseExplanation'])
2028 $('#emptyDialog').dialog({ buttons
: btns
});