8.8 KiB
RRDtool Specific Features
When a graph shows the wrong value, trace one measurement from collection to display. The RRDtool data-source type determines what gets stored. A DEF reads a series from an archive. A CDEF calculates a value at each point in time. A VDEF summarizes the series over the displayed interval. A GPRINT formats a result in the graph legend.
For example, store used and free disk space as gauges. Use a CDEF to draw the percentage used, a VDEF to find the peak percentage and a GPRINT to label it. A working example appears below.
Choose a data-source type
Set the type on the data-source item in the Data Source Template. Match it to what the collector returns. For example, an interface that reports total octets needs a rate calculation, while a sensor that already reports octets per second needs a gauge.
| Type | What RRDtool does with the reading |
|---|---|
| GAUGE | Stores the measured level, such as bytes free, degrees or the number of active sessions. |
| COUNTER | Converts differences between successive readings of a monotonically increasing integer counter into a per-second rate. A decrease is treated as a possible counter wrap. Choose a realistic maximum rate to help reject reset spikes. |
| DERIVE | Converts the signed difference between successive readings into a per-second rate. For a counter that can reset, a minimum of zero rejects negative rates. |
| ABSOLUTE | Divides each reading by the elapsed time. Use it when each reading counts events since the previous read and the device then resets the count. |
| DCOUNTER | Computes a rate from a floating-point counter. RRDtool detects its increasing or decreasing direction. Cacti offers this type with RRDtool 1.5 or later. |
| DDERIVE | Computes a signed rate of change from floating-point readings. Cacti offers this type with RRDtool 1.5 or later. |
| COMPUTE | Unsupported in Cacti's standard data-template creation workflow. RRDtool requires an expression such as used,free,+. Cacti's create command supplies heartbeat, minimum and maximum in that position. For a display calculation, use a CDEF. |
A heartbeat sets the longest acceptable interval between readings. A gap longer than the heartbeat, or a calculated value outside the configured bounds, produces unknown data. When troubleshooting a gap, check the polling interval, heartbeat and units of the stored value. For data-source syntax and archive types, including Holt-Winters forecasting in RRDtool itself, see the rrdcreate.
Build a graph calculation in Cacti
- Calculate a series. Open Console > Presets > CDEFs, add a named
CDEF and save it. Add its items in evaluation order. To convert octets per
second to bits per second, select the special data source Current Graph
Item Data Source, enter the custom string
8, then add the multiplication operator. Assign that CDEF to the graph item that draws the traffic series. - Summarize the interval. Open Console > Presets > VDEFs to create or inspect a summary such as a maximum or a percentile. Apply the VDEF to a graph item that uses the summary. Zooming into a shorter interval can change the result.
- Label the result. Under Console > Presets > GPRINTs, add a preset,
give it a name and enter a format such as
%6.1lffor one decimal place. On the graph template, add a GPRINT item for the measurement, select the preset and enter its legend text. Apply the same unit conversion as the plotted series if the legend should report the same units.
The editor uses reverse Polish notation. In CURRENT_DATA_SOURCE,8,*,
the operator consumes the two preceding values. Cacti resolves the special
data source when it builds the graph command. In a raw RRDtool command, use
the name assigned by a DEF. For the editor fields, see
CDEFs, VDEFs and GPRINT Presets.
Total or count graph items
Cacti builds its all-source and similar-source calculations from AREA, STACK
and LINE1 through LINE3 items that reference a data source. It looks up a
DEF for the consolidation function used by the calculation. A measurement
that appears only in a GPRINT or a comment contributes nothing. For a
similar-source calculation, associate the calculating item with the RRDtool
data-source name you want to match, such as traffic_in.
Suppose two interfaces report inbound rates of 10 and 20 octets/s. The graph also draws an outbound rate of 3 octets/s and draws the first inbound series a second time. With known samples and the same consolidation function, these are the contributions from those four items.
| Special data source | Values included | Sum | Count |
|---|---|---|---|
| All Data Sources, exclude duplicates | 10, 20, 3 | 33 | 3 |
| All Data Sources, include duplicates | 10, 20, 3, 10 | 43 | 4 |
All Similar Data Sources, exclude duplicates, matching traffic_in |
10, 20 | 30 | 2 |
All Similar Data Sources, include duplicates, matching traffic_in |
10, 20, 10 | 40 | 3 |
To calculate the average of the two distinct inbound sources, build the CDEF
SIMILAR_DATA_SOURCES_NODUPS,COUNT_SIMILAR_DS_NODUPS,/. For the values
above, the result is 15 octets/s. Check which items qualify, especially if
you attach the calculation to another drawing item. Repeating a source can
change an include-duplicates total.
Other special data sources expose the current item's configured minimum, maximum and polling interval, or the graph's configured lower and upper limits. For the observed maximum over the displayed interval, use a VDEF.
Graph disk use as a percentage
In a Cacti graph template that draws only disk used and disk free, add each
source as a LINE item. Give those two items the CDEF CURRENT_DATA_SOURCE,0,*
and color None so the raw byte values do not set the percentage scale.
Add an AREA for the used source and apply
CURRENT_DATA_SOURCE,ALL_DATA_SOURCES_NODUPS,/,100,*. The denominator now
contains used and free once each. Adding a third distinct plotted source would
change the denominator. A missing reading or zero capacity can leave a gap.
To see the calculation independently, run these commands in a new, empty directory with RRDtool on your path. The two gauges use the same units. Each update is five minutes apart, starting just after midnight UTC on 1 January 2025.
rrdtool create disk.rrd --start 1735689600 --step 300 \
DS:used:GAUGE:600:0:U DS:free:GAUGE:600:0:U RRA:AVERAGE:0.5:1:24
rrdtool update disk.rrd \
1735689900:40:60 1735690200:44:56 1735690500:50:50 \
1735690800:48:52 1735691100:55:45 1735691400:60:40 \
1735691700:58:42 1735692000:65:35 1735692300:72:28 \
1735692600:68:32 1735692900:66:34 1735693200:70:30
Give each input a DEF name. The CDEF below computes
100 × used / (used + free) at each step. The two VDEFs take the last and
largest values. A literal colon in GPRINT legend text is escaped as \:.
TZ=UTC LC_ALL=C rrdtool graph disk-use.png \
--start 1735689600 --end 1735693200 --step 300 \
--width 540 --height 160 --title 'Disk use' --vertical-label 'Percent used' \
--lower-limit 0 --upper-limit 100 --rigid \
DEF:used=disk.rrd:used:AVERAGE DEF:free=disk.rrd:free:AVERAGE \
'CDEF:pct=used,used,free,+,/,100,*' \
VDEF:lastpct=pct,LAST VDEF:peakpct=pct,MAXIMUM \
'AREA:pct#99CBBE:Used' 'LINE2:pct#126653' \
'GPRINT:lastpct:Last\: %.0lf%%' 'GPRINT:peakpct:Peak\: %.0lf%%'
The legend should read Last: 70% and Peak: 72%. In Cacti, open the graph in Console > Management > Graphs and enable graph debug mode to inspect the DEFs, calculation and legend arguments for your own graph.
Shade days, nights and weekends
To mark a time window behind a series, put a translucent AREA before the
measurement in the graph item order. Use a CDEF that returns infinity inside
the window and an unknown value outside it. LTIME uses the local time of
the RRDtool process. Include a reference to the current series so RRDtool
can determine the time step.
| Window | Cacti CDEF expression |
|---|---|
| Day, 08:00 up to 18:00 | LTIME,86400,%,28800,GE,LTIME,86400,%,64800,LT,*,INF,CURRENT_DATA_SOURCE,UNKN,*,IF |
| Night, 18:00 up to 08:00 | LTIME,86400,%,28800,LT,LTIME,86400,%,64800,GE,+,INF,CURRENT_DATA_SOURCE,UNKN,*,IF |
| Weekend, Saturday and Sunday | LTIME,604800,%,172800,GE,LTIME,604800,%,345600,LT,*,INF,CURRENT_DATA_SOURCE,UNKN,*,IF |
The weekend offsets count from Thursday, the weekday of the Unix epoch. Check a known Saturday in the graph's time zone when adapting this expression. For the full operator list, see the RRDtool RPN.
Copyright (c) 2004-2026 The Cacti Group

