Technology and Thoughts

Filter collectd metrics

18 May 2015

Recently I’ve needed to filter some of the metrics being shipped from collectd agents to our graphite instance.

The documentation on collectd to do this is very sparse, to say the least. Luckily someone in the #collectd channel and some trial and error on my part, I was able to get it working.

Here’s is what an example filter:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  LoadPlugin "match_regex"
  <Chain "PostCache">
    # only show system and user
    <Rule "ignore_cpu_metrics">
      <Match "regex">
        Plugin "^cpu"
        Type "^cpu$"
        TypeInstance "^(idle|interrupt|nice|softirq|steal|wait)$"
      </Match>
      Target "stop"
    </Rule>

    # only show read/write ops
    <Rule "ignore_disk_metrics">
      <Match "regex">
        Plugin "^disk"
        PluginInstance "^(dm|sd.*)"
        Type "^disk_(merged|octets|time)"
      </Match>
      Target "stop"
    </Rule>

    # Default target
    Target "write"
  </Chain>

The ‘ignore_cpu_metrics’ only gathers the ‘system and user’ metric and I’m only getting disk read/write operations in “ignore_disk_metrics”.

All the magic in done using Chains configs. You should also read up on the naming schema to understand how the metrics sections are split up.

Enjoy!