X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=bindings%2Fruby%2Ftest.rb;h=3d0b95f3cd6633fc089def79b98247e34de2406e;hb=377af7db1b7a7eef72d891328bb36a209ed23790;hp=3cdcca6177d6687e8a15b9731011fa697ebc9f8a;hpb=f718153b987ad9b2fbba81b1db248e0fda83a57e;p=rrdtool.git diff --git a/bindings/ruby/test.rb b/bindings/ruby/test.rb index 3cdcca6..3d0b95f 100755 --- a/bindings/ruby/test.rb +++ b/bindings/ruby/test.rb @@ -2,16 +2,19 @@ # $Id: test.rb,v 1.2 2002/10/22 17:34:00 miles Exp $ # Driver does not carry cash. +$: << '/scratch/rrd12build/lib/ruby/1.8/i386-linux/' + require "RRD" 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", @@ -19,13 +22,13 @@ RRD.create( 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 @@ -33,8 +36,8 @@ puts "generating graph #{name}.png" RRD.graph( "#{name}.png", "--title", " RubyRRD Demo", - "--start", "#{start} + 1 h", - "--end", "#{start} + 1000 min", + "--start", "#{start_time+3600}", + "--end", "start + 1000 min", "--interlace", "--imgformat", "PNG", "--width=450", @@ -46,5 +49,12 @@ RRD.graph( "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";