From 8501f32d8f67fd53bbc682ba9bfadd0ce5f39345 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Mon, 8 Aug 2011 00:52:07 +0100 Subject: Add a transformer option to allow operations on the data from RRD files - eg Network octets * 8 > bits --- docs/examples/jarmon_example_recipes.js | 4 ++-- jarmon/jarmon.js | 26 +++++++++++++++++++++----- 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