Collectd plugin written in Rust


#1

Collectd gathers system and application metrics and stores the values in any manner. Since Collectd provides a plugin API, I created a repo that demonstrates how to create a Collectd plugin written in Rust that uses bindgen to generate the ffi functions. I’ve successfully used it as base for an internal Collectd plugin.

I recently migrated to use failure crate, so if anyone needed an example of usage (or correct my usage!).

Motivation

There are four main ways to extend collectd:

  • Write plugin against the C api: <collectd/core/daemon/plugin.h>
  • Write plugin for collectd-python
  • Write plugin for collectd-java
  • Write a cli for the exec plugin

And my thoughts:

  • I’m not confident enough to write C without leaks and there isn’t a great package manager for C.
  • Python and Java aren’t self contained, aren’t necessarily deployed on the server, are more heavy weight, and I suspect that maintenance plays second fiddle to the C api.
  • The exec plugin is costly as it creates a new process for every collection

Rust’s combination of ecosystem, package manager, C ffi, single file, and optimized library made it seem like a natural choice.


#2

This looks cool. Thanks.

When we at CurrySoftware had this issue, we decided to use socket communication with collectd.
Works like a charm and you can add/remove counters at runtime or without changing configuration.

I wrote a little blogpost about it: https://www.curry-software.com/en/blog/collectd/


#3

Thanks for bringing up the unixsocket solution, definitely worth a look for those that want / need a standalone service outside of collectd.

As an aside, I tend to send application metrics directly to a time series database (graphite is my poison), and use collectd plugins for monitoring lower level system metrics. For instance, I have an internal collectd plugin that collects cpu, memory, disk, etc metrics on docker containers. Deployment of collectd plugins couldn’t be easier – deploy (copy) the library.so, collectd config (if needed), and restart collectd.

Below is the collectd docker plugin on my (idle) home server :sweat_smile:

image