function downloadBinary(url) { var d = new MochiKit.Async.Deferred(); $.ajax({ url: url, dataType: 'text', cache: false, beforeSend: function(request) { try { request.overrideMimeType('text/plain; charset=x-user-defined'); } catch(e) { // IE doesn't support overrideMimeType } }, success: function(data) { try { d.callback(new BinaryFile(data)); } catch(e) { d.errback(e); } }, error: function(xhr, textStatus, errorThrown) { // Special case for IE which handles binary data slightly // differently. if(textStatus == 'parsererror') { if (typeof xhr.responseBody != 'undefined') { return this.success(xhr.responseBody); } } d.errback(new Error(xhr.status)); } }); return d; } var RrdQuery = function(rrd) { this.rrd = rrd; } RrdQuery.prototype.getData = function(startTime, endTime) { var startTimestamp = startTime.getTime()/1000; var endTimestamp = endTime.getTime()/1000; var consolidationFunc = 'AVERAGE'; var lastUpdated = this.rrd.getLastUpdate(); var bestRRA = null; for(var i=0; i=0; d--) { flotData = []; timestamp = firstUpdated + (startRow - 1) * step; for (var i=startRow; i<=endRow; i++) { var val = bestRRA.getEl(i, d); flotData.push([timestamp*1000.0, val]); timestamp += step; } returnData.push({label: this.rrd.getDS(d).getName(), data: flotData}); } return returnData; }; var RrdQueryRemote = function(url) { this.url = url; this.rrd = null; } RrdQueryRemote.prototype.getData = function(startTime, endTime) { var endTimestamp = endTime.getTime()/1000; var d, self = this; if(!this.rrd || this.rrd.getLastUpdate() < endTimestamp) { d = downloadBinary(this.url) .addCallback( function(binary) { var rrd = new RRDFile(binary); self.rrd = rrd; return rrd; }); } else { d = new MochiKit.Async.Deferred() d.callback(this.rrd); } d.addCallback( function(rrd) { return new RrdQuery(rrd).getData(startTime, endTime); }); return d; };