[collectd] Get collectd data from C++ source code
Sebastian Harl
sh at tokkee.org
Fri Aug 3 16:15:32 CEST 2012
Hi,
On Fri, Aug 03, 2012 at 03:56:20PM +0200, Massimo Canonico wrote:
> I have to get the collectd data (in particular, the idle time of the
> last 4 measures) and use it in my C++ code.
>
> Is there any example available? Do you have any suggestion concerning
> which is the best way to do it?
While I have never tested this, this should be fairly simple. You'll
have to make sure that the callback functions and register_module() are
linked according to the C calling conventions, i.e., those functions
have to be declared "extern C". You should then be able to call any C++
code from those functions and compile the whole thing using a C++
compiler.
So, in short, an example should look something like this:
foo.cpp:
extern "C" {
#include "collectd.h"
#include "common.h"
#include "plugin.h"
}
/* further, possibly C++, includes */
extern "C" {
static int foo_read(void);
void module_register(void);
}
static int
foo_read(void) { /* ... */ }
void
module_register(void) {
plugin_register_read("foo", foo_read);
}
Compile that, again untested, using something like:
g++ -DHAVE_CONFIG_H -shared -fPIC -o foo.so foo.cpp
In case you manage to get that up and running, it would be nice to get
some feedback / short howto / example / whatever on the list or in the
wiki :-)
HTH,
Sebastian
--
Sebastian "tokkee" Harl +++ GnuPG-ID: 0x8501C7FC +++ http://tokkee.org/
Those who would give up Essential Liberty to purchase a little Temporary
Safety, deserve neither Liberty nor Safety. -- Benjamin Franklin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://mailman.verplant.org/pipermail/collectd/attachments/20120803/2a4463e2/attachment.pgp>
More information about the collectd
mailing list