Print time of recording for LAST value

2019-08-13 11:06发布

I want to be able to see when the last value in an RRD was recorded.

I have the following to print the last recorded value, which works ok.

DEF:temp1=temperatures2.rrd:iliakos:AVERAGE
GPRINT:temp1:LAST:"Current\:%8.1lf %s"

I have found in the documentation :strftime and I tried:

 GPRINT:temp1:LAST:"%H\:%M":strftime 

but got:

 graph.sh: line 21: GPRINT:temp1:LAST:%H\:%M:strftime: command not found

I read more carefully the docs and it mentions that strftime is applied on VDEF so I tried the following:

VDEF:vtemp1=temp1,AVERAGE
GPRINT:vtemp1:LAST:"%H\:%M":strftime  

but again got:

ERROR: I don't understand ':%H\:%M:strftime' in command: 'GPRINT:vtemp1:LAST:%H\:%M:strftime'

I thought that values in an rrd have an associated recorded timestamp, as we can see from a dump. How can we access this access this timestamp and use it in a graph commmand?

Thanks

标签: rrdtool
1条回答
Melony?
2楼-- · 2019-08-13 11:57

When rrdtool graph needs data from the rrd file, it simply states a time range and in response it gets the data delivered. Regardless if the rrd file actually holds has data for that time range or note. If no data is available the data handed to the graph component consists of NaNs.

So the question you can answer at best is, the last time 'known' data has been written into the rrd file.

You attempt using the strftime function is good, but you need to jump through another hoop. You need to prepare some data that grows over time, for all the points in time when data was available. This is what the CDEF accomplishes. You can then use VDEF to determine the maximum count value and retrieve the timestamp associated with that value.

rrdtool graph x.png \
   DEF:data=x.rrd:x:AVERAGE \
   CDEF:count=data,UN,UNKN,COUNT,IF \
   VDEF:last=count,MAXIMUM \
   GPRINT:last:%H\:%M\:%S:strftime
查看更多
登录 后发表回答