summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-12-08 21:34:51 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-12-08 21:34:51 -0500
commit14164bdb9a931073821933beeb863bc80bd22315 (patch)
treed5c7c2ce9aa4192cbcf389a22551482af4f4d7b2
parent4a41ade5990aae01e2ed39404ea5d2d12ce6bcae (diff)
parent2bff39e9b7c31f49ca02d7977d4315d6f09e1d36 (diff)
Merge branch 'lukeshu/independent-ds-transformers-1188220' into lukeshu/master
-rw-r--r--docs/examples/jarmon_example_recipes.js4
-rw-r--r--jarmon/jarmon.js47
-rw-r--r--jarmon/jarmon.test.js7
3 files changed, 28 insertions, 30 deletions
diff --git a/docs/examples/jarmon_example_recipes.js b/docs/examples/jarmon_example_recipes.js
index 7acfa8d..524515b 100644
--- a/docs/examples/jarmon_example_recipes.js
+++ b/docs/examples/jarmon_example_recipes.js
@@ -54,8 +54,8 @@ jarmon.CHART_RECIPES_COLLECTD = {
'interface': {
title: 'Wlan0 Throughput',
data: [
- ['data/interface/if_octets-wlan0.rrd', 'tx', 'Transmit', 'bit/s', function (v) { return v*8; }],
- ['data/interface/if_octets-wlan0.rrd', 'rx', 'Receive', 'bit/s', function (v) { return v*8; }]
+ ['data/interface-wlan0/if_octets.rrd', 'tx', 'Transmit', 'bit/s', function (v) { return -v*8; }],
+ ['data/interface-wlan0/if_octets.rrd', 'rx', 'Receive', 'bit/s', function (v) { return v*8; }]
],
options: jQuery.extend(true, {}, jarmon.Chart.BASE_OPTIONS)
},
diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js
index e4fd1dc..4e58334 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);
};
@@ -648,7 +649,7 @@ jarmon.Chart = function(template, recipe, downloader) {
};
var si = 0;
while(true) {
- if( Math.pow(1000, si+1)*0.9 > axis.max ) {
+ if( Math.pow(1000, si+1)*0.9 > (axis.max - axis.min) ) {
break;
}
si++;
@@ -658,7 +659,7 @@ jarmon.Chart = function(template, recipe, downloader) {
var maxVal = axis.max/Math.pow(1000, si);
var stepSizes = [0.01, 0.05, 0.1, 0.25, 0.5,
- 1, 5, 10, 25, 50, 100, 250];
+ 1, 2, 5, 10, 20, 25, 50, 100, 250];
var realStep = (maxVal - minVal)/5.0;
var stepSize, decimalPlaces = 0;
@@ -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));
}
};
diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js
index 5f5989d..8494406 100644
--- a/jarmon/jarmon.test.js
+++ b/jarmon/jarmon.test.js
@@ -296,11 +296,8 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) {
this.d.done(
function(rrd) {
self.resume(function() {
- var rq = new jarmon.RrdQuery(rrd, '', self._x10transformer);
- var data = rq.getData(RRD_STARTTIME, RRD_ENDTIME);
- // Make sure that the transformer is the
- // function we asked for
- Y.Assert.areEqual(self._x10transformer, rq.transformer);
+ var rq = new jarmon.RrdQuery(rrd, '');
+ var data = rq.getData(RRD_STARTTIME, RRD_ENDTIME, undefined, undefined, self._x10transformer);
// Real data goes 0,1,2,3...
// should be transformed to 0,10,20...
Y.Assert.areEqual(0, data.data[0][1]);