First steps with collectd
This short and incomplete article should guide the novice user through the process of getting collectd to work. Pointers to the manpages are provided where appropriate.
Since no OS is like the other, I'll talk about my Linux Distribution, Debian, here. So the location of some files or commands to install packages may differ for your system.
Getting the daemon
There are currently two "major versions" of collectd: Version 3 and version 4. This is the first number of the full version number of a release. Version 3 is outdated and should not be used for new setups anymore, so make sure you get a version that starts with "4.*".
To get the executable binaries, you have the choice between two possibilities: Find a binary package or compile the source yourself. We strongly recommend to use a binary package unless you have very specific needs.
Get a binary package
For many Linux distributions there are binary packages. Please make sure not to use the ancient version 3 (Debian Etch ships version 3.10.4, for example). Pointers to available binary packages can be found on the download page.
Compiling the sources
If there is no binary package for your distribution, or the one
existing is outdated, you can compile the sources. For that you will
need to install the usual C-compiler (most likely called
"gcc"), linker, and so on. Debian users can simply install the build-essential
package:
The daemon itself doesn't depend on any libraries, but the plugins that collect the actual values will. What
libraries are needed for which plugins is documented in the README file. Install the necessary
libraries:
After installing the build dependencies, you need to get and unpack the sources:
# wget http://collectd.org/files/collectd-x.y.z.tar.bz2
# tar jxf collectd-x.y.z.tar.bz2
# cd collectd-x.y.z
Now configure the sources with the usual:
After the configure-script is done it will display a
summary of the libraries it has found (and not found) and which plugins
are enabled. Per default, all plugins whose dependencies are met are
enabled. If a plugin you want to use is missing install the required
development package and run configure again.
Last but not least: Compile and install the program. Per default it will be installed to
/opt/collectd. If you prefer another directory, call the configure script with the
--prefix option.
# cd /opt/collectd/
Configuration
The configuration will lie in
<prefix>/etc/collectd.conf. It's manpage is
collectd.conf(5).
Open the file and pay particular attention to the
LoadPlugin lines.
Loading plugins
The LoadPlugin lines, that are commented out, belong to plugins that have not been built.
Commenting them in will not work, because the plugin does not exist. But, you may want to disable some plugins,
for example the csv plugin will not be of interest for people who just want to get pretty graphs.
Actually, we recommend to comment out all plugins and then just comment in the ones you
specifically want to have.
The following is a list of the very basic plugins and a short description:
| Name | Type | Description |
|---|---|---|
logfile |
logging | Writes log messages to a file or standard output |
rrdtool |
output | Writes data to RRD-files |
csv |
output | Writes data to CSV-files |
cpu |
input | Collects CPU usage |
memory |
input | Collects memory usage |
interface |
input | Collects traffic of network interfaces |
Setting options
The Interval setting sets how often values are read.
You should set this once and then never touch it again. If you do,
you will have to delete all your RRD-files or know
some serious RRDTool-magic!
Some plugins take an additional configuration. Of interest are the
logfile and rrdtool plugins. Before setting
anything explicitly, please read the relevant part of the collectd.conf(5)
manpage.
There are no undocumented options. The
rrdtool plugin is especially prone of mis-configuration,
please read the manual page especially careful when configuring this
plugin.
Starting the daemon
If you're done configuring, you need to (re-)start the daemon. If
you installed a binary package there should be an
init-script somewhere. Under Debian, the command would
be:
Alternatively you can start the daemon "by hand". This is done by executing:
Some plugins require root privileges to work properly. If you're missing graphs and/or see error messages that indicate insufficient permissions, restart collectd as root.
The daemon should now collect values using the "input" plugins you've loaded and write them to files using the "output" plugin(s). Any problems or interesting behavior is reported using the "log" plugin(s).
Congratulations, as far as collectd is concerned, you're all set! :)
Creating graphs
First off: It is not collectd's focus to generate graphs! The
focus is to collect the values and write it to files or send it to another host over a network. But since we
have to visualize the data somehow, too, we have been nice enough to throw a script that's
good enough for us into the contrib/ directory. This script, however, is not part of
collectd and not supported by us. It just happens to work sometimes.
That being said, here's how it's installed: In the contrib/ directory (or the directory
/usr/share/doc/collectd/examples/ if you installed the Debian package) you will find a directory
named collection3. This directory holds all the necessary files for the graph generation, grouped
again in subdirectories. Copy the entire directory somewhere, where your web server expects to find
something.
# cd /usr/lib/cgi-bin/collection3
In some of the subdirectories, you will find files named .htaccess. They (try
to) configure the web server, so that the appropriate files are executed, others are denied to visitors and so
on. Please make sure to set the Apache option AllowOverride to an appropriate value or move the
configuration to the main apache configuration.
The script is written in Perl and requires a number of Perl modules to be installed. Many of them are shipped with the standard Perl distributions, but some you will need to install yourself. Here's a (hopefully complete) list:
RRDsConfig::GeneralHTML::Entities
If everything worked out alright, you can now browse your graphs at
http://localhost/cgi-bin/collection3/bin/index.cgi or wherever you put the script. If you get an
error, check Apache's error log. Common errors include wrong permissions on the files in bin/ (they
need to be executable) and etc/ (needs to be readable by the web server). For web server specific
problems, please refer to read this how-to on CGI
scripts.
Good luck and have fun ;)
