Search code examples
python-2.7python-3.xrrdtoolrrd

rrdtool's fetch doesnt show single point


I used rrdtool python extension for save data in rrd:

## Creating db. 
rrdtool.create(rrd_file,
                 '--step', '2',
                   'DS:%s:GAUGE:4:U:U' % DSNAME,
                   'RRA:AVERAGE:0,5:1:288',
                   )
value = 23
for i in range(4):

    rrdtool.update('/home/way/workspace/RrdDaemon/test', "%s:%s" % (datetime_2_sec(str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))), str(value)))
    sleep(2) 

Cycle worked 4 times, and i want to get 4 points. But i get 3 only:

1460382646: -nan
1460382648: 2,3000000000e+01
1460382650: 2,3000000000e+01
1460382652: 2,3000000000e+01
1460382654: -nan

I tried to change heartbeat, step , xff - nothing helps me. Now i try with 1 iteration:

for i in range(1):

    rrdtool.update('/home/way/workspace/RrdDaemon/test', "%s:%s" % (datetime_2_sec(str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))), str(value)))

Timestamp : 1460385371

Result:

1460385368: -nan
1460385370: -nan
1460385372: -nan

sudo rrdtool info test:

filename = "test"
rrd_version = "0003"
step = 2
last_update = 1460385371
header_size = 584
ds[ds0].index = 0
ds[ds0].type = "GAUGE"
ds[ds0].minimal_heartbeat = 3
ds[ds0].min = NaN
ds[ds0].max = NaN
ds[ds0].last_ds = "23"
ds[ds0].value = NaN
ds[ds0].unknown_sec = 1
rra[0].cf = "AVERAGE"
rra[0].rows = 288
rra[0].cur_row = 65
rra[0].pdp_per_row = 1
rra[0].xff = 0,0000000000e+00
rra[0].cdp_prep[0].value = NaN
rra[0].cdp_prep[0].unknown_datapoints = 0

Do i make anything wrong or its the way which rrd working for? Thank you.


Solution

  • The problem you are running into is that you are crossing from an unknown state into a known state. The minimal_heartbeat defines the maximum interval permissible between two updates, for rrdtool to consider the time in between the updates to contain valid data.

    This also means that the first update after a period of unknown data only serves to indicate the time when the data becomes known again ... the next update (within the interval defined by the minimal_heartbeat).