summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 609630f)
raw | patch | inline | side by side (parent: 609630f)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Fri, 5 Feb 2010 18:28:41 +0000 (18:28 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Fri, 5 Feb 2010 18:28:41 +0000 (18:28 +0000) |
bindings/ruby/CHANGES | patch | blob | history | |
bindings/ruby/main.c | patch | blob | history | |
bindings/ruby/test.rb | patch | blob | history |
diff --git a/bindings/ruby/CHANGES b/bindings/ruby/CHANGES
index c84ff2933ec68d7e5b95b5c8079db18a77649f01..9e01ed52b44c28de0b60f3c3f6ef195addc552ab 100644 (file)
--- a/bindings/ruby/CHANGES
+++ b/bindings/ruby/CHANGES
+2010-02-05 Pavel Pachkovskij (Azati corp.)
+ add rrd_xport
+ update test.rb with rrd_xport example
+
2006-07-25 Loïs Lherbier
add y_min and y_max parameters to rrd_graph
update test.rb to send only strings to RRD.fetch
diff --git a/bindings/ruby/main.c b/bindings/ruby/main.c
index 355625f9c2ec5d87b6124b1ec05cca1243decfdf..6fe6a35116b6b5957e54ecc39de2131569d09926 100644 (file)
--- a/bindings/ruby/main.c
+++ b/bindings/ruby/main.c
return rb_funcall(rb_cTime, rb_intern("at"), 1, UINT2NUM(last));
}
+VALUE rb_rrd_xport(
+ VALUE self,
+ VALUE args)
+{
+ string_arr a;
+ unsigned long i, j, k, step, col_cnt;
+ int xxsize;
+ rrd_value_t *data;
+ char **legend_v;
+ VALUE legend, result, rdata;
+ time_t start, end;
+
+ a = string_arr_new(args);
+ rrd_xport(a.len, a.strings, &xxsize, &start, &end, &step, &col_cnt, &legend_v, &data);
+ string_arr_delete(a);
+
+ RRD_CHECK_ERROR;
+
+ legend = rb_ary_new();
+ for (i = 0; i < col_cnt; i++) {
+ rb_ary_push(legend, rb_str_new2(legend_v[i]));
+ free(legend_v[i]);
+ }
+ free(legend_v);
+
+ k = 0;
+ rdata = rb_ary_new();
+ for (i = start; i <= end; i += step) {
+ VALUE line = rb_ary_new2(col_cnt);
+ for (j = 0; j < col_cnt; j++) {
+ rb_ary_store(line, j, rb_float_new(data[k]));
+ k++;
+ }
+ rb_ary_push(rdata, line);
+ }
+ free(data);
+
+ result = rb_ary_new2(6);
+ rb_ary_store(result, 0, INT2FIX(start));
+ rb_ary_store(result, 1, INT2FIX(end));
+ rb_ary_store(result, 2, INT2FIX(step));
+ rb_ary_store(result, 3, INT2FIX(col_cnt));
+ rb_ary_store(result, 4, legend);
+ rb_ary_store(result, 5, rdata);
+ return result;
+}
+
void Init_RRD(
)
{
rb_define_module_function(mRRD, "info", rb_rrd_info, -2);
rb_define_module_function(mRRD, "updatev", rb_rrd_updatev, -2);
rb_define_module_function(mRRD, "graphv", rb_rrd_graphv, -2);
+ rb_define_module_function(mRRD, "xport", rb_rrd_xport, -2);
}
diff --git a/bindings/ruby/test.rb b/bindings/ruby/test.rb
index 3d0b95f3cd6633fc089def79b98247e34de2406e..2ca502de913661e9ce36d07642028fe5e94be851 100755 (executable)
--- a/bindings/ruby/test.rb
+++ b/bindings/ruby/test.rb
end
puts
+# xport method test
+puts "xporting data from #{rrd}"
+(fstart,fend,step,col,legend,data)=RRD.xport(
+ "--start", start_time.to_s,
+ "--end", (start_time + 300 * 300).to_s,
+ "--step", 10.to_s,
+ "DEF:A=#{rrd}:a:AVERAGE",
+ "DEF:B=#{rrd}:b:AVERAGE",
+ "XPORT:A:a",
+ "XPORT:B:b")
+puts "Xported #{col} columns(#{legend.join(", ")}) with #{data.length} rows from #{fstart} to #{fend} and step #{step}\n"
+
print "This script has created #{name}.png in the current directory\n";
print "This demonstrates the use of the TIME and % RPN operators\n";