summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Wall <richard@largo>2011-08-08 00:52:07 +0100
committerRichard Wall <richard@largo>2011-08-08 00:52:07 +0100
commit8501f32d8f67fd53bbc682ba9bfadd0ce5f39345 (patch)
treee8bd86b5ce6eca30f76e93fe67723c00a9a22624
parentd385e6ba4727b26c7e659f302544a1a8e117e76a (diff)
Add a transformer option to allow operations on the data from RRD files - eg Network octets * 8 > bits
-rw-r--r--docs/examples/jarmon_example_recipes.js4
-rw-r--r--jarmon/jarmon.js26
2 files changed, 23 insertions, 7 deletions
diff --git a/docs/examples/jarmon_example_recipes.js b/docs/examples/jarmon_example_recipes.js
index a2e822e..aa42d6f 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', 'B/s'],
- ['data/interface/if_octets-wlan0.rrd', 'rx', 'Receive', 'B/s']
+ ['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; }]
],
options: jQuery.extend(true, {}, jarmon.Chart.BASE_OPTIONS)
}
diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js
index 65ebedc..f6c3948 100644
--- a/jarmon/jarmon.js
+++ b/jarmon/jarmon.js
@@ -337,10 +337,17 @@ 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) {
+jarmon.RrdQuery = function(rrd, unit, transformer) {
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,
@@ -443,7 +450,7 @@ jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs,
var val;
var timestamp = startRowTime;
for(i=startRowIndex; i<endRowIndex; i++) {
- val = rra.getEl(i, dsIndex);
+ val = this.transformer(rra.getEl(i, dsIndex));
flotData.push([timestamp*1000.0, val]);
timestamp += step;
}
@@ -480,11 +487,19 @@ 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) {
+jarmon.RrdQueryRemote = function(url, unit, downloader, transformer) {
this.url = url;
this.unit = unit;
- this.downloader = downloader || jarmon.downloadBinary;
+ if(typeof(downloader) == 'undefined') {
+ this.downloader = jarmon.downloadBinary;
+ } else {
+ this.downloader = downloader;
+ }
+ this.transformer = transformer;
+
this.lastUpdate = 0;
this._download = null;
};
@@ -693,10 +708,11 @@ jarmon.Chart.prototype.setup = function() {
}
var label = recipe.data[j][2];
var unit = recipe.data[j][3];
+ var transformer = recipe.data[j][4];
if(typeof(dataDict[rrd]) === 'undefined') {
dataDict[rrd] = new jarmon.RrdQueryRemote(
- rrd, unit, this.downloader);
+ rrd, unit, this.downloader, transformer);
}
this.addData(label, new jarmon.RrdQueryDsProxy(dataDict[rrd], ds));
}