Skip to content

Instantly share code, notes, and snippets.

@twolfson
Last active May 1, 2023 21:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save twolfson/ad3bb967d37dd140382d to your computer and use it in GitHub Desktop.
Save twolfson/ad3bb967d37dd140382d to your computer and use it in GitHub Desktop.
Drawing graphs from collectd data via rrdtool

We are exploring capturing local laptop metrics as research for applying collectd recordings on our server (so we can get weekly emails).

The rrdtool syntax is non-obvious but we are making progress.

The apt package for collectd collects information into a few buckets (e.g. 10 second average, 50 second average, etc). We can see this information at a high level via rrdtool info:

rrdtool info /var/lib/collectd/rrd/Euclid/battery-0/charge.rrd
# step = 10
# last_update = 1454486292
rra[0].cf = "AVERAGE"
rra[0].rows = 1200
rra[0].cur_row = 246
rra[0].pdp_per_row = 1 # second per group
rra[0].xff = 1.0000000000e-01
rra[0].cdp_prep[0].value = NaN
rra[0].cdp_prep[0].unknown_datapoints = 0
# ...
rra[3].pdp_per_row = 7 # seconds per group

It's plausible to receive a NaN value for a row. This is due to missed data.

To view a dump of data in an XML format, use:

rrdtool dump /var/lib/collectd/rrd/Euclid/battery-0/charge.rrd

To draw a graph, we need to specify a variable and then a line to draw said variable.

Reference link: http://mailman.verplant.org/pipermail/collectd/2011-April/004470.html

Here is an example graph:

rrdtool graph output.png --start=1454485842 --end=1454485942 \
  DEF:a=/var/lib/collectd/rrd/Euclid/entropy/entropy.rrd:value:AVERAGE \
  LINE2:a#FF000

We can also use relative timings (e.g. -120 for 120 seconds ago):

rrdtool graph output.png --start=-120 --end=-0 \
  DEF:a=/var/lib/collectd/rrd/Euclid/entropy/entropy.rrd:value:AVERAGE \
  LINE2:a#FF000

The DEF's value (i.e. excluding a= which sets name of graph variable) has 3 parts:

/var/lib/collectd/rrd/Euclid/entropy/entropy.rrd:value:AVERAGE
  • /var/lib/collectd/rrd/Euclid/entropy/entropy.rrd is the source file
  • value is the key used for ds
    • When using rrdtool info we can see ds[value].index at the top
    • For metrics like disk, this can be ds[read] and ds[write] which are 2 separate metrics would be :read:AVERAGE and :write:AVERAGE in a graph
      • To view all possible variations provided by collectd, look at the types.db (set in /etc/collectd/collectd.conf via TypesDB)
      • For example, cat /usr/share/collectd/types.db
  • AVERAGE is the metric we want to view, we typically have MIN, MAX, and AVERAGE set but they will be visible in info as well

We aren't currently sure how to change the step used during graphing.

@rutsky
Copy link

rutsky commented May 1, 2023

Thanks for sharing this!

A small nitpick: the shared above commands produce empty graphs for me with RRDtool 1.7.2 due to missing last character of the color specification, instead of:

rrdtool graph output.png --start=1454485842 --end=1454485942 \
  DEF:a=/var/lib/collectd/rrd/Euclid/entropy/entropy.rrd:value:AVERAGE \
  LINE2:a#FF000

should be one more zero zero at the end of FF000 for red color:

rrdtool graph output.png --start=1454485842 --end=1454485942 \
  DEF:a=/var/lib/collectd/rrd/Euclid/entropy/entropy.rrd:value:AVERAGE \
  LINE2:a#FF0000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment