[rrd-users] Re: CDEFs and graduated colors

Allan Houston ahouston at blueyonder.co.uk
Thu May 1 15:26:06 MEST 2003

> It would be nice if Dave Beaumont would post his scripts for generating
> As a matter of fact, It would be nice if the code were available for all
> the gallery images.  They would server as great examples.

Joao asked for some example graphs so here they are -

One thing I noticed was that using stacked CDEFs made for a very "blocky"
graph - so what I've tried to do is increase the granularity by using say
200 CDEFs of 0.5 instead of stacking 100 with a value of 1.

My perl code is truly awful, so I apologise in advance ;o)

# granularity = the number of points per percent that we'll
# graph to. i.e. value of 2 means that graphs will be rounded up to the
# nearest half percent.

my $granularity = 2;


 push @ds_arg_rrd,"DEF:ds=$rrd_file:$ds:AVERAGE";
 push @ds_arg_rrd,"CDEF:dsutil=ds,$speed_ref->{ds},/,100,*";

 # speed_ref is a pre-populated hash with the speed of the int

 foreach $f  (0.. ($granularity*100) )
  $f_factor=$f / $granularity;
  push @ds_arg_rrd,

 push @ds_arg_rrd,"AREA:ds_flame_0$flame[0]";

 foreach $f  (0 .. ($granularity*100) )

  # @flame is an array of graduated colors,
  # 255 elements big.
  # we divide by 254 to ensure that we dont
  # index a value of out the arrays bounds.

  $f_factor=$f / ($granularity*100/254);
  push @ds_arg_rrd,

 my $err=RRDs::error;
 print "ERROR while updating $rrd_file: $err\n" if

 sub flame_colors()

        # This sub creates the @flame array by incrementing red
        # while decrementing blue. Green stays constant

        foreach $i (0..255)
                $r = $i;
                $b = 255 - $i;
                $g = '00';

                if ($r<=15) {$r_hex='0';} else {$r_hex='';}
                if ($b<=15) {$b_hex='0';} else {$b_hex='';}
                $g_hex =$g;

                push @flame,$color;

Allan Houston

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