[collectd] lua plugin
Florian Forster
octo at collectd.org
Sun Nov 28 17:20:35 CET 2010
Hi Schmurfy,
I have now implemented basic support for write callbacks and improved
the thread-handling: There is now one Lua thread created for each
callback, which makes it possible for a Lua-based read function to
indirectly call a Lua-based write function in the same script.
On Thu, Nov 25, 2010 at 12:37:33AM +0100, Schmurfy wrote:
> For the read/write callbacks we can call a function by name from the C
> code which is enough in my opinion and should reduce the C code of the
> plugin, with one function called you can call as many as you want in
> the lua code itself as you wish.
As a matter of fact, passing functions is actually easier than looking
up a function by its name, though storing the function pointers is a bit
harder, because they can't be exported to C. Nonetheless, I think the
interface is nicer if we can pass callback functions to the register
functions, because it's more Lua-like. No native Lua code would
reference a function using a string, right?
With the current status, I was able to run the following test-script
successfully:
-- 8< --
require ("collectd");
function test_read ()
collectd_dispatch_values ({
host = "leeloo.octo.it",
plugin = "lua",
type = "gauge",
interval = 10.0,
values = { 3.1337 }
});
return (0);
end
collectd_register_read (test_read);
collectd_register_write (function (vl)
collectd_info ("Lua: Anonymous write function has been called.");
return (0);
end);
-- >8 --
This script demonstrates how to:
* Register a named function.
* Register an anonymous function.
* Register read and write functions.
* Dispatch values to collectd.
With that the basic points are now covered. There are, of course, still
more interfaces to port to Lua, but read and write callbacks are the
most important ones in my opinion. Currently open todos are:
* Export oconfig_item_t to Lua and provide configuration hooks.
* Provide hooks for notifications and make it possible to dispatch
notifications to collectd.
* Provide hooks for "match" and "target" callbacks. (Requires the
configuration stuff above.)
What would you like to focus on now? The filter subsystem as you
indicated in an earlier email?
On Thu, Nov 25, 2010 at 12:37:33AM +0100, Schmurfy wrote:
> I already did most of the work you surely had to do to write this, I
> just wanted to have a build system running before adding more code to
> the plugin.
Sorry about that.. Please make sure to always push your changes to your
Git repository, so I can see that you're working on the plugin and what
you're working on. If you plan to rebase or modify your commits, I
suggest to use a special branch to indicate this, for example "lua/wip"
for "work in progress". You can also join our IRC channel [*] so I can
give you a heads up before working on the code.
Regards,
—octo
[*] #collectd on freenode
--
Florian octo Forster
Hacker in training
GnuPG: 0x0C705A15
http://octo.it/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: Digital signature
URL: <http://mailman.verplant.org/pipermail/collectd/attachments/20101128/64bb767a/attachment.pgp>
More information about the collectd
mailing list