Skip to content

Instantly share code, notes, and snippets.

@toff63
Last active March 21, 2016 20:25
Show Gist options
  • Save toff63/108909100a34379a1b18 to your computer and use it in GitHub Desktop.
Save toff63/108909100a34379a1b18 to your computer and use it in GitHub Desktop.
FQDNLookup true
LoadPlugin syslog
<Plugin syslog>
LogLevel info
</Plugin>
LoadPlugin amqp
LoadPlugin battery
LoadPlugin cpu
LoadPlugin df
LoadPlugin disk
LoadPlugin entropy
LoadPlugin interface
LoadPlugin irq
LoadPlugin load
LoadPlugin memory
LoadPlugin network
LoadPlugin processes
LoadPlugin rrdtool
LoadPlugin swap
LoadPlugin users
<Plugin amqp>
<Publish "name">
Host "localhost"
Port "5672"
VHost "/"
User "guest"
Password "guest"
Exchange "collectd.amq.fanout"
ExchangeType "fanout"
RoutingKey "collectd"
Persistent false
StoreRates false
ConnectionRetryDelay 0
Format "json"
</Publish>
</Plugin>
<Plugin df>
FSType rootfs
FSType sysfs
FSType proc
FSType devtmpfs
FSType devpts
FSType tmpfs
FSType fusectl
FSType cgroup
IgnoreSelected true
</Plugin>
<Plugin rrdtool>
DataDir "/var/lib/collectd/rrd"
</Plugin>
<Include "/etc/collectd/collectd.conf.d">
Filter "*.conf"
</Include>

Install collectd on Ubuntu 14.04

curl http://pkg.ci.collectd.org/pubkey.asc | sudo apt-key add -
sudo bash -c  'echo "deb http://pkg.ci.collectd.org/deb/ trusty collectd-5.5" > /etc/apt/sources.list.d/collectd-ci.list'
sudo apt-get update
sudo apt-get install collectd # This should install collectd version 5.5.x

Install rabbitmq on Ubuntu 14.0.4

wget https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.1/rabbitmq-server_3.6.1-1_all.deb
sudo apt-get install erlang-nox
sudo dpkg -i rabbitmq-server_3.6.1-1_all.deb

Havec collectd sending info in rabbitmq

Edit /etc/collectd/collectd.conf and uncomment the line:

LoadPlugin amqp

Add the following lines in /etc/collectd/collectd.conf

<Plugin amqp>
        <Publish "name">
        Host "localhost"
                Port "5672"
                VHost "/"
                User "guest"
                Password "guest"
                Exchange "collectd.amq.fanout"
                ExchangeType "fanout"
                RoutingKey "collectd"
                Persistent false
                StoreRates false
                ConnectionRetryDelay 0
                Format "json"
        </Publish>
</Plugin>

In Rabbitmq management webapp, create a new exchange named collectd.amq.fanout of type fanout. The Format parameter supports 3 formats:

  • json
  • command
  • graphite

You can check the results running the python script in the gist after installing pika:

sudo pip install pika
#!/usr/bin/env python
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(
host='localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='collectd.amq.fanout', type='fanout', durable='false')
result = channel.queue_declare(exclusive=True)
queue_name = result.method.queue
channel.queue_bind(exchange='collectd.amq.fanout',
queue=queue_name)
print(' [*] Waiting for logs. To exit press CTRL+C')
def callback(ch, method, properties, body):
print("%r" % body)
channel.basic_consume(callback,
queue=queue_name,
no_ack=True)
channel.start_consuming()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment