1COLLECTD-LUA(5) collectd COLLECTD-LUA(5)
2
3
4
6 collectd-lua - Documentation of collectd's "Lua plugin"
7
9 LoadPlugin lua
10 # ...
11 <Plugin lua>
12 BasePath "/path/to/your/lua/scripts"
13 Script "script1.lua"
14 Script "script2.lua"
15 </Plugin>
16
18 The "Lua plugin" embeds a Lua interpreter into collectd and provides an
19 interface to collectd's plugin system. This makes it possible to write
20 plugins for collectd in Lua. This is a lot more efficient than
21 executing a Lua script every time you want to read a value with the
22 "exec plugin" (see collectd-exec(5)) and provides a lot more
23 functionality, too.
24
25 The minimum required Lua version is 5.1.
26
28 LoadPlugin Lua
29 Loads the Lua plugin.
30
31 BasePath Name
32 The directory the "Lua plugin" looks in to find script Script. If
33 set, this is also prepended to package.path.
34
35 Script Name
36 The script the "Lua plugin" is going to run. If BasePath is not
37 specified, this needs to be an absolute path.
38
40 Writing your own plugins is quite simple. collectd manages plugins by
41 means of dispatch functions which call the appropriate callback
42 functions registered by the plugins. Any plugin basically consists of
43 the implementation of these callback functions and initializing code
44 which registers the functions with collectd. See the section "EXAMPLES"
45 below for a really basic example. The following types of callback
46 functions are implemented in the Lua plugin (all of them are optional):
47
48 read functions
49 These are used to collect the actual data. It is called once per
50 interval (see the Interval configuration option of collectd).
51 Usually it will call collectd.dispatch_values to dispatch the
52 values to collectd which will pass them on to all registered write
53 functions. If this function does not return 0 the plugin will be
54 skipped for an increasing amount of time until it returns normally
55 again.
56
57 write functions
58 These are used to write the dispatched values. They are called once
59 for every value that was dispatched by any plugin.
60
62 The following functions are provided to Lua modules:
63
64 register_read(callback)
65 The callback will be called without arguments. If this callback
66 function does not return 0 the next call will be delayed by an
67 increasing interval.
68
69 register_write
70 The callback function will be called with one argument passed,
71 which will be a table of values. If this callback function does
72 not return 0 next call will be delayed by an increasing interval.
73
74 log_error, log_warning, log_notice, log_info, log_debug(message)
75 Log a message with the specified severity.
76
78 A very simple read function might look like:
79
80 function read()
81 collectd.log_info("read function called")
82 t = {
83 host = 'localhost',
84 plugin = 'myplugin',
85 type = 'counter',
86 values = {42},
87 }
88 collectd.dispatch_values(t)
89 return 0
90 end
91
92 A very simple write function might look like:
93
94 function write(vl)
95 for i = 1, #vl.values do
96 collectd.log_info(vl.host .. '.' .. vl.plugin .. '.' .. vl.type .. ' ' .. vl.values[i])
97 end
98 return 0
99 end
100
101 To register those functions with collectd:
102
103 collectd.register_read(read)
104 collectd.register_write(write)
105
107 collectd(1), collectd.conf(5), lua(1),
108
110 The "Lua plugin" has been written by Julien Ammous
111 <j.ammous<nbsp>at gmail.com>, Florian Forster <octo at collectd.org>
112 and Ruben Kerkhof <ruben<nbsp>at rubenkerkhof.com<gt> and
113
114 This manpage has been written by Ruben Kerkhof
115 <ruben<nbsp>at rubenkerkhof.com<gt>. It is based on the
116 collectd-perl(5) manual page by Florian Forster <octo at collectd.org>
117 and Sebastian Harl <sh at tokkee.org>.
118
119
120
1215.8.0.614.g86fa80d+ 2018-10-04 COLLECTD-LUA(5)