Merge lp:~richardw/jarmon/independent-ds-transformers-1188220 into lp:jarmon

Proposed by Richard Wall
Status: Needs review
Proposed branch: lp:~richardw/jarmon/independent-ds-transformers-1188220
Merge into: lp:jarmon
Diff against target: 178 lines (+26/-25)
2 files modified
docs/examples/jarmon_example_recipes.js (+2/-2)
jarmon/jarmon.js (+24/-23)
To merge this branch: bzr merge lp:~richardw/jarmon/independent-ds-transformers-1188220
Reviewer Review Type Date Requested Status
Petr P (community) functional testing Approve
Richard Wall functional testing Needs Resubmitting
Review via email: mp+169468@code.launchpad.net

Description of the change

I hacked things around a bit.

RrdDsProxy now accepts transformer and passes as an argument to RrdQuery/RrdQueryRemote.getData

I'm not really happy with this but it does have the desired effect (at least for me with Fedora/Chrome/collectd5)

When I eventually get round to releasing another Jarmon, I might update / simplify all this RRD download and parsing code.

Anyway, please try out jarmon.js from this branch and let me know if it fixes things for you.

To post a comment you must log in.
Revision history for this message
Petr P (trubus) wrote :

I just tested it on our setup - it has the desired effect, I'm almost completely satisfied, but other thing turned up.

When the resulting graph is mostly negative (let's imagine Y-axis has max = 100 and min = -1000000, in other words, there is a lot more TX than RX for example), it sets the prefix incorrectly (according to the max value only) and it generates lot of steps.

I propose using the greater value of axis.min and axis.max in "this.options.yaxis.ticks" instead of axis.max only. Other possibility is to use difference (axis.max - axis.min), but that seems a bit more tricky to me.

Other than that it works fine, thanks a lot!

Peter

Revision history for this message
Petr P (trubus) wrote :

Just to be a bit more precise - I don't propose using greater value, but the value that is farther away from zero :)

Revision history for this message
Petr P (trubus) wrote :

It seems a quick fix, could you add this small change? Then I'll approve :)

652c652
< if( Math.pow(1000, si+1)*0.9 > axis.max ) {
---
> if( Math.pow(1000, si+1)*0.9 > axis.max && -(Math.pow(1000, si+1))*0.9 < axis.min) {

78. By Richard Wall

add extra condition suggested by trubus to take into account negative y axis

79. By Richard Wall

choose best si based on total length of y axis - negative to positive. Also add a few more step sizes to graphs without any ticks.

Revision history for this message
Richard Wall (richardw) wrote :

I applied your diff and it does give properly spaced negative ticks, but I couldn't clearly understand why.
I came up with a slightly different condition which seems to have the same effect and which I think I understand.

See what you think and let me know if it works for you.

I also added a couple of extra step sizes because (on my system ) I was graphs with only two tick labels.

Thanks again for testing.

-RichardW.

review: Needs Resubmitting (functional testing)
Revision history for this message
Petr P (trubus) wrote :

Works as expected, great job!

review: Approve (functional testing)

Unmerged revisions

79. By Richard Wall

choose best si based on total length of y axis - negative to positive. Also add a few more step sizes to graphs without any ticks.

78. By Richard Wall

add extra condition suggested by trubus to take into account negative y axis

77. By Richard Wall

hack things around to allow independent ds transformers, even when they are in the same RRD file

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'docs/examples/jarmon_example_recipes.js'
--- docs/examples/jarmon_example_recipes.js 2011-09-10 10:52:52 +0000
+++ docs/examples/jarmon_example_recipes.js 2013-06-20 23:01:24 +0000
@@ -54,8 +54,8 @@
54 'interface': {54 'interface': {
55 title: 'Wlan0 Throughput',55 title: 'Wlan0 Throughput',
56 data: [56 data: [
57 ['data/interface/if_octets-wlan0.rrd', 'tx', 'Transmit', 'bit/s', function (v) { return v*8; }],57 ['data/interface-wlan0/if_octets.rrd', 'tx', 'Transmit', 'bit/s', function (v) { return -v*8; }],
58 ['data/interface/if_octets-wlan0.rrd', 'rx', 'Receive', 'bit/s', function (v) { return v*8; }]58 ['data/interface-wlan0/if_octets.rrd', 'rx', 'Receive', 'bit/s', function (v) { return v*8; }]
59 ],59 ],
60 options: jQuery.extend(true, {}, jarmon.Chart.BASE_OPTIONS)60 options: jQuery.extend(true, {}, jarmon.Chart.BASE_OPTIONS)
61 },61 },
6262
=== modified file 'jarmon/jarmon.js'
--- jarmon/jarmon.js 2011-09-11 09:29:53 +0000
+++ jarmon/jarmon.js 2013-06-20 23:01:24 +0000
@@ -337,21 +337,14 @@
337 * @constructor337 * @constructor
338 * @param rrd {Object} A javascriptrrd.RRDFile338 * @param rrd {Object} A javascriptrrd.RRDFile
339 * @param unit {String} The unit symbol for this data series339 * @param unit {String} The unit symbol for this data series
340 * @param transformer {Function} A callable which performs a
341 * tranfsformation of the values returned from the RRD file.
342 **/340 **/
343jarmon.RrdQuery = function(rrd, unit, transformer) {341jarmon.RrdQuery = function(rrd, unit) {
344 this.rrd = rrd;342 this.rrd = rrd;
345 this.unit = unit;343 this.unit = unit;
346 if(typeof(transformer) !== 'undefined') {
347 this.transformer = transformer;
348 } else {
349 this.transformer = function(v) {return v;};
350 }
351};344};
352345
353jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs,346jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs,
354 dsId, cfName) {347 dsId, cfName, transformer) {
355 /**348 /**
356 * Generate a Flot compatible data object containing rows between start and349 * Generate a Flot compatible data object containing rows between start and
357 * end time. The rows are taken from the first RRA whose data spans the350 * end time. The rows are taken from the first RRA whose data spans the
@@ -363,6 +356,8 @@
363 * @param dsId {Variant} identifier of the RRD datasource (string or number)356 * @param dsId {Variant} identifier of the RRD datasource (string or number)
364 * @param cfName {String} The name of an RRD consolidation function (CF)357 * @param cfName {String} The name of an RRD consolidation function (CF)
365 * eg AVERAGE, MIN, MAX358 * eg AVERAGE, MIN, MAX
359 * @param transformer {Function} A callable which performs a
360 * tranfsformation of the values returned from the RRD file.
366 * @return {Object} A Flot compatible data series361 * @return {Object} A Flot compatible data series
367 * eg label: '', data: [], unit: ''362 * eg label: '', data: [], unit: ''
368 **/363 **/
@@ -392,6 +387,10 @@
392 cfName = 'AVERAGE';387 cfName = 'AVERAGE';
393 }388 }
394389
390 if(typeof(transformer) === 'undefined') {
391 transformer = function(v) {return v;};
392 }
393
395 var rra, step, rraRowCount, lastRowTime, firstRowTime;394 var rra, step, rraRowCount, lastRowTime, firstRowTime;
396395
397 for(var i=0; i<this.rrd.getNrRRAs(); i++) {396 for(var i=0; i<this.rrd.getNrRRAs(); i++) {
@@ -450,7 +449,7 @@
450 var val;449 var val;
451 var timestamp = startRowTime;450 var timestamp = startRowTime;
452 for(i=startRowIndex; i<endRowIndex; i++) {451 for(i=startRowIndex; i<endRowIndex; i++) {
453 val = this.transformer(rra.getEl(i, dsIndex));452 val = transformer(rra.getEl(i, dsIndex));
454 flotData.push([timestamp*1000.0, val]);453 flotData.push([timestamp*1000.0, val]);
455 timestamp += step;454 timestamp += step;
456 }455 }
@@ -487,10 +486,8 @@
487 * @param unit {String} The unit suffix of this data eg 'bit/sec'486 * @param unit {String} The unit suffix of this data eg 'bit/sec'
488 * @param downloader {Function} A callable which returns a Deferred and calls487 * @param downloader {Function} A callable which returns a Deferred and calls
489 * back with a javascriptrrd.BinaryFile when it has downloaded.488 * back with a javascriptrrd.BinaryFile when it has downloaded.
490 * @param transformer {Function} A callable which performs a
491 * tranfsformation of the values returned from the RRD file.
492 **/489 **/
493jarmon.RrdQueryRemote = function(url, unit, downloader, transformer) {490jarmon.RrdQueryRemote = function(url, unit, downloader) {
494 this.url = url;491 this.url = url;
495 this.unit = unit;492 this.unit = unit;
496 if(typeof(downloader) == 'undefined') {493 if(typeof(downloader) == 'undefined') {
@@ -498,7 +495,6 @@
498 } else {495 } else {
499 this.downloader = downloader;496 this.downloader = downloader;
500 }497 }
501 this.transformer = transformer;
502498
503 this.lastUpdate = 0;499 this.lastUpdate = 0;
504 this._download = null;500 this._download = null;
@@ -529,7 +525,7 @@
529 var rrd = new RRDFile(res);525 var rrd = new RRDFile(res);
530 self.lastUpdate = rrd.getLastUpdate();526 self.lastUpdate = rrd.getLastUpdate();
531527
532 var rq = new jarmon.RrdQuery(rrd, self.unit, self.transformer);528 var rq = new jarmon.RrdQuery(rrd, self.unit);
533 try {529 try {
534 ret.resolve(rq[methodName].apply(rq, args));530 ret.resolve(rq[methodName].apply(rq, args));
535 } catch(e) {531 } catch(e) {
@@ -544,7 +540,7 @@
544540
545541
546jarmon.RrdQueryRemote.prototype.getData = function(startTime, endTime,542jarmon.RrdQueryRemote.prototype.getData = function(startTime, endTime,
547 dsId, cfName) {543 dsId, cfName, transformer) {
548 /**544 /**
549 * Return a Flot compatible data series asynchronously.545 * Return a Flot compatible data series asynchronously.
550 *546 *
@@ -552,12 +548,16 @@
552 * @param startTime {Number} The start timestamp548 * @param startTime {Number} The start timestamp
553 * @param endTime {Number} The end timestamp549 * @param endTime {Number} The end timestamp
554 * @param dsId {Variant} identifier of the RRD datasource (string or number)550 * @param dsId {Variant} identifier of the RRD datasource (string or number)
551 * @param cfName {String} The name of an RRD consolidation function (CF)
552 * eg AVERAGE, MIN, MAX
553 * @param transformer {Function} A callable which performs a
554 * tranfsformation of the values returned from the RRD file.
555 * @return {Object} A Deferred which calls back with a flot data series.555 * @return {Object} A Deferred which calls back with a flot data series.
556 **/556 **/
557 if(this.lastUpdate < endTime/1000) {557 if(this.lastUpdate < endTime/1000) {
558 this._download = null;558 this._download = null;
559 }559 }
560 return this._callRemote('getData', [startTime, endTime, dsId, cfName]);560 return this._callRemote('getData', [startTime, endTime, dsId, cfName, transformer]);
561};561};
562562
563563
@@ -581,10 +581,11 @@
581 * @param rrdQuery {Object} An RrdQueryRemote instance581 * @param rrdQuery {Object} An RrdQueryRemote instance
582 * @param dsId {Variant} identifier of the RRD datasource (string or number)582 * @param dsId {Variant} identifier of the RRD datasource (string or number)
583 **/583 **/
584jarmon.RrdQueryDsProxy = function(rrdQuery, dsId) {584jarmon.RrdQueryDsProxy = function(rrdQuery, dsId, transformer) {
585 this.rrdQuery = rrdQuery;585 this.rrdQuery = rrdQuery;
586 this.dsId = dsId;586 this.dsId = dsId;
587 this.unit = rrdQuery.unit;587 this.unit = rrdQuery.unit;
588 this.transformer = transformer;
588};589};
589590
590jarmon.RrdQueryDsProxy.prototype.getData = function(startTime, endTime) {591jarmon.RrdQueryDsProxy.prototype.getData = function(startTime, endTime) {
@@ -596,7 +597,7 @@
596 * @param endTime {Number} A unix timestamp marking the start time597 * @param endTime {Number} A unix timestamp marking the start time
597 * @return {Object} A Deferred which calls back with a flot data series.598 * @return {Object} A Deferred which calls back with a flot data series.
598 **/599 **/
599 return this.rrdQuery.getData(startTime, endTime, this.dsId);600 return this.rrdQuery.getData(startTime, endTime, this.dsId, undefined, this.transformer);
600};601};
601602
602603
@@ -648,7 +649,7 @@
648 };649 };
649 var si = 0;650 var si = 0;
650 while(true) {651 while(true) {
651 if( Math.pow(1000, si+1)*0.9 > axis.max ) {652 if( Math.pow(1000, si+1)*0.9 > (axis.max - axis.min) ) {
652 break;653 break;
653 }654 }
654 si++;655 si++;
@@ -658,7 +659,7 @@
658 var maxVal = axis.max/Math.pow(1000, si);659 var maxVal = axis.max/Math.pow(1000, si);
659660
660 var stepSizes = [0.01, 0.05, 0.1, 0.25, 0.5,661 var stepSizes = [0.01, 0.05, 0.1, 0.25, 0.5,
661 1, 5, 10, 25, 50, 100, 250];662 1, 2, 5, 10, 20, 25, 50, 100, 250];
662 var realStep = (maxVal - minVal)/5.0;663 var realStep = (maxVal - minVal)/5.0;
663664
664 var stepSize, decimalPlaces = 0;665 var stepSize, decimalPlaces = 0;
@@ -712,9 +713,9 @@
712713
713 if(typeof(dataDict[rrd]) === 'undefined') {714 if(typeof(dataDict[rrd]) === 'undefined') {
714 dataDict[rrd] = new jarmon.RrdQueryRemote(715 dataDict[rrd] = new jarmon.RrdQueryRemote(
715 rrd, unit, this.downloader, transformer);716 rrd, unit, this.downloader);
716 }717 }
717 this.addData(label, new jarmon.RrdQueryDsProxy(dataDict[rrd], ds));718 this.addData(label, new jarmon.RrdQueryDsProxy(dataDict[rrd], ds, transformer));
718 }719 }
719};720};
720721

Subscribers

People subscribed via source and target branches

to all changes: