morellon / rrd-ffi

A ruby wrapper for librrd (rrdtool) using ffi.
MIT License
71 stars 20 forks source link

RRD::Base#fetch returns different values in the "time" column than 'rrdtool fetch' #29

Open dgutov opened 10 years ago

dgutov commented 10 years ago

Take this file:

require 'rrd'

rrd = RRD::Base.new("test.rrd")

time = Time.now.to_i / 300 * 300

rrd.create!(start: time, step: 5.minutes) do
  datasource "foo", type: :gauge, heartbeat: 10.minutes, min: 0.0, max: 1000000000.0
  archive :max, every: 5.minutes, during: (5*115200).minutes
end

rrd.update(time, 500)
rrd.update(time + 300, 600)
rrd.update(time + 600, 700)

puts "#{time} to #{time + 600}"

rrd.fetch!(:max, start: time, end: time + 600).each do |row|
  puts row.join("\t")
end

Compare its output with the command-line tool:

$ ruby test.rb
1392837600 to 1392838200
time    foo
1392837600  600.0
1392837900  700.0
1392838200  NaN
$ rrdtool fetch test.rrd MAX -s 1392837600 -e 1392838200
                            foo

1392837900: 6,0000000000e+02
1392838200: 7,0000000000e+02
1392838500: -nan

All time values returned by #fetch are smaller by the value of step.

hachpai commented 8 years ago

Have the same, all values are shifted by one.