summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cdbb3ff)
raw | patch | inline | side by side (parent: cdbb3ff)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Mon, 8 Dec 2008 16:07:27 +0000 (16:07 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Mon, 8 Dec 2008 16:07:27 +0000 (16:07 +0000) |
bindings/ruby/main.c | patch | blob | history | |
bindings/ruby/test.rb | patch | blob | history |
diff --git a/bindings/ruby/main.c b/bindings/ruby/main.c
index d18b905c356d21c71de67de3895847f88ed73bde..551203bf8626a10ce1159a113fb1275635646edf 100644 (file)
--- a/bindings/ruby/main.c
+++ b/bindings/ruby/main.c
string_arr_delete(a);
RRD_CHECK_ERROR
- return rb_funcall(rb_cTime, rb_intern("at"), 1, INT2FIX(last));
+ return rb_funcall(rb_cTime, rb_intern("at"), 1, UINT2NUM(last));
}
void Init_RRD(
diff --git a/bindings/ruby/test.rb b/bindings/ruby/test.rb
index 48533266b60b6a2f2a66a958a412c375bf7f9eb5..3d0b95f3cd6633fc089def79b98247e34de2406e 100755 (executable)
--- a/bindings/ruby/test.rb
+++ b/bindings/ruby/test.rb
name = "test"
rrd = "#{name}.rrd"
-start = Time.now.to_i
+start_time = Time.now.to_i
+end_time = start_time.to_i + 300 * 300
puts "creating #{rrd}"
RRD.create(
rrd,
- "--start", "#{start - 1}",
+ "--start", "#{start_time - 1}",
"--step", "300",
"DS:a:GAUGE:600:U:U",
"DS:b:GAUGE:600:U:U",
puts
puts "updating #{rrd}"
-start.to_i.step(start.to_i + 300 * 300, 300) { |i|
+start_time.step(end_time, 300) { |i|
RRD.update(rrd, "#{i}:#{rand(100)}:#{Math.sin(i / 800) * 50 + 50}")
}
puts
puts "fetching data from #{rrd}"
-(fstart, fend, data) = RRD.fetch(rrd, "--start", start.to_s, "--end", (start + 300 * 300).to_s, "AVERAGE")
+(fstart, fend, data) = RRD.fetch(rrd, "--start", start_time.to_s, "--end", end_time.to_s, "AVERAGE")
puts "got #{data.length} data points from #{fstart} to #{fend}"
puts
RRD.graph(
"#{name}.png",
"--title", " RubyRRD Demo",
- "--start", "#{start+3600}",
+ "--start", "#{start_time+3600}",
"--end", "start + 1000 min",
"--interlace",
"--imgformat", "PNG",
"LINE3:line#ff0000")
puts
+# last method test
+if end_time != RRD.last("#{rrd}").to_i
+ puts "last method expects #{Time.at(end_time)}."
+ puts " But #{RRD.last("#{rrd}")} returns."
+end
+puts
+
print "This script has created #{name}.png in the current directory\n";
print "This demonstrates the use of the TIME and % RPN operators\n";