Fix some memory leaks in server monitor

This commit is contained in:
Atul Pratap Singh 2012-12-05 03:29:20 +05:30
parent e2336b4b30
commit c410ce7e45

View File

@ -109,7 +109,7 @@ AJAX.registerOnload('server_status_monitor.js', function() {
dataPoints: [{type: 'statusvar', name: 'Qcache_hits'}, {type: 'statusvar', name: 'Com_select'}],
transformFn: 'qce'
} ],
maxYLabel: []
maxYLabel: 0
},
// Query cache usage
'qcu': {
@ -121,7 +121,7 @@ AJAX.registerOnload('server_status_monitor.js', function() {
dataPoints: [{type: 'statusvar', name: 'Qcache_free_memory'}, {type: 'servervar', name: 'query_cache_size'}],
transformFn: 'qcu'
} ],
maxYLabel: []
maxYLabel: 0
}
};
@ -145,7 +145,7 @@ AJAX.registerOnload('server_status_monitor.js', function() {
nodes: [ {
dataPoints: [{ type: 'cpu', name: 'loadavg'}]
} ],
maxYLabel: []
maxYLabel: 0
},
'memory': {
@ -163,7 +163,7 @@ AJAX.registerOnload('server_status_monitor.js', function() {
nodes: [{ dataPoints: [{ type: 'memory', name: 'MemTotal' }], valueDivisor: 1024 },
{ dataPoints: [{ type: 'memory', name: 'MemUsed' }], valueDivisor: 1024 }
],
maxYLabel: []
maxYLabel: 0
},
'swap': {
@ -180,7 +180,7 @@ AJAX.registerOnload('server_status_monitor.js', function() {
nodes: [{ dataPoints: [{ type: 'memory', name: 'SwapTotal' }]},
{ dataPoints: [{ type: 'memory', name: 'SwapUsed' }]}
],
maxYLabel: []
maxYLabel: 0
}
});
break;
@ -193,7 +193,7 @@ AJAX.registerOnload('server_status_monitor.js', function() {
label: PMA_messages['strAverageLoad']
} ],
nodes: [{ dataPoints: [{ type: 'cpu', name: 'irrelevant' }], transformFn: 'cpu-linux'}],
maxYLabel: []
maxYLabel: 0
},
'memory': {
title: PMA_messages['strSystemMemory'],
@ -209,7 +209,7 @@ AJAX.registerOnload('server_status_monitor.js', function() {
{ dataPoints: [{ type: 'memory', name: 'Buffers' }], valueDivisor: 1024 },
{ dataPoints: [{ type: 'memory', name: 'MemFree' }], valueDivisor: 1024 }
],
maxYLabel: []
maxYLabel: 0
},
'swap': {
title: PMA_messages['strSystemSwap'],
@ -223,7 +223,7 @@ AJAX.registerOnload('server_status_monitor.js', function() {
{ dataPoints: [{ type: 'memory', name: 'SwapCached' }], valueDivisor: 1024 },
{ dataPoints: [{ type: 'memory', name: 'SwapFree' }], valueDivisor: 1024 }
],
maxYLabel: []
maxYLabel: 0
}
});
break;
@ -238,7 +238,7 @@ AJAX.registerOnload('server_status_monitor.js', function() {
nodes: [ {
dataPoints: [{ type: 'cpu', name: 'loadavg'}]
} ],
maxYLabel: []
maxYLabel: 0
},
'memory': {
title: PMA_messages['strSystemMemory'],
@ -250,7 +250,7 @@ AJAX.registerOnload('server_status_monitor.js', function() {
{ dataPoints: [{ type: 'memory', name: 'MemUsed' }], valueDivisor: 1024 },
{ dataPoints: [{ type: 'memory', name: 'MemFree' }], valueDivisor: 1024 }
],
maxYLabel: []
maxYLabel: 0
},
'swap': {
title: PMA_messages['strSystemSwap'],
@ -262,7 +262,7 @@ AJAX.registerOnload('server_status_monitor.js', function() {
{ dataPoints: [{ type: 'memory', name: 'SwapUsed' }], valueDivisor: 1024 },
{ dataPoints: [{ type: 'memory', name: 'SwapFree' }], valueDivisor: 1024 }
],
maxYLabel: []
maxYLabel: 0
}
});
break;
@ -273,7 +273,7 @@ AJAX.registerOnload('server_status_monitor.js', function() {
'c0': { title: PMA_messages['strQuestions'],
series: [{label: PMA_messages['strQuestions']}],
nodes: [{dataPoints: [{ type: 'statusvar', name: 'Questions' }], display: 'differential' }],
maxYLabel: []
maxYLabel: 0
},
'c1': {
title: PMA_messages['strChartConnectionsTitle'],
@ -282,7 +282,7 @@ AJAX.registerOnload('server_status_monitor.js', function() {
nodes: [ { dataPoints: [{ type: 'statusvar', name: 'Connections' }], display: 'differential' },
{ dataPoints: [{ type: 'proc', name: 'processes' }] }
],
maxYLabel: []
maxYLabel: 0
},
'c2': {
title: PMA_messages['strTraffic'],
@ -294,7 +294,7 @@ AJAX.registerOnload('server_status_monitor.js', function() {
{ dataPoints: [{ type: 'statusvar', name: 'Bytes_sent' }], display: 'differential', valueDivisor: 1024 },
{ dataPoints: [{ type: 'statusvar', name: 'Bytes_received' }], display: 'differential', valueDivisor: 1024 }
],
maxYLabel: []
maxYLabel: 0
}
};
@ -1127,7 +1127,6 @@ AJAX.registerOnload('server_status_monitor.js', function() {
}
chartObj.chart = $.jqplot('gridchart' + runtime.chartAI, series, settings);
chartObj.numPoints = 0;
if (initialize != true) {
runtime.charts['c' + runtime.chartAI] = chartObj;
@ -1389,7 +1388,6 @@ AJAX.registerOnload('server_status_monitor.js', function() {
/* Update values in each graph */
$.each(runtime.charts, function(orderKey, elem) {
var key = elem.chartID;
var maxVal = 1;
// If newly added chart, we have no data for it yet
if (! chartData[key]) {
return;
@ -1439,33 +1437,30 @@ AJAX.registerOnload('server_status_monitor.js', function() {
// Set y value, if defined
if (value != undefined) {
elem.chart.series[j].data.push([chartData.x, value]);
maxVal = (maxVal > value) ? maxVal : value;
elem.chart.series[j].data.push([chartData.x, value]);
if(value > elem.maxYLabel) {
elem.maxYLabel = value;
}
// free old data point values and update maxYLabel
if(elem.chart.series[j].data.length > runtime.gridMaxPoints) {
// check if the next freeable point is highest
if(elem.maxYLabel <= elem.chart.series[j].data[0][1]) {
elem.chart.series[j].data.shift();
elem.maxYLabel = getMaxYLabel(elem.chart.series[j].data);
} else {
elem.chart.series[j].data.shift();
}
}
}
}
if (elem.maxYLabel.length == 0) {
elem.maxYLabel.push([runtime.xmax, 1]);
}
if (maxVal > elem.maxYLabel[elem.maxYLabel.length - 1][1]) {
elem.maxYLabel.push([chartData.x, (Math.ceil(maxVal*1.2))]);
} else if (maxVal > elem.maxYLabel[0][1]) {
elem.maxYLabel.splice(1,0,[chartData.x, (Math.ceil(maxVal*1.2))]);
}
if (elem.maxYLabel.length > 1
&& elem.maxYLabel[elem.maxYLabel.length - 1][0] < runtime.xmin
) {
elem.maxYLabel.pop();
elem.maxYLabel.sort(function(a,b){return a[1]-b[1]});
}
// update chart options
elem.chart['axes']['xaxis']['max'] = runtime.xmax;
elem.chart['axes']['xaxis']['min'] = runtime.xmin;
elem.chart['axes']['yaxis']['max'] = elem.maxYLabel[elem.maxYLabel.length - 1][1];
elem.chart['axes']['yaxis']['tickInterval'] = elem.maxYLabel[elem.maxYLabel.length - 1][1]/5;
elem.chart['axes']['yaxis']['max'] = Math.ceil(elem.maxYLabel*1.2);
elem.chart['axes']['yaxis']['tickInterval'] = Math.ceil(elem.maxYLabel*1.2)/5;
i++;
runtime.charts[orderKey].numPoints++;
if (runtime.redrawCharts) {
elem.chart.replot();
}
@ -1477,6 +1472,16 @@ AJAX.registerOnload('server_status_monitor.js', function() {
});
}
/* Function to get highest plotted point's y label, to scale the chart,
* TODO: make jqplot's autoscale:true work here
*/
function getMaxYLabel(dataValues) {
var yValues = [];
var maxY = dataValues[0][1];
$.each(dataValues,function(k,v){maxY = (v[1]>maxY) ? v[1] : maxY});
return maxY;
}
/* Function that supplies special value transform functions for chart values */
function chartValueTransform(name, cur, prev) {
switch(name) {