[rrd-users] HOWTO: average office hours only

Alex van den Bogaerdt alex at ergens.op.HET.NET
Sun Jan 28 23:19:10 MET 2001


Howto ignore traffic outside office hours.

RRDtool is a rather flexible tool.  You can use RPN to do various
calculations/modifications on gathered statisctics.  Tutorials are
available for both RRDtool and for RPN, see the documentation dir
in your source distrinution or check the RRDtool website.

Even after reading the tutorials it may not always be clear how to
use them.  This is why I write this little document.  Experiment
with it and enjoy.

This document may contain bugs.  Use at your own risc etcetera.
I would like to be notified about any error you find, I also
welcome suggestions for other experiments.
mailto:alex at ergens.op.Het.Net


Ignoring certain time ranges is not hard.  All we have to do is to
compare the time at which the sample was taken with a range of
valid times.

Let's assume working hours are from 09:00 until 17:00.  This means
that any statistics valid before 09:00, or after 17:00, should be
ignored.  The interval which ends at 09:00 exactly is about time
before 09:00.  Thus, any interval ending before or at 09:00 should
be ignored.  The interval which ends at 17:00 exactly is the last
interval that should stay, any interval thereafter should be ignored
to.  The interval we're interested in is 09:00:01 to 17:00:00.

RRDtool knows nothing about local time (aka Wall Clock time), it
works with the time since the unix epoch.  This is the number of
seconds since januari 1st, 1970, 00:00:00 without considering
time zones.  This means that we should do some calculations.
Several tools (such as GNU date and bc) can help you with this but
it is also possible to do it by hand.  In this simplified example
I only look at the hours, not at the days.  This means that I do
not need to look at the real unix-epoch-time, I can calculate
the modulo 86400 from it.  This leaves us only with the number of
seconds in the day.

If you live one hour east of Greenwich, as I do, you can just use
the numbers that I calculate here.  If not, make sure you use the
correct numbers!

Midnight UTC modulo 86400 results in 0.  Our time is one hour
ahead so local time 01:00 mod 86400 results in 0.
09:00 % 86400 should therefore result in (8*3600 = ) 28800 and
17:00 % 86400 should result in (28800 + 8*3600 = ) 57600.

If a sample is valid just after 09:00, it should be included. If
a sample is valid before 09:00 or after 17:00, it should not be
included.  Exactly 09:00 should also be excluded as this defines
the interval from (09:00-stepsize upto 09:00)

This gives us a range of 28801 to 57600.  If the sample is outside
this range, we make it unknown.  RTFM and convert this to RPN:

We use:
TIME   to push the time
LIMIT  to enforce the valid time range
UN     to test for unknown values
UNKN   to insert an unknown value
IF     to make a decision
As input for the RPN we use var "var1" which can be a DEF or CDEF.

Calculate the modulo 86400 from the timestamp:
TIME,86400,%          <--- we'll call the outcome of this "t"
t,28801,57600,LIMIT   <--- results in UNKNOWN if outside the range, "l"
l,UN                  <--- results in "1" for l == unknown, "0" if not
u,UNKN,var1,IF        <--- results in "unknown" or the value of "var1"

Fill in the variables and end up with:

CDEF:var1a=TIME,86400,%,28801,57600,LIMIT,UN,UNKN,var1,IF

This will make the values outside the valid hours to become unknown.
When doing stuff like printing averages these unknown values will
be discarded and you will therefore end up with the average valid
during working hours.

The example is kept simple (I think it is hard enough for first timers)
and this imposes a few problems:
- If you live in a time zone where midnight UTC is actually during
  working hours, you'll have to invert the decision and the limits
  Example for a time zone 9 hours west of UTC:
     TIME,86400,%,7200,64800,LIMIT,UN,var1,UNKN,IF
- During summer time, the wall clock time shifts but the unix-clock
  doesn't.  That means that you should shift the boundaries too.
- Currently no effort is made do exclude saturday nor sunday. This
  can be done using the same method but now with a modulo of 604800

-- 
   __________________________________________________________________
 / alex at slot.hollandcasino.nl                  alex at ergens.op.het.net \
| work                                                         private |
| My employer is capable of speaking therefore I speak only for myself |
+----------------------------------------------------------------------+
| Technical questions sent directly to me will be nuked. Use the list. | 
+----------------------------------------------------------------------+
| http://faq.mrtg.org/                                                 |
| http://rrdtool.eu.org  --> tutorial                                  |
+----------------------------------------------------------------------+

--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-users mailing list