Monitoring CPU, RAM, Network with collectd Linux 06.05.2014

collectd is a UNIX-daemon that collects, transfers and stores performance data of computers and network equipment. The acquired data is meant to help system administrators maintain an overview over available resources to detect existing or looming bottlenecks (source).

collectd uses a modular design: the daemon itself only implements infrastructure for filtering and relaying data as well as auxiliary functions and requires very few resources.

Data acquisition and storage is handled by plugins in the form of shared objects. Data acquisition plug-ins, called "read plugins" in collectd's documentation so called "write plug-ins" offer the possibility to store the collected data on disk using RRD- or CSV-files, or to send data over the network to a remote instance of the daemon.


We'll use collectd for data gathering and rrdtool for visualization.

There are packages in package repositories for Arch Linux and Ubuntu.

# arch
yaourt -S collectd rrdtool

# ubuntu
sudo apt-get install collectd rrdtool


The configuration lie in /etc/collectd.conf.

For each plugin, there is a LoadPlugin line in the configuration. Almost all of those lines are commented out in order to keep the default configuration lean. By default the following plugins are enabled: CPU, Interface, Load, and Memory.

Simple config file

# egrep -v '^$|^#' /etc/collectd/collectd.conf

FQDNLookup true
LoadPlugin syslog
<Plugin syslog>
        LogLevel info
LoadPlugin cpu
LoadPlugin df
LoadPlugin interface
LoadPlugin load
LoadPlugin memory
LoadPlugin processes
LoadPlugin rrdtool
LoadPlugin swap
LoadPlugin users
<Plugin rrdtool>
        DataDir "/var/lib/collectd/rrd"
<Plugin df>
        Device "/dev/sda1"
        MountPoint "/"
        FSType "ext4"
Include "/etc/collectd/filters.conf"
Include "/etc/collectd/thresholds.conf"

If you're done configuring, you need to (re-)start the daemon.

# start in arch 
sudo systemctl start collectd.service

# restart in arch
sudo systemctl restart collectd.service

# enable in arch
sudo systemctl restart collectd.service

# start in ubuntu
sudo service collectd start

# restart in ubuntu
sudo service collectd restart


There are many options to present data from collectd. You can use front-ends (collectd-web, graphite, visage) or generate png files with rrdtool and include in html file which is accessible from outside.

First option is to use front-end. I'm going to show Collectd-Web.

# download
git clone git://

# check dependency
cd collectd-web

# make sure collectd looks under the correct location
# cat /etc/collectd/collection.conf 

datadir: "/var/lib/collectd/rrd/" 
libdir: "/usr/lib/collectd/"

After that you should copy collectd-web to public directory.

sudo cp -r *.* /var/www/

Second option is to use rrdtool for generation png file with diagram. After generation we can use images in any html file as source for img tag.

Example of rrdtool script you can get here.

Add it to cron as usual

# sudo crontab -e

*/15 * * * * root /path/to/ > /dev/null 2>&1

You can check your network speed with speedtest-cli.


Collectd can inform you if something is strange. For example, it can send email if CPU load is more than 80% or RAM utilization is more than 90% and so on.

First, we need activate notify_email plugin and set recipient.

# sudo vim /etc/collectd/collectd.conf

LoadPlugin "threshold"
LoadPlugin notify_email

<Plugin notify_email>
   SMTPServer ""
   SMTPPort 25
   SMTPUser ""
   SMTPPassword "password"
   From ""
   Subject "[collectd] %s on %s!"
   Recipient ""

Second, set up threshold

# sudo vim /etc/collectd/thresholds.conf

<Type "cpu">
     Instance "user"
     WarningMax 85
     Hits 1

Last, restart collectd

# restart in arch
sudo systemctl restart collectd.service

# restart in ubuntu
sudo service collectd restart

You can check CPU overload with cpuburn.

How to write custom plugin