2 # $Id: test.rb,v 1.2 2002/10/22 17:34:00 miles Exp $
3 # Driver does not carry cash.
5 $: << '/scratch/rrd12build/lib/ruby/1.8/i386-linux/'
11 start_time = Time.now.to_i
12 end_time = start_time.to_i + 300 * 300
14 puts "creating #{rrd}"
17 "--start", "#{start_time - 1}",
21 "RRA:AVERAGE:0.5:1:300")
24 puts "updating #{rrd}"
25 start_time.step(end_time, 300) { |i|
26 RRD.update(rrd, "#{i}:#{rand(100)}:#{Math.sin(i / 800) * 50 + 50}")
30 puts "fetching data from #{rrd}"
31 (fstart, fend, data) = RRD.fetch(rrd, "--start", start_time.to_s, "--end", end_time.to_s, "AVERAGE")
32 puts "got #{data.length} data points from #{fstart} to #{fend}"
35 puts "generating graph #{name}.png"
38 "--title", " RubyRRD Demo",
39 "--start", "#{start_time+3600}",
40 "--end", "start + 1000 min",
44 "DEF:a=#{rrd}:a:AVERAGE",
45 "DEF:b=#{rrd}:b:AVERAGE",
46 "CDEF:line=TIME,2400,%,300,LT,a,UNKN,IF",
48 "AREA:line#0022e9:alpha",
53 if end_time != RRD.last("#{rrd}").to_i
54 puts "last method expects #{Time.at(end_time)}."
55 puts " But #{RRD.last("#{rrd}")} returns."
59 print "This script has created #{name}.png in the current directory\n";
60 print "This demonstrates the use of the TIME and % RPN operators\n";