Relaying of collectd metrics to a central graphit with syslog

Posted by Markus Benning on December 28, 2014

Download and install the Collectd::Plugins::WriteSyslogGraphite plugin from cpan:

cpanm Collectd::Plugins::WriteSyslogGraphite

This plugin allows you to write the collectd output to syslog.

Activate the plugin within your collectd configuration:

<LoadPlugin "perl">
  Globals true
</LoadPlugin>

<Plugin "perl">
  BaseName "Collectd::Plugins"
  LoadPlugin "WriteSyslogGraphite"

  <Plugin "SyslogGraphite">
    level "info"
    facility "local0"
    ident   "metric"
  </Plugin>
</Plugin>

Now configure rsyslogd to log to your central logging host.

If you’re using logstash on your central logging host can use the following grok pattern/filter to extract the metrics from the log stream and pass them to graphits carbon storage.

Grok pattern:

METRIC_PATH \S+
METRIC_VALUE .*
METRICLOG %{METRIC_PATH:metric_path}\s+%{METRIC_VALUE:metric_value}

Logstash filter/output:

filter {
  if [program] =~ "^metric$" {
    mutate { add_tag => [ "collectd_metric" ] }
    grok {
      patterns_dir => "/etc/logstash/patterns"
      match => [ "message", "%{METRICLOG}" ]
    }
  }
}

output {
  if "collectd_metric" in [tags] {
    graphite {
      host => [ "127.0.0.1" ]
      metrics => [ 'servers.%{@source_host}.%{metric_path}', '%{metric_value}' ]
    }
  }
}