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";