Setting Up Collectd to Use RRD

Posted on Fri 22 January 2016 in ops

There are a lot of blog posts out there about collectd can be enabled to output to RRD files, but nothing I found spelled out the actual steps.

I recommend reading all the docs you can find on both rrd and collectd, but to help spare your (and my) motivation, here are steps I followed to set it all up.

Step 1: Install

This is pretty straightforward:

# yum install collectd rrdtool rrdtool-perl collectd-rrdtool

What took me forever was figuring out that I needed collectd-rrdtool. This package solely installs the file /usr/lib64/collectd/rrdtool.so, which allows collectd to use RRDs as write targets.

Step 2: Configure

This is also pretty straightforward, except for collectd's slightly awkward commenting pattern in its /etc/collectd.conf.

Basically, one hash ("#") means you have that library (shared object) installed, but disabled. Two hashes ("##") means the library is not installed, nor enabled.

First, backup the original:

# cp /etc/collectd.conf /etc/collectd.conf.orig

Then, in /etc/collectd.conf, uncomment the line:

LoadPlugin rrdtool

Next, uncomment and configure the plugin (should be commented out in the same file). Change the values to whatever you like:

<Plugin rrdtool>
        DataDir "/var/lib/collectd/rrd"
        CreateFilesAsync false
        CacheTimeout 120
        CacheFlush   30
        WritesPerSecond 50
</Plugin>

Step 3: Test

Collectd has a couple of handy flags to test your config. From the CLI help:

-t              Test config and exit.
-T              Test plugin read and exit.

So, I like to run both separately to make sure everything is well-formed:

# collectd -t ; echo $?
0
# collectd -T ; echo $?
0

If you don't see zeroes as return codes, go back and verify nothing is obviously wrong (fat-fingered something). You can always restore from /etc/collectd.conf.orig you made in Step 2.

Step 4: Profit

Now you can just run collectd:

# collectd

For the paranoid crew among us (read: SREs/ops folks), you can check to ensure the process is running:

# ps aux | grep [c]ollectd
root     22855  0.2  0.0 899636  3768 ?        Ssl  Jan19  11:01 collectd

You can also poke around the directory you defined in the plugin block to see the RRD files themselves.

That's it!

Next step will be to hook up graphite to these rrd files and see what's happening with the system. That'll hopefully be in another blog post.

Quick Troubleshooting

"I don't see RRD files being generated."

Make sure you have collectd-rrdtool installed. Check for the existence of the file /usr/lib64/collectd/rrdtool.so.

If that file doesn't exist, use your system's package manager to determine what provides that file.

"The system log says 'Available write targets: [none]'"

Collectd is saying it can't write out to the system. Fix this either by enabling the rrdtool plugin (as outlined in this post), or one of the write_* plugins.