rrdtool-1.x icon indicating copy to clipboard operation
rrdtool-1.x copied to clipboard

Wrong areas in generated graph

Open polettix opened this issue 3 years ago • 5 comments

Describe the bug In certain cases, the generated graph with stacked areas is wrong.

To Reproduce Consider the RRD database file prova.rrd. It contains two data sources:

  • total, always reporting about 4 M of "something" (kbyte RAM)
  • used, showing an increase from about 200 k to about 2 M over a 10-years period.

There are aggregation at multiple levels, one over the span of 10 years.

The stand-alone graph for used is the following, showing the increase over time:

used standalone

The graph above was generated with the following command:

db=prova.rrd
start=1323302401
end=1637798399
step=604800
rows=520
cf=AVERAGE
height=200


rrdtool graph prova-used.png \
   --start $start \
   --end $end \
   --step $step \
   --width $rows \
   --height $height \
   --disable-rrdtool-tag \
   --title "prova" \
   --vertical-label bytes \
   --lower-limit 0 \
   "DEF:used=$db:used:$cf" \
   "DEF:total=$db:total:$cf" \
   "CDEF:available=total,used,-" \
   AREA:used#770000#CC0000:used\\c:STACK

From total and used we can calculate how much is available and graph it:

rrdtool graph prova-available.png \
   --start $start \
   --end $end \
   --step $step \
   --width $rows \
   --height $height \
   --disable-rrdtool-tag \
   --title "prova" \
   --vertical-label bytes \
   --lower-limit 0 \
   "DEF:used=$db:used:$cf" \
   "DEF:total=$db:total:$cf" \
   "CDEF:available=total,used,-" \
   AREA:available#007700#00CC00:available\\c:STACK

This is the result, showing a decrease in time:

available standalone

It is possible to stack the two, here we have used over available and everything goes fine:

rrdtool graph prova-used-over-available.png \
   --start $start \
   --end $end \
   --step $step \
   --width $rows \
   --height $height \
   --disable-rrdtool-tag \
   --title "prova" \
   --vertical-label bytes \
   --lower-limit 0 \
   "DEF:used=$db:used:$cf" \
   "DEF:total=$db:total:$cf" \
   "CDEF:available=total,used,-" \
   AREA:available#007700#00CC00:available\\c:STACK \
   AREA:used#770000#CC0000:used\\c:STACK

used over available

On the other hand, stacking available over user does not produce the expected result:

rrdtool graph prova-available-over-user.png \
   --start $start \
   --end $end \
   --step $step \
   --width $rows \
   --height $height \
   --disable-rrdtool-tag \
   --title "prova" \
   --vertical-label bytes \
   --lower-limit 0 \
   "DEF:used=$db:used:$cf" \
   "DEF:total=$db:total:$cf" \
   "CDEF:available=total,used,-" \
   AREA:used#770000#CC0000:used\\c:STACK \
   AREA:available#007700#00CC00:available\\c:STACK

available over used

This was tested with:

rrdtool -v
RRDtool 1.7.2  Copyright by Tobias Oetiker <[email protected]>
               Compiled Jul 28 2021 15:46:00

Usage: rrdtool [options] command command_options
Valid commands: create, update, updatev, graph, graphv,  dump, restore,
		last, lastupdate, first, info, list, fetch, tune,
		resize, xport, flushcached

RRDtool is distributed under the Terms of the GNU General
Public License Version 2. (www.gnu.org/copyleft/gpl.html)

For more information read the RRD manpages

UPDATE

It seems that the bug depends on shading with a gradient. This:

rrdtool graph prova-available-over-user.png \
   --start $start \
   --end $end \
   --step $step \
   --width $rows \
   --height $height \
   --disable-rrdtool-tag \
   --title "prova" \
   --vertical-label bytes \
   --lower-limit 0 \
   "DEF:used=$db:used:$cf" \
   "DEF:total=$db:total:$cf" \
   "CDEF:available=total,used,-" \
   AREA:used#CC0000:used\\c:STACK \
   AREA:available#00CC00:available\\c:STACK

produces the expected graph:

available over used

polettix avatar Dec 02 '21 00:12 polettix

hmmm interesting ... there is one odd thing in your code, the first item drawn, should not be STACK. since there is nothing to stack it onto ... can you try if this makes a difference ?

oetiker avatar Dec 03 '21 07:12 oetiker

Hi! Thanks for getting back on this.

I know there's no difference because the STACK in the first entry was not there in the original command line that made me suspicious:

   rrdtool graph "$target/$root-memory-$cf-$step$suffix.png" \
      --start $start \
      --end $end \
      --step $step \
      --width $rows \
      --height $height \
      --disable-rrdtool-tag \
      --title "$root - memory" \
      --vertical-label bytes \
      --lower-limit 0 \
      "DEF:unavailable=$db:memory_used:$cf" \
      "DEF:buffers=$db:memory_buffers:$cf" \
      "DEF:cached=$db:memory_cached:$cf" \
      "DEF:shared=$db:memory_shared:$cf" \
      "DEF:total=$db:memory_total:$cf" \
      "CDEF:unavailable_=unavailable,buffers,-,cached,-,shared,-,1024,*" \
      "CDEF:available_=total,1024,*,unavailable_,-" \
      AREA:unavailable_#770000#CC0000:busy \
      AREA:available_#007700#00CC00:available\\c:STACK

I then simplified the input data to restrict the error and the STACK-on-first-layer remained out of lazyness of trying different layers ordering.

There's another thing that is a bit fishy in this otherwise correct picture with the increasing feature on top:

fishy picture

The gradient seems to be applied only to the top band (which goes from dark red to bright red from left to right) but not in the part that fills the part underneath, which is always dark red. I suspect it might have to do with the same issue.

Moreover, it seems that gradient is applied top-to-bottom in the standalone cases, but in the stacked cases it's sometimes applied left-to-right:

fishy second picture

polettix avatar Dec 03 '21 09:12 polettix

I remember when we got that patch to introduce gradients, and I wondered what the benefit was, since the gradients do not provide any additional information ... now with them not even working properly, this is even worse :(

oetiker avatar Dec 03 '21 09:12 oetiker

It might be that it just plays wrong with stacked stuff and, short of fixing the bug (I can try to take a look), it might be disabled for that case. At the end of the day, it seems that I've been the only one to use it so far, so it should not be too big of a loss!

polettix avatar Dec 03 '21 12:12 polettix

if you could look into why this is happening, it would be great! My guess is that the person who implemented the gradient code was not aware of the stacking function (and I did not catch it when reviewing).

oetiker avatar Dec 03 '21 13:12 oetiker