Using Externally Updated RRDs in Cacti

The intention is to remove the SNMP workaround described here to import mailgraph data into cacti. The method described below will work for any existing rrd file updated by some other process external to cacti as well.

Get RRDTool Info

First, we use the rrdtool info command to learn some details about our existing rrd file. My particular mailgraph configuration uses two rrd files:

$ rrdtool info /var/lib/mailgraph/mailgraph.rrd filename = "/var/lib/mailgraph/mailgraph.rrd" rrd_version = "0003" step = 60 last_update = 1308611880 ds[sent].type = "ABSOLUTE" ds[sent].minimal_heartbeat = 120 ds[sent].min = 0.0000000000e+00 ds[sent].max = NaN ds[sent].last_ds = "11" ds[sent].value = 0.0000000000e+00 ds[sent].unknown_sec = 0 ds[recv].type = "ABSOLUTE" ds[recv].minimal_heartbeat = 120 ds[recv].min = 0.0000000000e+00 ds[recv].max = NaN ds[recv].last_ds = "74" ds[recv].value = 0.0000000000e+00 ds[recv].unknown_sec = 0 ds[bounced].type = "ABSOLUTE" ds[bounced].minimal_heartbeat = 120 ds[bounced].min = 0.0000000000e+00 ds[bounced].max = NaN ds[bounced].last_ds = "0" ds[bounced].value = 0.0000000000e+00 ds[bounced].unknown_sec = 0 ds[rejected].type = "ABSOLUTE" ds[rejected].minimal_heartbeat = 120 ds[rejected].min = 0.0000000000e+00 ds[rejected].max = NaN ds[rejected].last_ds = "1" ds[rejected].value = 0.0000000000e+00 ds[rejected].unknown_sec = 0 rra[0].cf = "AVERAGE" rra[0].rows = 198 rra[0].cur_row = 28 rra[0].pdp_per_row = 8 [...] $ rrdtool info /var/lib/mailgraph/mailgraph_virus.rrd filename = "/var/lib/mailgraph/mailgraph_virus.rrd" rrd_version = "0003" step = 60 last_update = 1308672120 ds[virus].type = "ABSOLUTE" ds[virus].minimal_heartbeat = 120 ds[virus].min = 0.0000000000e+00 ds[virus].max = NaN ds[virus].last_ds = "0" ds[virus].value = 0.0000000000e+00 ds[virus].unknown_sec = 0 ds[spam].type = "ABSOLUTE" ds[spam].minimal_heartbeat = 120 ds[spam].min = 0.0000000000e+00 ds[spam].max = NaN ds[spam].last_ds = "40" ds[spam].value = 0.0000000000e+00 ds[spam].unknown_sec = 0 rra[0].cf = "AVERAGE" rra[0].rows = 198 rra[0].cur_row = 150 rra[0].pdp_per_row = 8 [...]

The data source names, ds[...], their type, min, max and heartbeat values will all be used for creating the Data Source Items on the Cacti Data Template. In this case:

rrdds steptypeminmaxheartbeat
mailgraph.rrdsent, recv, bounced, rejected 60ABSOLUTE0NaN120
mailgraph_virus.rrdvirus, spam

Note: The string NaN stands for *UNKNOWN* data. In the example it means that this RRD has no maximum values defined for any of its data sources.

Create Data Template

The Data Template will tell Cacti, how the data is stored within the rrd file. This is the way to tell cacti about all data sources and their properties. The purpose is twofold:

While the first goal is not needed in this context, the second one is crucial. So lets define a new Data Template. Goto Data Templates and Add a new one from the Cacti web interface:

SettingSample ValueNotes
Data Template NameMailgraph TemplateOr as desired.
Data Source Name Mailgraph Template DS Or as desired. You can use the keyword |host_description| in this field, which will be automatically substituted with the current host description.
Data Input Method None As this rrd file is updated externally, you must set the Data Input Method to None. You can add your own method by going to Data Input Methods.
Associated RRS'a Select All You need to associate the data source with at least one RRA so RRDTool knows how often and for how long to keep its data. You will almost always want to select all of these values however so you can render daily, weekly, monthly, and yearly graphs.
Step 60 Use the step value from rrdtool info above.
Data Source ActiveUncheck Box Uncheck the Data Source Active checkbox. This will prevent cacti from actually gathering data for this Data Template.

Add a Data Source Item for every data source name ds[...] e.g. sent, recv, bounced & rejected:
Internal Data Source Namesent You must use the existing data source name, ds[...], as retrieved from your rrd file.
Minimum Value0 Use the ds[...].min value from rrdtool info above. This is not required here, but is recommend.
Maximum Value10000 Use the ds[...].max value from rrdtool info above. This is not required here, but is recommend.
Data Source TypeABSOLUTE Use the ds[...].type value from rrdtool info above. This is not required here, but is recommend.
Heartbeat120 Use the ds[...].minimal_heartbeat value from rrdtool info above. This is not required here, but is recommend.

Create Data Sources

Usually, you would create the Data Sources and Graphs automatically using Create Graphs for this Host. But using this approach, cacti would enumerate and generate the needed rrd file(s) on its own. That is not wanted now. So, we make cacti generate all Data Sources stuff but accept our external rrd file name. This is accomplished by adding the Data Source manually from the Data Sources list.

SettingSample ValueNotes
Selected Data TemplateMailgraph Template Select the name of the Data Template created above.
HostLocalhost ( as desired.
Data Source Path/var/lib/mailgraph/mailgraph.rrd The full path to your external rrd file. If this resides in cacti's default ./rra directory, you may use <path_rra> for this. Remember, that the web server must have at least read access to the rrd file.

Create the Graph Template

I used the existing Mail Statistics - Messages Per Minute graph template from Curu Wong's Cacti graph template for mail server monitoring * installed earlier and modified it to match my rrds (named Mailgraph Graph and Mailgraph_Virus Graph). However, you can create your own.

Note: If you intend to combine data from multiple Data Sources (rrds) into one graph include them in your Graph Template.

Create New Graph

Create a new Graph from Graph Management.

SettingSample ValueNotes
Selected Graph TemplateMailgraph GraphOr as desired.
HostLocalhost ( as desired.

Supplemental Graph Template Data: For each Graph Item Field select the matching Data Source Item created in your Data Template.
Data Source [bounced]Mailgraph Template DS (bounced)Or as desired and repeat for each Data Source Item.