2010/11/03

Building stand-alone Collectd plugin

I'm working on building a plugin for the collectd data collection system (www.collectd.org) that will gather stats on our ESX RedHat VMs through the VMware Guest API.

Here's what I've found so far...

unpack collectd, configure and make it.
In a separate directory, create the source files for the new plugin.

(minimal plugin code:
#include "collectd.h"
#include "common.h"
#include "plugin.h"

static int my_read(void) {
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;

values[0].counter = 0;

vl.values = values;
vl.values_len = 1;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "test1", sizeof (vl.plugin));
sstrncpy (vl.type, "counter", sizeof (vl.type));

plugin_dispatch_values (&vl);

return 0;
}

void module_register(void) {
plugin_register_read ("test1", my_read);
}


Then I use libtool to build the .o:
$ libtool --mode=compile gcc -DHAVE_CONFIG_H -I ../collectd-4.10.1/src -Wall -Werror -g -O2 -MT test1.lo -MD -MP -MF test1.Tpo -c -o test1.lo test1.c
and link it:
$ libtool --tag=CC --mode=link gcc -Wall -Werror -g -O2 -module -avoid-version -o test1.la -rpath /apps/collectd-4.10.1/lib/collectd -lpthread -ldl test1.lo

This generates the files in ./libs/test1.* which I copy into the $prefix/lib/collectd/ directory and enable it in my config.

So much for part 1... Up next, getting actual data.

--Joe

No comments: