[rrd-users] DS:var:ABSOLUTE:... simulation
john at ziar.net
john at ziar.net
Wed Jan 19 13:21:18 MET 2005
Below a script that demonstrates an "ABSOLUTE" counter for counting e-mail
messages (spam in this case). I posted it, because I couldn't find any
satisfactory examples of ABSOLUTE and as a chance to get
feedback from others and possibly help others.
It seems to work fine, but I'm not an experienced rrdtool user, so if
other users have tips or find bugs please respond.
## Start this script in am empty dir (just in case because it creates
## some files) and then open simulate.html in your favorite browser.
PERIOD=$(($DAY * $GENERATIONS))
## Create self refreshing html-page
cat > simulation.html << EOF
<META HTTP-EQUIV="Refresh" CONTENT="5; URL=simulation.html">
<P>The graph above shows a simulation
of the number of spam messages (red bars) I
receive each day. The short blue stacked bars
are false negatives, meaning messages
that were not filtered out by the spam filter,
but manually identified as spam later on*.
<P>This simulation uses a 10 second "day"
for the obvious reason that a real time
simulation would take too long. The script as a
whole is not useable in this form**.
You'll have to split it up in a create, update
and a graph piece. Set DAY to 86400
(seconds). The current number of generations
would result in about 2 Months of data.
Make sure you manually expand the shell variables
or put them in a separate script
and include that script in all the pieces.
(Too include a script use this statement:
". /scriptpath/scriptname" without the quotes.)
Btw: <I>bash</I> is needed, because
of the calculations in the script. HTH for those
people that are too lazy, like me,
to read the <I>excellent</I> documentation that
comes with rrdtool. You really
should read it, but I posted this because I
couldn't find any satisfactory examples
of "ABSOLUTE" counters.
<BR>* These are moved to a specific folder and
then automatically collected by a
script, which feeds them to the spam filter to
learn from. The same script updates rrdb.
<BR>** This was first developed as a simulation to
find out if every was working and put to use in the
real world later. 24 Hour debug cycles aren't a
lot of fun!
## Create rrdb
rrdtool create sim.rrd --start 'N' --step $DAY \
## Can update only once per second. Avoid writing too soon.
while [ 1 ] ;
## Feed simulated data to the rrdb
MSG=$((RANDOM % 4))
if [ $MSG == 0 ] ; then
UNK=$((RANDOM % 2))
## Allow pausing updates for a while, eg.: > stop; sleep 10; rm -f
stop if [ -f stop ] ; then
rrdtool update sim.rrd N:$MSG:$UNK
rrdtool graph tmpgraph.gif --start -$PERIOD \
AREA:real#FF0000:"Number of spam messages" \
STACK:unrl#0000FF:"Number of false negatives"
## To prevent reading the gif while it's being written:
mv -f tmpgraph.gif simgraph.gif
## Sleep one more second. Note that the whole loop
## will take more, because it's relatively resource
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help mailto:rrd-users-request at list.ee.ethz.ch?subject=help
More information about the rrd-users