This page covers configuration and usage of RRDtool.
RRDtool is a command-line tool, not a daemon. Configuration happens through command-line arguments when creating and updating RRD files.
rrdtool create temperature.rrd \
--step 300 \
DS:temp:GAUGE:600:-273.15:5000 \
RRA:AVERAGE:0.5:1:288 \
RRA:AVERAGE:0.5:6:336 \
RRA:AVERAGE:0.5:24:700 \
RRA:AVERAGE:0.5:288:775
| Parameter | Description |
|---|---|
--step 300 |
Collect data every 300 seconds (5 minutes) |
DS:temp:GAUGE |
Data Source named “temp”, type GAUGE |
600 |
Heartbeat (seconds before data is unknown) |
-273.15:5000 |
Min/Max values (absolute zero to 5000) |
RRA:AVERAGE |
Round-Robin Archive using AVERAGE |
0.5 |
XFilesFactor (50% of data must be known) |
1:288 |
1 sample per PDP, 288 rows (1 day at 5min) |
| Type | Description | Example |
|---|---|---|
GAUGE |
Absolute value | Temperature, memory usage |
COUNTER |
Continuously increasing | Bytes transmitted |
DERIVE |
Like COUNTER, can decrease | Rate calculations |
ABSOLUTE |
Counter resets after read | Per-interval counts |
# 1 day of 5-minute samples (288 samples)
RRA:AVERAGE:0.5:1:288
# 1 week of 30-minute averages (336 samples)
RRA:AVERAGE:0.5:6:336
# 1 month of 2-hour averages (372 samples)
RRA:AVERAGE:0.5:24:372
# 1 year of daily averages (365 samples)
RRA:AVERAGE:0.5:288:365
rrdtool update temperature.rrd N:23.5
rrdtool update temperature.rrd \
1609459200:22.1 \
1609459500:22.3 \
1609459800:22.5
#!/bin/bash
TEMP=$(sensors | grep "Core 0" | awk '{print $3}' | tr -d '+°C')
rrdtool update /var/rrd/temperature.rrd N:$TEMP
rrdtool fetch temperature.rrd AVERAGE \
--start -1d \
--end now
rrdtool fetch temperature.rrd AVERAGE \
--start -1d \
--resolution 300 \
| sed -e 's/ nan / 0 /g'
rrdtool graph /var/www/temperature.png \
--start -1d \
--end now \
--title "Temperature (Last 24 Hours)" \
--vertical-label "Degrees Celsius" \
DEF:temp=temperature.rrd:temp:AVERAGE \
LINE2:temp#0000FF:"Temperature"
rrdtool graph /var/www/temperature_advanced.png \
--start -7d \
--end now \
--width 800 \
--height 200 \
--title "Temperature (Last 7 Days)" \
--vertical-label "Degrees Celsius" \
--color BACK#FFFFFF \
--color CANVAS#FFFFFF \
DEF:temp=temperature.rrd:temp:AVERAGE \
AREA:temp#0000FF80:"Temperature" \
LINE2:temp#0000FF \
GPRINT:temp:AVERAGE:"Average\:%.2lf%s" \
GPRINT:temp:MIN:"Min\:%.2lf%s" \
GPRINT:temp:MAX:"Max\:%.2lf%s" \
GPRINT:temp:LAST:"Current\:%.2lf%s\n"
# Collect temperature every 5 minutes
*/5 * * * * /usr/local/bin/collect_temp.sh
# Generate daily graph at midnight
0 0 * * * /usr/local/bin/generate_daily_graph.sh
# Generate weekly graph on Sundays
0 0 * * 0 /usr/local/bin/generate_weekly_graph.sh
# In collectd.conf
LoadPlugin rrdtool
<Plugin rrdtool>
DataDir "/var/lib/collectd/rrd"
StepSize 10
HeartBeat 20
XFF 0.1
</Plugin>
#!/bin/bash
# collect_metrics.sh
RRD_DIR="/var/rrd"
TIMESTAMP=$(date +%s)
# CPU usage
CPU=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}')
rrdtool update $RRD_DIR/cpu.rrd $TIMESTAMP:$CPU
# Memory usage
MEM=$(free | grep Mem | awk '{print $3/$2 * 100.0}')
rrdtool update $RRD_DIR/memory.rrd $TIMESTAMP:$MEM
# Disk usage
DISK=$(df / | tail -1 | awk '{print $5}' | tr -d '%')
rrdtool update $RRD_DIR/disk.rrd $TIMESTAMP:$DISK
# Check RRD file info
rrdtool info temperature.rrd
# View RRD structure
rrdtool dump temperature.rrd | head -50
# Test graph generation
rrdtool graph /tmp/test.png --start -1h DEF:temp=temperature.rrd:temp:AVERAGE AREA:temp#FF0000:"Test"