diff options
author | Richard Wall <richard@the-moon.net> | 2013-06-14 16:37:54 +0100 |
---|---|---|
committer | Richard Wall <richard@the-moon.net> | 2013-06-14 16:37:54 +0100 |
commit | 0b4e3665a016d40a1fbf47a8542cb6a022096e1c (patch) | |
tree | b0e6943bd02edb3f65af0bcc9955c94cb38995f9 /jarmon | |
parent | 4a41ade5990aae01e2ed39404ea5d2d12ce6bcae (diff) |
hack things around to allow independent ds transformers, even when they are in the same RRD file
Diffstat (limited to 'jarmon')
-rw-r--r-- | jarmon/jarmon.js | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js index e4fd1dc..51b1c33 100644 --- a/jarmon/jarmon.js +++ b/jarmon/jarmon.js @@ -337,21 +337,14 @@ jarmon.localTimeFormatter = function (v, axis) { * @constructor * @param rrd {Object} A javascriptrrd.RRDFile * @param unit {String} The unit symbol for this data series - * @param transformer {Function} A callable which performs a - * tranfsformation of the values returned from the RRD file. **/ -jarmon.RrdQuery = function(rrd, unit, transformer) { +jarmon.RrdQuery = function(rrd, unit) { this.rrd = rrd; this.unit = unit; - if(typeof(transformer) !== 'undefined') { - this.transformer = transformer; - } else { - this.transformer = function(v) {return v;}; - } }; jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs, - dsId, cfName) { + dsId, cfName, transformer) { /** * Generate a Flot compatible data object containing rows between start and * end time. The rows are taken from the first RRA whose data spans the @@ -363,6 +356,8 @@ jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs, * @param dsId {Variant} identifier of the RRD datasource (string or number) * @param cfName {String} The name of an RRD consolidation function (CF) * eg AVERAGE, MIN, MAX + * @param transformer {Function} A callable which performs a + * tranfsformation of the values returned from the RRD file. * @return {Object} A Flot compatible data series * eg label: '', data: [], unit: '' **/ @@ -392,6 +387,10 @@ jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs, cfName = 'AVERAGE'; } + if(typeof(transformer) === 'undefined') { + transformer = function(v) {return v;}; + } + var rra, step, rraRowCount, lastRowTime, firstRowTime; for(var i=0; i<this.rrd.getNrRRAs(); i++) { @@ -450,7 +449,7 @@ jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs, var val; var timestamp = startRowTime; for(i=startRowIndex; i<endRowIndex; i++) { - val = this.transformer(rra.getEl(i, dsIndex)); + val = transformer(rra.getEl(i, dsIndex)); flotData.push([timestamp*1000.0, val]); timestamp += step; } @@ -487,10 +486,8 @@ jarmon.RrdQuery.prototype.getDSNames = function() { * @param unit {String} The unit suffix of this data eg 'bit/sec' * @param downloader {Function} A callable which returns a Deferred and calls * back with a javascriptrrd.BinaryFile when it has downloaded. - * @param transformer {Function} A callable which performs a - * tranfsformation of the values returned from the RRD file. **/ -jarmon.RrdQueryRemote = function(url, unit, downloader, transformer) { +jarmon.RrdQueryRemote = function(url, unit, downloader) { this.url = url; this.unit = unit; if(typeof(downloader) == 'undefined') { @@ -498,7 +495,6 @@ jarmon.RrdQueryRemote = function(url, unit, downloader, transformer) { } else { this.downloader = downloader; } - this.transformer = transformer; this.lastUpdate = 0; this._download = null; @@ -529,7 +525,7 @@ jarmon.RrdQueryRemote.prototype._callRemote = function(methodName, args) { var rrd = new RRDFile(res); self.lastUpdate = rrd.getLastUpdate(); - var rq = new jarmon.RrdQuery(rrd, self.unit, self.transformer); + var rq = new jarmon.RrdQuery(rrd, self.unit); try { ret.resolve(rq[methodName].apply(rq, args)); } catch(e) { @@ -544,7 +540,7 @@ jarmon.RrdQueryRemote.prototype._callRemote = function(methodName, args) { jarmon.RrdQueryRemote.prototype.getData = function(startTime, endTime, - dsId, cfName) { + dsId, cfName, transformer) { /** * Return a Flot compatible data series asynchronously. * @@ -552,12 +548,16 @@ jarmon.RrdQueryRemote.prototype.getData = function(startTime, endTime, * @param startTime {Number} The start timestamp * @param endTime {Number} The end timestamp * @param dsId {Variant} identifier of the RRD datasource (string or number) + * @param cfName {String} The name of an RRD consolidation function (CF) + * eg AVERAGE, MIN, MAX + * @param transformer {Function} A callable which performs a + * tranfsformation of the values returned from the RRD file. * @return {Object} A Deferred which calls back with a flot data series. **/ if(this.lastUpdate < endTime/1000) { this._download = null; } - return this._callRemote('getData', [startTime, endTime, dsId, cfName]); + return this._callRemote('getData', [startTime, endTime, dsId, cfName, transformer]); }; @@ -581,10 +581,11 @@ jarmon.RrdQueryRemote.prototype.getDSNames = function() { * @param rrdQuery {Object} An RrdQueryRemote instance * @param dsId {Variant} identifier of the RRD datasource (string or number) **/ -jarmon.RrdQueryDsProxy = function(rrdQuery, dsId) { +jarmon.RrdQueryDsProxy = function(rrdQuery, dsId, transformer) { this.rrdQuery = rrdQuery; this.dsId = dsId; this.unit = rrdQuery.unit; + this.transformer = transformer; }; jarmon.RrdQueryDsProxy.prototype.getData = function(startTime, endTime) { @@ -596,7 +597,7 @@ jarmon.RrdQueryDsProxy.prototype.getData = function(startTime, endTime) { * @param endTime {Number} A unix timestamp marking the start time * @return {Object} A Deferred which calls back with a flot data series. **/ - return this.rrdQuery.getData(startTime, endTime, this.dsId); + return this.rrdQuery.getData(startTime, endTime, this.dsId, undefined, this.transformer); }; @@ -712,9 +713,9 @@ jarmon.Chart.prototype.setup = function() { if(typeof(dataDict[rrd]) === 'undefined') { dataDict[rrd] = new jarmon.RrdQueryRemote( - rrd, unit, this.downloader, transformer); + rrd, unit, this.downloader); } - this.addData(label, new jarmon.RrdQueryDsProxy(dataDict[rrd], ds)); + this.addData(label, new jarmon.RrdQueryDsProxy(dataDict[rrd], ds, transformer)); } }; |