How to install and setup collectd on Centos7

Introduction

In this post, I will go through the installation and setting of collectd. Then configure it to send the system metrics to remote Graphite server.

Environment

  • Local Machine: Centos 7.5
  • Collectd: version 5.8.1-1.el7

A Graphite Server should already be setup and ready to accept metrics with carbon service. Follow How to install Graphite on Centos7 first if you haven’t got that setup yet.

My Graphite server is:

  • Centos 7.5
  • Carbon listening on port 2003/tcp
  • Firewall rules allow the incoming traffic on port 2003

Install Collect

$ sudo yum install collectd

Configure

Collectd comes with some pre-configured metrics collection services. All settings are stored in single file: /etc/collectd.conf

I leave all the default settings which will collect all metrics I need and more. By default below services are enabled:

LoadPlugin syslog
LoadPlugin cpu
LoadPlugin interface
LoadPlugin load
LoadPlugin memory

The only change will be to tell the collectd daemon about the Graphite server details. One can add the details into the same config file but I will add them to a new file below: /etc/collectd.d/my-graphite.conf.

$ sudo vim /etc/collectd.d/my-graphite.conf
$ sudo vim /etc/collectd.d/my-graphite.con
LoadPlugin write_graphite

<Plugin write_graphite>
<Node "my-graphite>
Host "mygraphite.com"
# or IP address
# Host "xxx.xxx.xxx.xxx"
Port "2003"
Protocol "tcp"
ReconnectInterval 0
LogSendErrors true
Prefix "collectd."
# Postfix ".collectd"
StoreRates true
AlwaysAppendDS false
EscapeCharacter "_"
SeparateInstances false
PreserveSeparator false
DropDuplicateFields false
</Node>
</Plugin>

Start Daemon

We are all set to go. Now start the service and make sure it will be started during the system startup.

sudo systemctl enable collectd
sudo systemctl start collectd

Data in Graphite

You should see new data available in Graphite. All data will have prefix of collectd. as set in the config file. If you prefer something else you can update the configuration.

Sample data created in carbon storage on graphite server:

$ ls -al /opt/graphite/storage/whisper/collectd/bamboo-test/
total 0
drwxr-xr-x. 7 root root 89 Jan 18 09:51 .
drwxr-xr-x. 5 root root 77 Jan 18 10:16 ..
drwxr-xr-x. 2 root root 177 Jan 18 09:51 cpu-0
drwxr-xr-x. 6 root root 76 Jan 18 09:51 interface-ens192
drwxr-xr-x. 6 root root 76 Jan 18 09:51 interface-lo
drwxr-xr-x. 3 root root 18 Jan 18 09:51 load
drwxr-xr-x. 2 root root 162 Jan 18 09:51 memory

[Fri Jan 18 11:54:27 - /dev/pts/0]
[saeed@dana-: ~ ]
$ ls -ahl /opt/graphite/storage/whisper/collectd/bamboo-test/memory/
total 37M
drwxr-xr-x. 2 root root 162 Jan 18 09:51 .
drwxr-xr-x. 7 root root 89 Jan 18 09:51 ..
-rw-r--r--. 1 root root 6.1M Jan 18 11:56 memory-buffered.wsp
-rw-r--r--. 1 root root 6.1M Jan 18 11:56 memory-cached.wsp
-rw-r--r--. 1 root root 6.1M Jan 18 11:56 memory-free.wsp
-rw-r--r--. 1 root root 6.1M Jan 18 11:56 memory-slab_recl.wsp
-rw-r--r--. 1 root root 6.1M Jan 18 11:56 memory-slab_unrecl.wsp
-rw-r--r--. 1 root root 6.1M Jan 18 11:55 memory-used.wsp

[Fri Jan 18 11:56:27 - /dev/pts/0]
[saeed@dana-: ~ ]
$

Visualise data in Graphite


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.