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
1=== modified file 'docs/examples/jarmon_example_recipes.js'
2--- docs/examples/jarmon_example_recipes.js 2011-09-10 10:52:52 +0000
3+++ docs/examples/jarmon_example_recipes.js 2013-06-20 23:01:24 +0000
4@@ -54,8 +54,8 @@
5 'interface': {
6 title: 'Wlan0 Throughput',
7 data: [
8- ['data/interface/if_octets-wlan0.rrd', 'tx', 'Transmit', 'bit/s', function (v) { return v*8; }],
9- ['data/interface/if_octets-wlan0.rrd', 'rx', 'Receive', 'bit/s', function (v) { return v*8; }]
10+ ['data/interface-wlan0/if_octets.rrd', 'tx', 'Transmit', 'bit/s', function (v) { return -v*8; }],
11+ ['data/interface-wlan0/if_octets.rrd', 'rx', 'Receive', 'bit/s', function (v) { return v*8; }]
12 ],
13 options: jQuery.extend(true, {}, jarmon.Chart.BASE_OPTIONS)
14 },
15
16=== modified file 'jarmon/jarmon.js'
17--- jarmon/jarmon.js 2011-09-11 09:29:53 +0000
18+++ jarmon/jarmon.js 2013-06-20 23:01:24 +0000
19@@ -337,21 +337,14 @@
20 * @constructor
21 * @param rrd {Object} A javascriptrrd.RRDFile
22 * @param unit {String} The unit symbol for this data series
23- * @param transformer {Function} A callable which performs a
24- * tranfsformation of the values returned from the RRD file.
25 **/
26-jarmon.RrdQuery = function(rrd, unit, transformer) {
27+jarmon.RrdQuery = function(rrd, unit) {
28 this.rrd = rrd;
29 this.unit = unit;
30- if(typeof(transformer) !== 'undefined') {
31- this.transformer = transformer;
32- } else {
33- this.transformer = function(v) {return v;};
34- }
35 };
36
37 jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs,
38- dsId, cfName) {
39+ dsId, cfName, transformer) {
40 /**
41 * Generate a Flot compatible data object containing rows between start and
42 * end time. The rows are taken from the first RRA whose data spans the
43@@ -363,6 +356,8 @@
44 * @param dsId {Variant} identifier of the RRD datasource (string or number)
45 * @param cfName {String} The name of an RRD consolidation function (CF)
46 * eg AVERAGE, MIN, MAX
47+ * @param transformer {Function} A callable which performs a
48+ * tranfsformation of the values returned from the RRD file.
49 * @return {Object} A Flot compatible data series
50 * eg label: '', data: [], unit: ''
51 **/
52@@ -392,6 +387,10 @@
53 cfName = 'AVERAGE';
54 }
55
56+ if(typeof(transformer) === 'undefined') {
57+ transformer = function(v) {return v;};
58+ }
59+
60 var rra, step, rraRowCount, lastRowTime, firstRowTime;
61
62 for(var i=0; i<this.rrd.getNrRRAs(); i++) {
63@@ -450,7 +449,7 @@
64 var val;
65 var timestamp = startRowTime;
66 for(i=startRowIndex; i<endRowIndex; i++) {
67- val = this.transformer(rra.getEl(i, dsIndex));
68+ val = transformer(rra.getEl(i, dsIndex));
69 flotData.push([timestamp*1000.0, val]);
70 timestamp += step;
71 }
72@@ -487,10 +486,8 @@
73 * @param unit {String} The unit suffix of this data eg 'bit/sec'
74 * @param downloader {Function} A callable which returns a Deferred and calls
75 * back with a javascriptrrd.BinaryFile when it has downloaded.
76- * @param transformer {Function} A callable which performs a
77- * tranfsformation of the values returned from the RRD file.
78 **/
79-jarmon.RrdQueryRemote = function(url, unit, downloader, transformer) {
80+jarmon.RrdQueryRemote = function(url, unit, downloader) {
81 this.url = url;
82 this.unit = unit;
83 if(typeof(downloader) == 'undefined') {
84@@ -498,7 +495,6 @@
85 } else {
86 this.downloader = downloader;
87 }
88- this.transformer = transformer;
89
90 this.lastUpdate = 0;
91 this._download = null;
92@@ -529,7 +525,7 @@
93 var rrd = new RRDFile(res);
94 self.lastUpdate = rrd.getLastUpdate();
95
96- var rq = new jarmon.RrdQuery(rrd, self.unit, self.transformer);
97+ var rq = new jarmon.RrdQuery(rrd, self.unit);
98 try {
99 ret.resolve(rq[methodName].apply(rq, args));
100 } catch(e) {
101@@ -544,7 +540,7 @@
102
103
104 jarmon.RrdQueryRemote.prototype.getData = function(startTime, endTime,
105- dsId, cfName) {
106+ dsId, cfName, transformer) {
107 /**
108 * Return a Flot compatible data series asynchronously.
109 *
110@@ -552,12 +548,16 @@
111 * @param startTime {Number} The start timestamp
112 * @param endTime {Number} The end timestamp
113 * @param dsId {Variant} identifier of the RRD datasource (string or number)
114+ * @param cfName {String} The name of an RRD consolidation function (CF)
115+ * eg AVERAGE, MIN, MAX
116+ * @param transformer {Function} A callable which performs a
117+ * tranfsformation of the values returned from the RRD file.
118 * @return {Object} A Deferred which calls back with a flot data series.
119 **/
120 if(this.lastUpdate < endTime/1000) {
121 this._download = null;
122 }
123- return this._callRemote('getData', [startTime, endTime, dsId, cfName]);
124+ return this._callRemote('getData', [startTime, endTime, dsId, cfName, transformer]);
125 };
126
127
128@@ -581,10 +581,11 @@
129 * @param rrdQuery {Object} An RrdQueryRemote instance
130 * @param dsId {Variant} identifier of the RRD datasource (string or number)
131 **/
132-jarmon.RrdQueryDsProxy = function(rrdQuery, dsId) {
133+jarmon.RrdQueryDsProxy = function(rrdQuery, dsId, transformer) {
134 this.rrdQuery = rrdQuery;
135 this.dsId = dsId;
136 this.unit = rrdQuery.unit;
137+ this.transformer = transformer;
138 };
139
140 jarmon.RrdQueryDsProxy.prototype.getData = function(startTime, endTime) {
141@@ -596,7 +597,7 @@
142 * @param endTime {Number} A unix timestamp marking the start time
143 * @return {Object} A Deferred which calls back with a flot data series.
144 **/
145- return this.rrdQuery.getData(startTime, endTime, this.dsId);
146+ return this.rrdQuery.getData(startTime, endTime, this.dsId, undefined, this.transformer);
147 };
148
149
150@@ -648,7 +649,7 @@
151 };
152 var si = 0;
153 while(true) {
154- if( Math.pow(1000, si+1)*0.9 > axis.max ) {
155+ if( Math.pow(1000, si+1)*0.9 > (axis.max - axis.min) ) {
156 break;
157 }
158 si++;
159@@ -658,7 +659,7 @@
160 var maxVal = axis.max/Math.pow(1000, si);
161
162 var stepSizes = [0.01, 0.05, 0.1, 0.25, 0.5,
163- 1, 5, 10, 25, 50, 100, 250];
164+ 1, 2, 5, 10, 20, 25, 50, 100, 250];
165 var realStep = (maxVal - minVal)/5.0;
166
167 var stepSize, decimalPlaces = 0;
168@@ -712,9 +713,9 @@
169
170 if(typeof(dataDict[rrd]) === 'undefined') {
171 dataDict[rrd] = new jarmon.RrdQueryRemote(
172- rrd, unit, this.downloader, transformer);
173+ rrd, unit, this.downloader);
174 }
175- this.addData(label, new jarmon.RrdQueryDsProxy(dataDict[rrd], ds));
176+ this.addData(label, new jarmon.RrdQueryDsProxy(dataDict[rrd], ds, transformer));
177 }
178 };
179

Subscribers

People subscribed via source and target branches

to all changes: