Skip to content

Instantly share code, notes, and snippets.

@polettix
Last active December 2, 2021 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polettix/96261795e95d6097ee8e614325775722 to your computer and use it in GitHub Desktop.
Save polettix/96261795e95d6097ee8e614325775722 to your computer and use it in GitHub Desktop.

Bug in rrdtool?

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:

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 availableand 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 something meaningful:

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 <tobi@oetiker.ch>
               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

#!/bin/sh
db=prova.rrd
start=1323302401
end=1637798399
step=604800
rows=520
cf=AVERAGE
height=200
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
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
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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment