I am storing information from temperature sensors in a rrd. I want to retrieve the values from a given timespan in php.
For data from the last 2 hours, I use this:
rrd_fetch($file, array("AVERAGE", "-s -2h"));
This is working. However, the last value that I can get via rrd_lastupdate($file);
is not found in the data from rrd_fetch. How can I adapt my code so that the rrd_fetch call also contains data from the last update?
The rrd is setup like this in Python:
rrdtool.create(
RRD_FILE,
"--start", "now",
"--step", "300",
"RRA:AVERAGE:0.5:1:288",
"RRA:AVERAGE:0.5:12:336",
"RRA:AVERAGE:0.5:288:365",
"DS:temp:GAUGE:600:0:50")
And updated like this in a while loop:
while True:
temp = get_value()
data_rrd = "N:{0}".format(temp)
try:
rrdtool.update(file, data_rrd)
except:
print("Failed to write to RRD.")
time.sleep(300)