summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorFrank Wuerthwein <fkw@ucsd.edu>2009-05-01 02:59:27 +0000
committerFrank Wuerthwein <fkw@ucsd.edu>2009-05-01 02:59:27 +0000
commit91765b1419fcb78da8c4625580a939c9a095e346 (patch)
tree5bc3e87678edabe1f5ad799be0c09b1b584c5384 /src/lib
parent8e135b5e98b463f6654a18e90fb360bca73381fe (diff)
Add rrdRRAStackFlotObj
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/rrdFlotSupport.js114
1 files changed, 114 insertions, 0 deletions
diff --git a/src/lib/rrdFlotSupport.js b/src/lib/rrdFlotSupport.js
index 2fd7268..634604c 100644
--- a/src/lib/rrdFlotSupport.js
+++ b/src/lib/rrdFlotSupport.js
@@ -88,7 +88,121 @@ function rrdRRA2FlotObj(rrd_file,rra_idx,ds_list,want_ds_labels,want_rounding) {
flot_el.label= ds_name;
}
out_el.data.push(flot_el);
+ } //end for ds_list_idx
+ return out_el;
+}
+
+// return an object with an array containing Flot elements
+// have a positive and a negative stack of DSes, plus DSes with no stacking
+// min and max are also returned
+// If one_undefined_enough==true, a whole stack is invalidated is a single element
+// of the stack is invalid
+function rrdRRAStackFlotObj(rrd_file,rra_idx,
+ ds_positive_stack_list,ds_negative_stack_list,ds_single_list,
+ want_ds_labels,want_rounding,one_undefined_enough) {
+ var rra=rrd_file.getRRA(rra_idx);
+ var rra_rows=rra.getNrRows();
+ var last_update=rrd_file.getLastUpdate();
+ var step=rra.getStep();
+ if (want_rounding!=false) {
+ // round last_update to step
+ // so that all elements are sync
+ last_update-=(last_update%step);
+ }
+ if (one_undefined_enough!=true) { // make sure it is a boolean
+ one_undefined_enough=false;
}
+
+ var first_el=last_update-(rra_rows-1)*step;
+
+ var out_el={data:[], min:first_el*1000.0, max:last_update*1000.0};
+
+ // first the stacks stack
+ var stack_els=[ds_positive_stack_list,ds_negative_stack_list];
+ for (stack_list_id in stack_els) {
+ var stack_list=stack_els[stack_list_id];
+ var tmp_flot_els=[];
+ var tmp_ds_ids=[];
+ var tmp_nr_ids=stack_list.length;
+ for (ds_list_idx in stack_list) {
+ var ds_id=stack_list[ds_list_idx];
+ var ds=rrd_file.getDS(ds_id);
+ var ds_name=ds.getName();
+ var ds_idx=ds.getIdx();
+ tmp_ds_ids.append(ds_idx); // getting this is expensive, call only once
+
+ // initialize
+ var flot_el={data:[]}
+ if (want_ds_labels!=false) {
+ var ds_name=ds.getName();
+ flot_el.label= ds_name;
+ }
+ tmp_flot_els.append(flot_el);
+ }
+
+ var timestamp=first_el;
+ for (var row=0;row<rra_rows;row++) {
+ var ds_vals=[];
+ var all_undef=true;
+ var all_def=true;
+ for (var id=0; id<tmp_nr_ids; id++) {
+ var ds_idx=tmp_ds_ids[id];
+ var el=rra.getEl(row,ds_idx);
+ if (el!=undefined) {
+ all_undef=false;
+ ds_val.push(el);
+ } else {
+ all_def=false;
+ ds_val.push(0);
+ }
+ } // end for id
+ if (!all_undef) { // if all undefined, skip
+ if (all_def || (!one_undefined_enough)) {
+ // this is a valid column, do the math
+ for (var id=1; id<tmp_nr_ids; id++) {
+ ds_val[id]+=ds_val[id-1]; // both positive and negative stack use a +, negative stack assumes negative values
+ }
+ // fill the flot data
+ for (var id=0; id<tmp_nr_ids; id++) {
+ tmp_flot_els[id].data.push([timestamp*1000.0,ds_val[id]]);
+ }
+ }
+ } // end if
+
+ timestamp+=step;
+ } // end for row
+
+ // put flot data in output object
+ // reverse order so higher numbers are behind
+ for (var id=0; id<tmp_nr_ids; id++) {
+ out_el.data.push(tmp_flot_els[tmp_nr_ids-id-1]);
+ }
+ } //end for stack_list_id
+
+ for (var row=0;row<rra_rows;row++) {
+ for (ds_list_idx in ds_list) {
+ var ds_id=ds_list[ds_list_idx];
+ var ds=rrd_file.getDS(ds_id);
+ var ds_name=ds.getName();
+ var ds_idx=ds.getIdx();
+
+ var timestamp=first_el;
+ var flot_series=[];
+
+ var el=rra.getEl(row,ds_idx);
+ if (el!=undefined) {
+ flot_series.push([timestamp*1000.0,el]);
+ }
+ timestamp+=step;
+ } // end for
+
+ var flot_el={data:flot_series};
+ if (want_ds_labels!=false) {
+ var ds_name=ds.getName();
+ flot_el.label= ds_name;
+ }
+ out_el.data.push(flot_el);
+ } //end for row
return out_el;
}