COLLECTD-LUA(5) | collectd | COLLECTD-LUA(5) |
collectd-lua - Documentation of collectd's "Lua plugin"
LoadPlugin lua # ... <Plugin lua> BasePath "/path/to/your/lua/scripts" Script "script1.lua" Script "script2.lua" </Plugin>
The "Lua plugin" embeds a Lua interpreter into collectd and provides an interface to collectd's plugin system. This makes it possible to write plugins for collectd in Lua. This is a lot more efficient than executing a Lua script every time you want to read a value with the "exec plugin" (see collectd-exec(5)) and provides a lot more functionality, too.
The minimum required Lua version is 5.1.
Writing your own plugins is quite simple. collectd manages plugins by means of dispatch functions which call the appropriate callback functions registered by the plugins. Any plugin basically consists of the implementation of these callback functions and initializing code which registers the functions with collectd. See the section "EXAMPLES" below for a really basic example. The following types of callback functions are implemented in the Lua plugin (all of them are optional):
The following functions are provided to Lua modules:
function read() collectd.log_info("read function called") t = { host = 'localhost', plugin = 'myplugin', type = 'counter', values = {42}, } collectd.dispatch_values(t) return 0 end
A very simple write function might look like:
function write(vl) for i = 1, #vl.values do collectd.log_info(vl.host .. '.' .. vl.plugin .. '.' .. vl.type .. ' ' .. vl.values[i]) end return 0 end
To register those functions with collectd:
collectd.register_read(read) -- pass function as variable collectd.register_write("write") -- pass by global-scope function name
The "Lua plugin" has been written by Julien Ammous <j.ammous at gmail.com>, Florian Forster <octo at collectd.org> and Ruben Kerkhof <ruben at rubenkerkhof.com>.
This manpage has been written by Ruben Kerkhof <ruben at rubenkerkhof.com>. It is based on the collectd-perl(5) manual page by Florian Forster <octo at collectd.org> and Sebastian Harl <sh at tokkee.org>.
2021-07-14 | 5.12.0.git |