-
-
-function processLogLineForChart( logLine ) {
- // TODO: make this more robust: anything could go wrong in here
- var match = logLine.match(/(.*)crunchstat:(.*)-- interval(.*)/);
- if( match ) {
- var series = match[2].trim().split(' ')[0];
- if( $.inArray( series, jobGraphSeries) < 0 ) {
- jobGraphSeries.push(series);
- }
- var intervalData = match[3].trim().split(' ');
- var dt = parseFloat(intervalData[0]);
- var dsum = 0.0;
- for(var i=2; i < intervalData.length; i += 2 ) {
- dsum += parseFloat(intervalData[i]);
- }
- // TODO: why 4? what if the data is smaller than 0.0001?
- var datum = (dsum/dt).toFixed(4);
- var preamble = match[1].trim().split(' ');
- var timestamp = preamble[0].replace('_','T');
- var xpoints = $.grep( jobGraphData, function(e){ return e['t'] === timestamp; });
- if(xpoints.length) {
- // xpoints[0] is the x point that that matched the timestamp and so already existed: add the new datum
- xpoints[0][series] = datum;
- } else {
- var entry = { 't': timestamp };
- entry[series] = datum;
- jobGraphData.push( entry );
- }
- }
-}
-
-$(document).on('arv-log-event', '#log_graph_div', function(event, eventData) {
- if( eventData.properties.text ) {
- var series_length = jobGraphSeries.length;
- processLogLineForChart( eventData.properties.text );
- if( series_length < jobGraphSeries.length) {
- // series have changed, draw entirely new graph
- $('#log_graph_div').html('');
- window.jobGraph = Morris.Line({
- element: 'log_graph_div',
- data: jobGraphData,
- xkey: 't',
- ykeys: jobGraphSeries,
- labels: jobGraphSeries
- });
- } else {
- jobGraph.setData( jobGraphData );
- }
- }
-
-} );
\ No newline at end of file