Collectd

General

Check config file

collectd -ft

Debugging

  • Add this to your config file
LoadPlugin logfile
<Plugin logfile>
  LogLevel debug
    File STDOUT
</Plugin>
  • Start collectd in foreground
collectd -f -C /etc/collectd.conf

Example SNMP config

  • For single values use Table false
<Plugin snmp>
  <Data "a_value">
        Type "gauge"
        Table true
        Values ".1.3.6.1.4.1.34097.9.80.1.1.6.1"
   </Data>
   <Host "some-host.domain.tld">
         Address "1.2.3.4"
         Version 1
         Community "public"
         Collect "a_value"
         Interval 5
   </Host>
</Plugin>

Graphite output plugin

LoadPlugin "write_graphite"
<Plugin "write_graphite">
 <Carbon>
   Host "127.0.0.1"
   Port "2003"
   Protocol "tcp"
   Prefix "collectd."
   EscapeCharacter "_"
   SeparateInstances true
   StoreRates false
   AlwaysAppendDS false
 </Carbon>
</Plugin>

Mongodb output

LoadPlugin write_mongodb
<Plugin "write_mongodb">
  <Node "default">
      Host "localhost"
      Port     "27017"
      Timeout    2000
      StoreRates true
  </Node>
</Plugin>

RRD output

  • For using rrdcached (prefered method)
LoadPlugin rrdcached
<Plugin "rrdcached">
  DaemonAddress "unix:/var/run/rrdcached/rrdcached.sock"
  DataDir "/var/lib/collectd/rrd"
  CreateFiles true
</Plugin>
  • For direct rrd
LoadPlugin rrdtool
<Plugin rrdtool>
   DataDir "/var/lib/collectd/rrd"
   CacheTimeout 120
   CacheFlush   900
   # default 3600, 86400, 604800, 2678400, 31622400
   # RRATimespan <seconds>
</Plugin>

Example tail file

LoadPlugin tail
<Plugin "tail">
  <File "/var/log/httpd/error_log">
    Instance "httpd_error"
    <Match>
      Regex "python"
      DSType "CounterInc"
      Type "counter"
      Instance "total"
    </Match>
  </File>
</Plugin>

Example exec plugin

  • Source of script (e.g. /usr/bin/count_lines_in_file)
#!/bin/bash
HOSTNAME="${COLLECTD_HOSTNAME:-localhost}"
INTERVAL="${COLLECTD_INTERVAL:-60}"
FILE=$1

 while sleep "$INTERVAL"; do
   VALUE=`cat $FILE | wc -l`
   echo "PUTVAL \"$HOSTNAME/"`basename $FILE`"_count/counter\" interval=$INTERVAL N:$VALUE"
 done
  • Config for plugin
LoadPlugin exec
<Plugin exec>
  Exec "nobody" "/usr/bin/count_lines_in_file" "/var/log/httpd/error_log"
</Plugin>