[rrd-users] contributed shell code to compute VRULE/midnight

Pablo Sanchez pablo at blueoakdb.com
Tue Apr 28 20:13:55 CEST 2009


Howdy,

I looked around for a bit of code which computes `epoch seconds' for
midnight within a time bracket.  I didn't find one so I wrote a shell
function.  I thought I'd post it here for general consumption.  

I'm hoping attachments are allowed and if not, I'll re-post with it
in-line - may look awful.

The shell function relies on the `GNU date' function to compute
epoch-seconds for the start and end boundaries.  I may change that at
some point but for now, it works well in my situation.

Below is a sample call of the function where the start time is `-72
hours' from `now' and the end time is `now' - `db7093' is the VRULE
RGB color:

   compute_midnight "-72 hours" "now" "db7093"

If you wanted to generate the VRULE values from 72 hours ago to 24
hours ago, you'd call it as follows:

   compute_midnight "-72 hours" "-24 hours" "db7093"

The function will set a global shell variable $VRULE_GLOBAL which can
be used in your `rrdtool graph' call.  Below is an `rrdtool graph'
fragment:

   ...
   rrdtool graph $GRAPH_FILE_NAME \
      -s "$PERIOD" \
      --imgformat PNG \
      -w $WIDTH -h $HEIGHT \
      --title "Wind:  Gust and Speed in km/h, and direction colorized" \
      --lazy \
      --lower-limit 0 \
      --y-grid 5:1 \
      --no-minor \
      --color MGRID#c1c1c1 \
      $VRULE_GLOBAL \
      DEF:wind_speed=$WIND_SPEED_FILE:wind_speed:AVERAGE \
      DEF:gust_speed=$GUST_SPEED_FILE:gust_speed:AVERAGE \
      CDEF:wind_speed_kmh='wind_speed,1.852,*' \
      ...

Enjoy!
-- 
Pablo Sanchez - Blueoak Database Engineering, Inc
Ph:    819.459.1926      Fax:   760.860.5225 (US)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: midnight_func.sh
Type: application/x-shellscript
Size: 1608 bytes
Desc: not available
Url : http://lists.oetiker.ch/pipermail/rrd-users/attachments/20090428/1c547e06/attachment.bin 


More information about the rrd-users mailing list